@ SuppressWarnings ( "unchecked" ) public Hashtable getEnvironment ( ) { Properties env = new Properties ( ) ; env . put ( Context . INITIAL_CONTEXT_FACTORY , _contextFactory ) ; String url = null ; if ( _providerUrl != null ) { url = _providerUrl ; } else { if ( _hostname != null ) { url = "ldap://" + _hostname + "/" ; if ( _port != 0 ) { url += ":" + _port + "/" ; } LOG . warn ( "Using hostname and port. Use providerUrl instead: " + url ) ; } } env . put ( Context . PROVIDER_URL , url ) ; if ( _authenticationMethod != null ) { env . put ( Context . SECURITY_AUTHENTICATION , _authenticationMethod ) ; } if ( _bindDn != null ) { env . put ( Context . SECURITY_PRINCIPAL , _bindDn ) ; } if ( _bindPassword != null ) { env . put ( Context . SECURITY_CREDENTIALS , _bindPassword ) ; } env . put ( "com.sun.jndi.ldap.read.timeout" , Long . toString ( _timeoutRead ) ) ; env . put ( "com.sun.jndi.ldap.connect.timeout" , Long . toString ( _timeoutConnect ) ) ; // Set the SSLContextFactory to implementation that validates cert subject if ( url != null && url . startsWith ( "ldaps" ) && _ldapsVerifyHostname ) { try { URI uri = new URI ( url ) ; HostnameVerifyingSSLSocketFactory . setTargetHost ( uri . getHost ( ) ) ; env . put ( "java.naming.ldap.factory.socket" , "com.dtolabs.rundeck.jetty.jaas.HostnameVerifyingSSLSocketFactory" ) ; } catch ( URISyntaxException e ) { throw new RuntimeException ( e ) ; } } return env ; }
get the context for connection