public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
Object password = authentication.getCredentials();
try {
String hashedPassword = ESAPI.encryptor().hash((String) password, username);
User user = userService.findByUsername(username);
if (user == null) {
throw new BadCredentialsException("Username not found."); // TODO message
}
if (!hashedPassword.equals(user.getPassword())) {
throw new BadCredentialsException("Wrong password."); // TODO message
}
Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
return new UsernamePasswordAuthenticationToken(username, password, authorities);
}
catch (EncryptionException e) {
e.printStackTrace();