What's more, if the LoginModule throws an Acegi exception straight away, it gets wrapped in a LoginException by JAAS. The exception handler could look if the target exception of the LoginException is an Acegi exception, and use that one.
Code:
public Authentication authenticate(Authentication auth)
try {
....
} catch (LoginException e) {
context.publishEvent(new JaasAuthenticationFailedEvent(auth, e));
resolveLoginException(e);
}
...
/**
* Tries to resolves a JAAS login exception into an Acegie exception, such as BadCredentialsException, DisabledException, UsernameNotFoundException or LockedException
* @param loginException The login exception causing the failed login
* @return AcegiSecurityException The corresponding exception of Acegi
*/
public AcegiSecurityException resolveLoginException(LoginException loginException) {
// if the code needs to be compatible with pre 1.4, we need to use reflection here
if (loginException.getCause() instanceof AcegiSecurityException) {
return (AcegiSecurityException)loginException.getCause();
} else {
//We have no way of knowing what caused the exception, so we return the general AuthenticationServiceException
//So we'll just throw an AuthenticationServiceException
throw new AuthenticationServiceException(loginException.toString());
}
}
Ben, if u want, I'll be happy to contribute the modified JaasAuthenticationProvider (and test case).
Stefaan.