From 3889894d161eacbd5c7f6c44999fc04f70986d43 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Thu, 24 Aug 2006 10:32:38 +0000 Subject: [PATCH] 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. --- .../ldap/DefaultInitialDirContextFactory.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/ldap/DefaultInitialDirContextFactory.java b/core/src/main/java/org/acegisecurity/ldap/DefaultInitialDirContextFactory.java index 1d1c5178ab..048bc0020f 100644 --- a/core/src/main/java/org/acegisecurity/ldap/DefaultInitialDirContextFactory.java +++ b/core/src/main/java/org/acegisecurity/ldap/DefaultInitialDirContextFactory.java @@ -34,6 +34,7 @@ import java.util.StringTokenizer; import javax.naming.CommunicationException; import javax.naming.Context; import javax.naming.NamingException; +import javax.naming.OperationNotSupportedException; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; @@ -169,16 +170,21 @@ public class DefaultInitialDirContextFactory implements InitialDirContextFactory try { return new InitialDirContext(env); - } catch (CommunicationException ce) { - throw new LdapDataAccessException(messages.getMessage( - "DefaultIntitalDirContextFactory.communicationFailure", "Unable to connect to LDAP server"), ce); - } catch (javax.naming.AuthenticationException ae) { - throw new BadCredentialsException(messages.getMessage("DefaultIntitalDirContextFactory.badCredentials", - "Bad credentials"), ae); - } catch (NamingException nx) { + } catch (NamingException ne) { + if ((ne instanceof javax.naming.AuthenticationException) || + (ne instanceof OperationNotSupportedException)) { + throw new BadCredentialsException(messages.getMessage("DefaultIntitalDirContextFactory.badCredentials", + "Bad credentials"), ne); + } + + if (ne instanceof CommunicationException) { + throw new LdapDataAccessException(messages.getMessage( + "DefaultIntitalDirContextFactory.communicationFailure", "Unable to connect to LDAP server"), ne); + } + throw new LdapDataAccessException(messages.getMessage( "DefaultIntitalDirContextFactory.unexpectedException", - "Failed to obtain InitialDirContext due to unexpected exception"), nx); + "Failed to obtain InitialDirContext due to unexpected exception"), ne); } }