throws AuthenticationException {
if ( authentication == null ) return null;
if ( !supports(authentication.getClass()) ) return null;
UsernamePasswordAuthenticationToken retr
= (UsernamePasswordAuthenticationToken) authentication;
String principal = (String) retr.getPrincipal();
String password = (String) retr.getCredentials();
PracticalUserDetails user = null;
try {
user = pudsim.loadUserByUsername(principal);
} catch(UsernameNotFoundException ex) {
throw new BadCredentialsException(
principal + " principal not found", ex);
}
// Returned user is never null
if ( !user.isEnabled() ) {
throw new DisabledException("Username: " + user.getUsername());
}
if ( !user.isAccountNonLocked() ) {
throw new LockedException("Username: " + user.getUsername());
}
if ( !user.getPassword().equals(password) ) {
throw new BadCredentialsException("Username: " + user.getUsername());
}
return new UsernamePasswordAuthenticationToken(
user.getUsername(), user.getPassword(), user.getAuthorities());
}