Search in sources :

Example 11 with SSLContextBuilder

use of org.forgerock.opendj.ldap.SSLContextBuilder in project OpenAM by OpenRock.

the class ServiceBase method getLDAPConnection.

/**
     * Returns a LDAP connection to the directory host.
     *
     * @param dsHostName name of the sever where DS is installed
     * @param dsPort port at which the directory server is listening
     * @param dsProtocol protocol used by directory server
     * @param dsManager admin user name for directory server
     * @param dsAdminPwd  admin password used by admin user name
     * @return LDAP connection
     */
protected static Connection getLDAPConnection(String dsHostName, int dsPort, String dsProtocol, String dsManager, String dsAdminPwd) {
    try {
        // All connections will use authentication
        Options options = Options.defaultOptions().set(CONNECT_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray()));
        if (dsProtocol.equalsIgnoreCase("ldaps")) {
            options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
        }
        ConnectionFactory factory = new LDAPConnectionFactory(dsHostName, dsPort, options);
        return factory.getConnection();
    } catch (Exception ignored) {
        return null;
    }
}
Also used : Options(org.forgerock.util.Options) ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) Duration(org.forgerock.util.time.Duration) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) SSLContextBuilder(org.forgerock.opendj.ldap.SSLContextBuilder) LdapException(org.forgerock.opendj.ldap.LdapException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)11 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)11 Options (org.forgerock.util.Options)8 Duration (org.forgerock.util.time.Duration)7 GeneralSecurityException (java.security.GeneralSecurityException)5 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)5 LdapException (org.forgerock.opendj.ldap.LdapException)5 IOException (java.io.IOException)4 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)3 ByteString (org.forgerock.opendj.ldap.ByteString)2 Connection (org.forgerock.opendj.ldap.Connection)2 SimpleBindRequest (org.forgerock.opendj.ldap.requests.SimpleBindRequest)2 ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)2 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)1 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 ServerInstance (com.iplanet.services.ldap.ServerInstance)1 ShutdownManager (com.sun.identity.common.ShutdownManager)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 PolicyException (com.sun.identity.policy.PolicyException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1