// Path: src/main/java/com/nvisium/androidnv/api/service/impl/UserServiceImpl.java
// @Service
// @Qualifier("userService")
// public class UserServiceImpl implements UserService {
// 
// 	@Autowired
// 	private UserRepository accountRepository;
// 
// 	@Autowired
// 	private SecurityUtils security;
// 
// 	/*
// 	 * Inserts a new user
// 	 */
// 	public void addRegularUser(String username, String password, String email,
// 			String answer, String firstname, String lastname) {
// 		com.nvisium.androidnv.api.model.User user = new com.nvisium.androidnv.api.model.User();
// 		user.addAccountInfo(username, password, email, answer, firstname,
// 				lastname);
// 		accountRepository.save(user);
// 	}
// 
// 	public boolean validateCredentials(String username, String password) {
// 		return (!(accountRepository.findByUsernameAndPassword(username,
// 				password) == null));
// 	}
// 
// 	@Transactional
// 	public void logout() {
// 		// TODO: purge from redis...for now, who cares, tokens live forever!!
// 		// VULN
// 	}
// 
// 	public boolean validateCurrentPassword(String password) {
// 		return (accountRepository.findUserByIdAndPassword(
// 				security.getCurrentUserId(), password) != null);
// 	}
// 
// 	@Transactional
// 	public void updatePasswordById(String password) {
// 		accountRepository.updatePasswordById(password,
// 				security.getCurrentUserId());
// 	}
// 
// 	public boolean doesUserExist(String username) {
// 		return accountRepository.findByUsername(username) != null;
// 	}
// 
// 	@Transactional(readOnly = true)
// 	public UserDetails loadUserByUsername(String username) {
// 
// 		com.nvisium.androidnv.api.model.User user = accountRepository
// 				.getUserModelByUsername(username);
// 		List<GrantedAuthority> authorities = buildUserAuthority(user.getRoles());
// 		return new NvUserDetails(user, authorities);
// 	}
// 
// 	private List<GrantedAuthority> buildUserAuthority(Set<Role> roles) {
// 
// 		Set<GrantedAuthority> setAuths = new HashSet<GrantedAuthority>();
// 
// 		// Build user's authorities
// 		for (Role role : roles) {
// 			setAuths.add(new SimpleGrantedAuthority(role.getRoleName()));
// 		}
// 		return new ArrayList<GrantedAuthority>(setAuths);
// 	}
// 	
// 	@Transactional
// 	public User loadUserById(Long id) {
// 		return accountRepository.findById(id);
// 	}
// 	
// 	@Transactional
// 	public User loadUser(String username) {
// 		return accountRepository.getUserModelByUsername(username);
// 	}
// 	
// 	@Transactional
// 	public void updateUser(String username, String firstname, String lastname, String email) {
// 		accountRepository.updateUserProfile(username,firstname,lastname,email);
// 	}
// 
// 	public List<User> getPublicUsers() {
// 		return accountRepository.getUsersByPrivacyDisabled();
// 	}
// 
// 	public void credit(Long id, BigDecimal amount) {
// 		
// 		BigDecimal newAmount = loadUserById(id).getBalance().add(amount);
// 		accountRepository.updateBalance(id, newAmount);
// 	}
// 
// 	public boolean debit(Long id, BigDecimal amount) {
// 		User u = accountRepository.findById(id);
// 		if (u.getBalance().compareTo(amount) != -1) {
// 			credit(id, amount.negate());
// 
// 			return true;
// 		}
// 		return false;
// 	}
// 
// 	public boolean isAnswerValid(String username, String answer) {
// 		if (accountRepository.getAnswerByUsername(username).equals(answer))
// 			return true;
// 		else
// 			return false;
// 	}
// 
// 	@Transactional
// 	public void updatePasswordByUsername(String username, String password) {
// 		accountRepository.updatePasswordByUsername(username, password);
// 	}
// 
// 	public void updateAnswerById(String answer) {
// 		accountRepository.updateAnswerById(answer, security.getCurrentUserId());
// 		
// 	}
// }


import org.h2.server.web.WebServlet;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import com.nvisium.androidnv.api.service.impl.UserServiceImpl;
package com.nvisium.androidnv.api;



@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcAutoConfigurationAdapter{

    @Bean
    ServletRegistrationBean h2servletRegistration(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
        registrationBean.addUrlMappings("/console/*");
        return registrationBean;
    }
	
    @Bean
    @Override
    public InternalResourceViewResolver defaultViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
    
    @Bean
    public AuthenticationProvider daoAuthenticationProvider() {
        DaoAuthenticationProvider impl = new DaoAuthenticationProvider();
// Path: src/main/java/com/nvisium/androidnv/api/service/impl/UserServiceImpl.java
// @Service
// @Qualifier("userService")
// public class UserServiceImpl implements UserService {
// 
// 	@Autowired
// 	private UserRepository accountRepository;
// 
// 	@Autowired
// 	private SecurityUtils security;
// 
// 	/*
// 	 * Inserts a new user
// 	 */
// 	public void addRegularUser(String username, String password, String email,
// 			String answer, String firstname, String lastname) {
// 		com.nvisium.androidnv.api.model.User user = new com.nvisium.androidnv.api.model.User();
// 		user.addAccountInfo(username, password, email, answer, firstname,
// 				lastname);
// 		accountRepository.save(user);
// 	}
// 
// 	public boolean validateCredentials(String username, String password) {
// 		return (!(accountRepository.findByUsernameAndPassword(username,
// 				password) == null));
// 	}
// 
// 	@Transactional
// 	public void logout() {
// 		// TODO: purge from redis...for now, who cares, tokens live forever!!
// 		// VULN
// 	}
// 
// 	public boolean validateCurrentPassword(String password) {
// 		return (accountRepository.findUserByIdAndPassword(
// 				security.getCurrentUserId(), password) != null);
// 	}
// 
// 	@Transactional
// 	public void updatePasswordById(String password) {
// 		accountRepository.updatePasswordById(password,
// 				security.getCurrentUserId());
// 	}
// 
// 	public boolean doesUserExist(String username) {
// 		return accountRepository.findByUsername(username) != null;
// 	}
// 
// 	@Transactional(readOnly = true)
// 	public UserDetails loadUserByUsername(String username) {
// 
// 		com.nvisium.androidnv.api.model.User user = accountRepository
// 				.getUserModelByUsername(username);
// 		List<GrantedAuthority> authorities = buildUserAuthority(user.getRoles());
// 		return new NvUserDetails(user, authorities);
// 	}
// 
// 	private List<GrantedAuthority> buildUserAuthority(Set<Role> roles) {
// 
// 		Set<GrantedAuthority> setAuths = new HashSet<GrantedAuthority>();
// 
// 		// Build user's authorities
// 		for (Role role : roles) {
// 			setAuths.add(new SimpleGrantedAuthority(role.getRoleName()));
// 		}
// 		return new ArrayList<GrantedAuthority>(setAuths);
// 	}
// 	
// 	@Transactional
// 	public User loadUserById(Long id) {
// 		return accountRepository.findById(id);
// 	}
// 	
// 	@Transactional
// 	public User loadUser(String username) {
// 		return accountRepository.getUserModelByUsername(username);
// 	}
// 	
// 	@Transactional
// 	public void updateUser(String username, String firstname, String lastname, String email) {
// 		accountRepository.updateUserProfile(username,firstname,lastname,email);
// 	}
// 
// 	public List<User> getPublicUsers() {
// 		return accountRepository.getUsersByPrivacyDisabled();
// 	}
// 
// 	public void credit(Long id, BigDecimal amount) {
// 		
// 		BigDecimal newAmount = loadUserById(id).getBalance().add(amount);
// 		accountRepository.updateBalance(id, newAmount);
// 	}
// 
// 	public boolean debit(Long id, BigDecimal amount) {
// 		User u = accountRepository.findById(id);
// 		if (u.getBalance().compareTo(amount) != -1) {
// 			credit(id, amount.negate());
// 
// 			return true;
// 		}
// 		return false;
// 	}
// 
// 	public boolean isAnswerValid(String username, String answer) {
// 		if (accountRepository.getAnswerByUsername(username).equals(answer))
// 			return true;
// 		else
// 			return false;
// 	}
// 
// 	@Transactional
// 	public void updatePasswordByUsername(String username, String password) {
// 		accountRepository.updatePasswordByUsername(username, password);
// 	}
// 
// 	public void updateAnswerById(String answer) {
// 		accountRepository.updateAnswerById(answer, security.getCurrentUserId());
// 		
// 	}
// }


// Path: src/main/java/com/nvisium/androidnv/api/MvcConfig.java
import org.h2.server.web.WebServlet;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import com.nvisium.androidnv.api.service.impl.UserServiceImpl;

package com.nvisium.androidnv.api;



@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcAutoConfigurationAdapter{

    @Bean
    ServletRegistrationBean h2servletRegistration(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
        registrationBean.addUrlMappings("/console/*");
        return registrationBean;
    }
	
    @Bean
    @Override
    public InternalResourceViewResolver defaultViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
    
    @Bean
    public AuthenticationProvider daoAuthenticationProvider() {
        DaoAuthenticationProvider impl = new DaoAuthenticationProvider();
        impl.setUserDetailsService(new UserServiceImpl());