public LoginStatus login(String username, String password) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
logger.debug("Attempting login.");
try {
Authentication auth = authenticationManager.authenticate(token);
logger.debug("Login succeeded!");
SecurityContextHolder.getContext().setAuthentication(auth);
Collection<? extends GrantedAuthority> authorities = null;
if (auth.getAuthorities().isEmpty()){
authorities = new ArrayList<GrantedAuthority>();
} else {
authorities = auth.getAuthorities();
}
return new LoginStatus(auth.isAuthenticated(), auth.getName(), authorities);
} catch (BadCredentialsException e) {
Collection<? extends GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
return new LoginStatus(false, null, authorities);
}
}