Search in sources :

Example 6 with Duration

use of org.forgerock.util.time.Duration 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)

Example 7 with Duration

use of org.forgerock.util.time.Duration in project OpenAM by OpenRock.

the class UserIdRepo method getLDAPConnection.

private Connection getLDAPConnection(Map userRepo) throws Exception {
    String userSSLStore = (String) userRepo.get(SetupConstants.USER_STORE_SSL);
    // All connections will use authentication.
    SimpleBindRequest request = LDAPRequests.newSimpleBindRequest(getBindDN(userRepo), getBindPassword(userRepo).toCharArray());
    Options options = Options.defaultOptions().set(REQUEST_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, request);
    if (userSSLStore != null && userSSLStore.equals("SSL")) {
        options = options.set(SSL_CONTEXT, SSLContext.getDefault());
    }
    return getConnectionFactory(getHost(userRepo), Integer.parseInt(getPort(userRepo)), options).getConnection();
}
Also used : Options(org.forgerock.util.Options) SimpleBindRequest(org.forgerock.opendj.ldap.requests.SimpleBindRequest) Duration(org.forgerock.util.time.Duration)

Example 8 with Duration

use of org.forgerock.util.time.Duration 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)

Example 9 with Duration

use of org.forgerock.util.time.Duration in project OpenAM by OpenRock.

the class AjaxPage method getConnection.

protected Connection getConnection(String host, int port, String bindDN, char[] bindPwd, int timeout, boolean isSSl) throws GeneralSecurityException, LdapException {
    Options ldapOptions = Options.defaultOptions().set(CONNECT_TIMEOUT, new Duration((long) timeout, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(bindDN, bindPwd));
    if (isSSl) {
        ldapOptions = ldapOptions.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
    }
    ConnectionFactory factory = new LDAPConnectionFactory(host, port, ldapOptions);
    return factory.getConnection();
}
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)

Example 10 with Duration

use of org.forgerock.util.time.Duration in project OpenAM by OpenRock.

the class LDAPRoles method initialize.

/** 
     * Initialize the LDAPGroup object by using the configuration
     * information passed by the Policy Framework.
     * @param configParams the configuration information
     * @exception PolicyException if an error occured during 
     * initialization of the instance
     */
public void initialize(Map configParams) throws PolicyException {
    if (configParams == null) {
        throw (new PolicyException(ResBundleUtils.rbName, "ldaproles_initialization_failed", null, null));
    }
    String configuredLdapServer = (String) configParams.get(PolicyConfig.LDAP_SERVER);
    if (configuredLdapServer == null) {
        debug.error("LDAPRoles.initialize(): failed to get LDAP " + "server name. If you enter more than one server name " + "in the policy config service's Primary LDAP Server " + "field, please make sure the ldap server name is preceded " + "with the local server name.");
        throw (new PolicyException(ResBundleUtils.rbName, "invalid_ldap_server_host", null, null));
    }
    ldapServer = configuredLdapServer.toLowerCase();
    localDS = PolicyUtils.isLocalDS(ldapServer);
    aliasEnabled = Boolean.valueOf((String) configParams.get(PolicyConfig.USER_ALIAS_ENABLED)).booleanValue();
    authid = (String) configParams.get(PolicyConfig.LDAP_BIND_DN);
    authpw = (String) configParams.get(PolicyConfig.LDAP_BIND_PASSWORD);
    if (authpw != null) {
        authpw = PolicyUtils.decrypt(authpw);
    }
    baseDN = (String) configParams.get(PolicyConfig.LDAP_BASE_DN);
    roleSearchFilter = (String) configParams.get(PolicyConfig.LDAP_ROLES_SEARCH_FILTER);
    String scope = (String) configParams.get(PolicyConfig.LDAP_ROLES_SEARCH_SCOPE);
    if (scope.equalsIgnoreCase(LDAP_SCOPE_BASE)) {
        roleSearchScope = SearchScope.BASE_OBJECT;
    } else if (scope.equalsIgnoreCase(LDAP_SCOPE_ONE)) {
        roleSearchScope = SearchScope.SINGLE_LEVEL;
    } else {
        roleSearchScope = SearchScope.WHOLE_SUBTREE;
    }
    roleRDNAttrName = (String) configParams.get(PolicyConfig.LDAP_ROLES_SEARCH_ATTRIBUTE);
    userSearchFilter = (String) configParams.get(PolicyConfig.LDAP_USERS_SEARCH_FILTER);
    scope = (String) configParams.get(PolicyConfig.LDAP_USERS_SEARCH_SCOPE);
    userSearchScope = LDAPUtils.getSearchScope(scope, SearchScope.WHOLE_SUBTREE);
    userRDNAttrName = (String) configParams.get(PolicyConfig.LDAP_USER_SEARCH_ATTRIBUTE);
    try {
        timeLimit = Integer.parseInt((String) configParams.get(PolicyConfig.LDAP_SEARCH_TIME_OUT));
        maxResults = Integer.parseInt((String) configParams.get(PolicyConfig.LDAP_SEARCH_LIMIT));
        minPoolSize = Integer.parseInt((String) configParams.get(PolicyConfig.LDAP_CONNECTION_POOL_MIN_SIZE));
        maxPoolSize = Integer.parseInt((String) configParams.get(PolicyConfig.LDAP_CONNECTION_POOL_MAX_SIZE));
    } catch (NumberFormatException nfe) {
        throw (new PolicyException(nfe));
    }
    String ssl = (String) configParams.get(PolicyConfig.LDAP_SSL_ENABLED);
    if (ssl.equalsIgnoreCase("true")) {
        sslEnabled = true;
    } else {
        sslEnabled = false;
    }
    // get the organization name
    Set orgNameSet = (Set) configParams.get(PolicyManager.ORGANIZATION_NAME);
    if ((orgNameSet != null) && (!orgNameSet.isEmpty())) {
        Iterator items = orgNameSet.iterator();
        orgName = (String) items.next();
    }
    if (debug.messageEnabled()) {
        debug.message("LDAPRoles.initialize(): getting params" + "\nldapServer: " + ldapServer + "\nauthid: " + authid + "\nbaseDN: " + baseDN + "\nroleSearchFilter: " + roleSearchFilter + "\nroleRDNAttrName: " + roleRDNAttrName + "\nuserSearchFilter: " + userSearchFilter + "\nuserRDNAttrName: " + userRDNAttrName + "\ntimeLimit: " + timeLimit + "\nmaxResults: " + maxResults + "\nminPoolSize: " + minPoolSize + "\nmaxPoolSize: " + maxPoolSize + "\nSSLEnabled: " + sslEnabled + "\nOrgName: " + orgName);
    }
    // initialize the connection pool for the ldap server
    Options options = Options.defaultOptions().set(REQUEST_TIMEOUT, new Duration((long) timeLimit, TimeUnit.MILLISECONDS));
    LDAPConnectionPools.initConnectionPool(ldapServer, authid, authpw, sslEnabled, minPoolSize, maxPoolSize, options);
    connPool = LDAPConnectionPools.getConnectionPool(ldapServer);
    initialized = true;
}
Also used : Options(org.forgerock.util.Options) HashSet(java.util.HashSet) Set(java.util.Set) PolicyException(com.sun.identity.policy.PolicyException) Iterator(java.util.Iterator) Duration(org.forgerock.util.time.Duration) ByteString(org.forgerock.opendj.ldap.ByteString)

Aggregations

Duration (org.forgerock.util.time.Duration)15 Options (org.forgerock.util.Options)14 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)9 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)7 ByteString (org.forgerock.opendj.ldap.ByteString)4 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)4 PolicyException (com.sun.identity.policy.PolicyException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)3 LdapException (org.forgerock.opendj.ldap.LdapException)3 ShutdownManager (com.sun.identity.common.ShutdownManager)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 SimpleBindRequest (org.forgerock.opendj.ldap.requests.SimpleBindRequest)2 IdRepoException (com.sun.identity.idm.IdRepoException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 StringTokenizer (java.util.StringTokenizer)1