I understand what happened. Here is the explanation.
The exception I actually saw in the logs was BadCredentialsException
but this exception is never thrown by adAuthenticationProvider.authenticate
and therefore never rethrown by the below method.
What actually happened was that the authentication.isAuthenticated()
was just returning false and I was passing this boolean value to the client code.
I am including the method again for clarity's sake:
@Override
public boolean doAuthenticate(String userAndDomain, String password) {
UsernamePasswordAuthenticationToken userToken = new UsernamePasswordAuthenticationToken(replaceBackSlashWithAtSign(userAndDomain), password);
try {
Authentication authentication = adAuthenticationProvider.authenticate(userToken);
return authentication.isAuthenticated();
} catch (BadCredentialsException e) {
log.error("Authentication failed - wrong username\\password", e);
throw new BadCredentialsException("Authentication failed - wrong username\\password", e);
} catch (AuthenticationException e) {
log.error("Authentication failed - AuthenticationException", e);
throw new AuthenticationException("Authentication failed - AuthenticationException", e) { };
}
}