Search in sources :

Example 1 with Options

use of org.forgerock.util.Options in project OpenAM by OpenRock.

the class AMSetupDSConfig method getLDAPConnection.

/**
     * Helper method to return Ldap connection 
     *
     * @param ssl <code>true</code> if directory server is running SSL.
     * @return Ldap connection 
     */
private synchronized Connection getLDAPConnection(boolean ssl) {
    try {
        if (ld == null) {
            ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
            // All connections will use authentication
            SimpleBindRequest request = LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray());
            Options options = Options.defaultOptions().set(REQUEST_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, request);
            if (ssl) {
                options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
            }
            ld = new LDAPConnectionFactory(dsHostName, getPort(), options);
            shutdownMan.addShutdownListener(new ShutdownListener() {

                public void shutdown() {
                    disconnectDServer();
                }
            });
        }
        return ld.getConnection();
    } catch (LdapException e) {
        disconnectDServer();
        dsConfigInstance = null;
        ld = null;
    } catch (Exception e) {
        dsConfigInstance = null;
        ld = null;
    }
    return null;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) Options(org.forgerock.util.Options) SimpleBindRequest(org.forgerock.opendj.ldap.requests.SimpleBindRequest) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) Duration(org.forgerock.util.time.Duration) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) SSLContextBuilder(org.forgerock.opendj.ldap.SSLContextBuilder) LdapException(org.forgerock.opendj.ldap.LdapException) LdapException(org.forgerock.opendj.ldap.LdapException) IOException(java.io.IOException)

Example 2 with Options

use of org.forgerock.util.Options in project OpenAM by OpenRock.

the class IdRepoUtils method getLDAPConnection.

private static ConnectionFactory getLDAPConnection(Map attrValues) throws Exception {
    Options options = Options.defaultOptions().set(CONNECT_TIMEOUT, new Duration((long) 300, TimeUnit.MILLISECONDS));
    if (CollectionHelper.getBooleanMapAttr(attrValues, "sun-idrepo-ldapv3-config-ssl-enabled", false)) {
        options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
    }
    Set<LDAPURL> ldapUrls = getLDAPUrls(attrValues);
    if (CollectionUtils.isEmpty(ldapUrls)) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdRepoUtils.getLDAPConnection: No LDAPURLs found");
        }
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_AUTHENTICATE_LDAP_SERVER, null);
    }
    LDAPURL ldapUrl = ldapUrls.iterator().next();
    if (org.forgerock.openam.utils.StringUtils.isEmpty(ldapUrl.getHost())) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdRepoUtils.getLDAPConnection: No LDAP host found");
        }
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_AUTHENTICATE_LDAP_SERVER, null);
    }
    // All connections will use authentication
    String bindDn = CollectionHelper.getMapAttr(attrValues, "sun-idrepo-ldapv3-config-authid");
    if (org.forgerock.openam.utils.StringUtils.isBlank(bindDn)) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdRepoUtils.getLDAPConnection: No LDAP bindDN found");
        }
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_AUTHENTICATE_LDAP_SERVER, null);
    }
    String bindPwd = CollectionHelper.getMapAttr(attrValues, "sun-idrepo-ldapv3-config-authpw");
    if (org.forgerock.openam.utils.StringUtils.isBlank(bindPwd)) {
        if (DEBUG.warningEnabled()) {
            DEBUG.warning("IdRepoUtils.getLDAPConnection: No LDAP bindPW found");
        }
        throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.UNABLE_AUTHENTICATE_LDAP_SERVER, null);
    }
    options = options.set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(bindDn, bindPwd.toCharArray()));
    return new LDAPConnectionFactory(ldapUrl.getHost(), ldapUrl.getPort(), options);
}
Also used : Options(org.forgerock.util.Options) LDAPURL(org.forgerock.openam.ldap.LDAPURL) IdRepoException(com.sun.identity.idm.IdRepoException) Duration(org.forgerock.util.time.Duration) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) SSLContextBuilder(org.forgerock.opendj.ldap.SSLContextBuilder)

Example 3 with Options

use of org.forgerock.util.Options in project OpenAM by OpenRock.

the class UpgradeUtils method getLDAPConnection.

/**
     * Helper method to return Ldap connection
     *
     * @return Ldap connection
     */
private static Connection getLDAPConnection() {
    String classMethod = "UpgradeUtils:getLDAPConnection : ";
    if (debug.messageEnabled()) {
        debug.message(classMethod + "Directory Server Host: " + dsHostName);
        debug.message(classMethod + "Directory Server Port: " + dsPort);
        debug.message(classMethod + "Direcotry Server DN: " + dsManager);
    }
    try {
        // All connections will use authentication.
        Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray())).set(CONNECT_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS));
        return getLDAPConnectionFactory(dsHostName, dsPort, options).getConnection();
    } catch (LdapException e) {
        debug.error(classMethod + " Error getting LDAP Connection");
    }
    return null;
}
Also used : Options(org.forgerock.util.Options) Duration(org.forgerock.util.time.Duration) ByteString(org.forgerock.opendj.ldap.ByteString) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 4 with Options

use of org.forgerock.util.Options in project OpenAM by OpenRock.

the class LdapConnectionFactoryProvider method createFactory.

/**
     * Creates instances of ConnectionFactory which are aware of the need to share the
     * DataLayer and CTS connections in the same connection pool.
     *
     * @return {@inheritDoc}
     */
public ConnectionFactory<Connection> createFactory() throws InvalidConfigurationException {
    ConnectionConfig config = configFactory.getConfig(connectionType);
    int timeout = timeoutConfig.getTimeout(connectionType);
    Options options = Options.defaultOptions().set(REQUEST_TIMEOUT, new Duration((long) timeout, TimeUnit.SECONDS));
    debug("Creating Embedded Factory:\nURL: {0}\nMax Connections: {1}\nHeartbeat: {2}\nOperation Timeout: {3}", config.getLDAPURLs(), config.getMaxConnections(), config.getLdapHeartbeat(), timeout);
    final org.forgerock.opendj.ldap.ConnectionFactory ldapConnectionFactory = LDAPUtils.newFailoverConnectionPool(config.getLDAPURLs(), config.getBindDN(), config.getBindPassword(), config.getMaxConnections(), config.getLdapHeartbeat(), SECONDS.toString(), options);
    return new LdapConnectionFactory(ldapConnectionFactory);
}
Also used : Options(org.forgerock.util.Options) Duration(org.forgerock.util.time.Duration) ConnectionConfig(org.forgerock.openam.sm.ConnectionConfig)

Example 5 with Options

use of org.forgerock.util.Options in project OpenAM by OpenRock.

the class EmbeddedOpenDS method getLDAPConnectionFactory.

private static synchronized ConnectionFactory getLDAPConnectionFactory(String dsHostName, String dsPort, String dsManager, String dsAdminPwd) {
    if (factory == null) {
        // All connections will use authentication
        Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray())).set(CONNECT_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS));
        factory = new LDAPConnectionFactory(dsHostName, Integer.parseInt(dsPort), options);
        ShutdownManager.getInstance().addShutdownListener(new ShutdownListener() {

            @Override
            public void shutdown() {
                if (factory != null) {
                    factory.close();
                }
            }
        });
    }
    return factory;
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) Options(org.forgerock.util.Options) Duration(org.forgerock.util.time.Duration) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory)

Aggregations

Options (org.forgerock.util.Options)22 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)16 Duration (org.forgerock.util.time.Duration)14 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)8 ByteString (org.forgerock.opendj.ldap.ByteString)7 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)7 GeneralSecurityException (java.security.GeneralSecurityException)6 LdapException (org.forgerock.opendj.ldap.LdapException)6 IOException (java.io.IOException)4 SimpleBindRequest (org.forgerock.opendj.ldap.requests.SimpleBindRequest)4 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)4 PolicyException (com.sun.identity.policy.PolicyException)3 Connection (org.forgerock.opendj.ldap.Connection)3 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)2 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)2 ShutdownManager (com.sun.identity.common.ShutdownManager)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2