@@ -57,7 +57,7 @@ private static Pair<String, DirContext> getContext(final Properties props) {
57
57
try {
58
58
return new Pair <String , DirContext >(ldapUrl , new InitialDirContext (env ));
59
59
} catch (Exception e ) {
60
- theLogger .info ("Failed to connext to ldap instance [" + ldapUrl .trim () + "]. Trying next...\n " );
60
+ theLogger .info ("Failed to connect to ldap instance [" + ldapUrl .trim () + "]. Trying next...\n " );
61
61
}
62
62
}
63
63
}
@@ -78,7 +78,7 @@ private static void connect(final Properties props) throws Exception {
78
78
throw new IllegalArgumentException ("Could not connect to any of the provided ldap urls based on the given credentials." );
79
79
}
80
80
81
- DirContext ctx = pair . getSecond () ;
81
+ DirContext ctx = null ;
82
82
83
83
try {
84
84
ctx = pair .getSecond ();
@@ -104,6 +104,20 @@ private static void connect(final Properties props) throws Exception {
104
104
theLogger .info ("User name: " + result .getName ());
105
105
theLogger .info ("User full name: " + result .getNameInNamespace ());
106
106
107
+ String authnPsw = props .getProperty ("ldap.authn.password" );
108
+ if (authnPsw != null ) {
109
+ theLogger .info ("Attempting to authenticate " + result .getName () + " with password " + authnPsw );
110
+
111
+ final Hashtable <String , String > env = new Hashtable <String , String >(6 );
112
+ env .put (Context .INITIAL_CONTEXT_FACTORY , props .getProperty ("ldap.factory" ));
113
+ env .put (Context .PROVIDER_URL , pair .getFirst ().trim ());
114
+ env .put (Context .SECURITY_AUTHENTICATION , props .getProperty ("ldap.authentication" ));
115
+ env .put (Context .SECURITY_PRINCIPAL , result .getNameInNamespace ());
116
+ env .put (Context .SECURITY_CREDENTIALS , authnPsw );
117
+ env .put ("com.sun.jndi.ldap.connect.timeout" , props .getProperty ("ldap.timeout" ));
118
+ DirContext userCtx = new InitialDirContext (env );
119
+ theLogger .info ("Successfully authenticated " + result .getName () + " with password " + authnPsw + " at " + pair .getFirst ());
120
+ }
107
121
final NamingEnumeration <String > attrs = result .getAttributes ().getIDs ();
108
122
109
123
while (attrs .hasMoreElements ()) {
0 commit comments