Skip to content

Commit dde032a

Browse files
committed
[KARAF-4486] LDAPOptions sets Context.SECURITY_AUTHENTICATION only if username is provided
1 parent ac12c65 commit dde032a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

jaas/modules/src/main/java/org/apache/karaf/jaas/modules/ldap/LDAPOptions.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,15 @@ public Hashtable<String, Object> getEnv() throws NamingException {
144144
env.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactory());
145145
env.put(Context.PROVIDER_URL, getConnectionURL());
146146
if (getConnectionUsername() != null && getConnectionUsername().trim().length() > 0) {
147-
env.put(Context.SECURITY_AUTHENTICATION, getAuthentication());
147+
String auth = getAuthentication();
148+
if (auth == null) {
149+
auth = DEFAULT_AUTHENTICATION;
150+
}
151+
env.put(Context.SECURITY_AUTHENTICATION, auth);
148152
env.put(Context.SECURITY_PRINCIPAL, getConnectionUsername());
149153
env.put(Context.SECURITY_CREDENTIALS, getConnectionPassword());
154+
} else if (getAuthentication() != null) {
155+
env.put(Context.SECURITY_AUTHENTICATION, getAuthentication());
150156
}
151157
if (getSsl()) {
152158
setupSsl(env);
@@ -202,11 +208,7 @@ public String getConnectionPassword() {
202208
}
203209

204210
public String getAuthentication() {
205-
String authentication = (String) options.get(AUTHENTICATION);
206-
if (authentication == null) {
207-
authentication = DEFAULT_AUTHENTICATION;
208-
}
209-
return authentication;
211+
return (String) options.get(AUTHENTICATION);
210212
}
211213

212214
public boolean getSsl() {

0 commit comments

Comments
 (0)