private DirContext bind ( String bindDn , ProtectedString bindPw ) throws NamingException { Hashtable < Object , Object > env = new Hashtable < Object , Object > ( ) ; String url = this . idStoreDefinition . getUrl ( ) ; if ( url == null || url . isEmpty ( ) ) { throw new IllegalArgumentException ( "No URL was provided to the LdapIdentityStore." ) ; } env . put ( Context . INITIAL_CONTEXT_FACTORY , "com.sun.jndi.ldap.LdapCtxFactory" ) ; env . put ( Context . PROVIDER_URL , url ) ; boolean sslEnabled = url != null && url . startsWith ( "ldaps" ) ; if ( sslEnabled ) { env . put ( "java.naming.ldap.factory.socket" , "com.ibm.ws.ssl.protocol.LibertySSLSocketFactory" ) ; env . put ( Context . SECURITY_PROTOCOL , "ssl" ) ; } /* * Add credentials. */ if ( bindDn != null && ! bindDn . isEmpty ( ) && bindPw != null ) { /* * Support encoded passwords. */ String decodedBindPw = PasswordUtil . passwordDecode ( new String ( bindPw . getChars ( ) ) . trim ( ) ) ; if ( decodedBindPw == null || decodedBindPw . isEmpty ( ) ) { throw new IllegalArgumentException ( "An empty password is invalid." ) ; } env . put ( Context . SECURITY_PRINCIPAL , bindDn ) ; env . put ( Context . SECURITY_CREDENTIALS , decodedBindPw ) ; } if ( tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "JNDI_CALL bind" , new Object [ ] { bindDn , url } ) ; } return getDirContext ( env ) ; }
Bind to the LDAP server .