Let me present one possible solution to your problem. Let's say that there is a callback interface like:
Code:
public interface AuthenticationErrorCallback {
/**
* This method will be called with the authentication exception in
* case there is a problem with the authentication.
*
* @param e the exception that was caught in the authentication method
*/
void execute(Exception e);
}
Let's further assume that the authentication methods in LdapTemplate call this callback when there is an error:
Code:
boolean authenticate(String base, String filter, String password,
AuthenticatedLdapEntryContextCallback callback,
AuthenticationErrorCallback errorCallback)
{
...
}
catch (Exception e) {
log.error("Authentication failed for entry with DN '" + entryIdentification.getAbsoluteDn() + "'", e);
errorCallback.execute(e);
return false;
}
}
A user interested in the actual exception could then write a callback that collects the exception for later retrieval, like this:
Code:
public static final class CollectingErrorCallback implements AuthenticationErrorCallback {
private Exception error;
public void execute(Exception e) {
this.error = e;
}
public Exception getError() {
return error;
}
}
When we put these pieces together, it could look like this:
Code:
CollectingErrorCallback errorCallback = new CollectingErrorCallback();
AuthenticatedLdapEntryContextCallback callback = new NullAuthenticatedLdapEntryContextCallback();
boolean result = tested.authenticate("", filter.toString(), "invalidpassword", callback, errorCallback);
if (!result) {
Exception error = errorCallback.getError();
// error is likely of type org.springframework.ldap.AuthenticationException
}
We would obviously provide the CollectingErrorCallback implementation. We would also make NullAuthenticatedLdapEntryContextCallback public, which it isn't today. So the only code you need to write is the last section above.
Would this be of any help to you?