@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
String username = token.getName();
String password = (String)token.getCredentials();
User account = accountRepository.findByEmailAndPassword(username, password);
if (account == null) {
logger.info("Invalid login. username={} password={}", username, password);
throw new BadCredentialsException("Bad credentials");
}
return authenticatedToken(account, authentication);