@@ -47,6 +47,8 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
47
47
48
48
private static final Log logger = LogFactory .getLog (BindAuthenticator .class );
49
49
50
+ private boolean alsoHandleJavaxNamingBindExceptions = false ;
51
+
50
52
/**
51
53
* Create an initialized instance using the {@link BaseLdapPathContextSource}
52
54
* provided.
@@ -125,23 +127,30 @@ private DirContextOperations bindWithDn(String userDnStr, String username, Strin
125
127
// This will be thrown if an invalid user name is used and the method may
126
128
// be called multiple times to try different names, so we trap the exception
127
129
// unless a subclass wishes to implement more specialized behaviour.
128
- if ((ex instanceof org .springframework .ldap .AuthenticationException )
129
- || (ex instanceof org .springframework .ldap .OperationNotSupportedException )) {
130
- handleBindException (userDnStr , username , ex );
131
- }
132
- else {
133
- throw ex ;
134
- }
130
+ handleIfBindException (userDnStr , username , ex );
135
131
}
136
132
catch (javax .naming .NamingException ex ) {
137
- throw LdapUtils .convertLdapException (ex );
133
+ if (!this .alsoHandleJavaxNamingBindExceptions ) {
134
+ throw LdapUtils .convertLdapException (ex );
135
+ }
136
+ handleIfBindException (userDnStr , username , LdapUtils .convertLdapException (ex ));
138
137
}
139
138
finally {
140
139
LdapUtils .closeContext (ctx );
141
140
}
142
141
return null ;
143
142
}
144
143
144
+ private void handleIfBindException (String dn , String username , org .springframework .ldap .NamingException naming ) {
145
+ if ((naming instanceof org .springframework .ldap .AuthenticationException )
146
+ || (naming instanceof org .springframework .ldap .OperationNotSupportedException )) {
147
+ handleBindException (dn , username , naming );
148
+ }
149
+ else {
150
+ throw naming ;
151
+ }
152
+ }
153
+
145
154
/**
146
155
* Allows subclasses to inspect the exception thrown by an attempt to bind with a
147
156
* particular DN. The default implementation just reports the failure to the debug
@@ -151,4 +160,18 @@ protected void handleBindException(String userDn, String username, Throwable cau
151
160
logger .trace (LogMessage .format ("Failed to bind as %s" , userDn ), cause );
152
161
}
153
162
163
+ /**
164
+ * Set whether javax-based bind exceptions should also be delegated to {@code #handleBindException}
165
+ * (only Spring-based bind exceptions are handled by default)
166
+ *
167
+ * <p>For passivity reasons, defaults to {@code false}, though may change to {@code true}
168
+ * in future releases.
169
+ *
170
+ * @param alsoHandleJavaxNamingBindExceptions - whether to delegate javax-based bind exceptions to
171
+ * #handleBindException
172
+ * @since 6.4
173
+ */
174
+ public void setAlsoHandleJavaxNamingBindExceptions (boolean alsoHandleJavaxNamingBindExceptions ) {
175
+ this .alsoHandleJavaxNamingBindExceptions = alsoHandleJavaxNamingBindExceptions ;
176
+ }
154
177
}
0 commit comments