Added extra mapping of OperationNotSupportedException to BadCredentialsException as some servers return a 53 code (unwilling to perform) when attempting a bind (e.g. is password has expired). This shouldn't be treated as an outright failure.

This commit is contained in:
Luke Taylor 2006-08-24 10:32:38 +00:00
parent 67fcf426eb
commit 3889894d16

View File

@ -34,6 +34,7 @@ import java.util.StringTokenizer;
import javax.naming.CommunicationException; import javax.naming.CommunicationException;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.naming.OperationNotSupportedException;
import javax.naming.directory.DirContext; import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext; import javax.naming.directory.InitialDirContext;
@ -169,16 +170,21 @@ public class DefaultInitialDirContextFactory implements InitialDirContextFactory
try { try {
return new InitialDirContext(env); return new InitialDirContext(env);
} catch (CommunicationException ce) { } catch (NamingException ne) {
throw new LdapDataAccessException(messages.getMessage( if ((ne instanceof javax.naming.AuthenticationException) ||
"DefaultIntitalDirContextFactory.communicationFailure", "Unable to connect to LDAP server"), ce); (ne instanceof OperationNotSupportedException)) {
} catch (javax.naming.AuthenticationException ae) { throw new BadCredentialsException(messages.getMessage("DefaultIntitalDirContextFactory.badCredentials",
throw new BadCredentialsException(messages.getMessage("DefaultIntitalDirContextFactory.badCredentials", "Bad credentials"), ne);
"Bad credentials"), ae); }
} catch (NamingException nx) {
if (ne instanceof CommunicationException) {
throw new LdapDataAccessException(messages.getMessage(
"DefaultIntitalDirContextFactory.communicationFailure", "Unable to connect to LDAP server"), ne);
}
throw new LdapDataAccessException(messages.getMessage( throw new LdapDataAccessException(messages.getMessage(
"DefaultIntitalDirContextFactory.unexpectedException", "DefaultIntitalDirContextFactory.unexpectedException",
"Failed to obtain InitialDirContext due to unexpected exception"), nx); "Failed to obtain InitialDirContext due to unexpected exception"), ne);
} }
} }