public AuthenticatedUserToken login(LoginRequest request) {
validate(request);
User user = null;
user = userRepository.findByEmailAddress(request.getUsername());
if (user == null) {
throw new AuthenticationException();
}
String hashedPassword = null;
try {
hashedPassword = user.hashPassword(request.getPassword());
} catch (Exception e) {
throw new AuthenticationException();
}
if (hashedPassword.equals(user.getHashedPassword())) {
return new AuthenticatedUserToken(user.getUuid().toString(), createAuthorizationToken(user).getToken());
} else {
throw new AuthenticationException();
}
}