Search in sources :

Example 6 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class DataLayer method initLdapPool.

/**
     * Initialize the pool shared by all DataLayer object(s).
     */
private synchronized void initLdapPool() throws UMSException {
    // Don't do anything if pool is already initialized
    if (_ldapPool != null)
        return;
    /*
         * Initialize the pool with minimum and maximum connections settings
         * retrieved from configuration
         */
    ServerInstance svrCfg = null;
    String hostName = null;
    try {
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        hostName = dsCfg.getHostName("default");
        baseFactory = dsCfg.getNewProxyConnectionFactory();
        svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_PROXY);
    } catch (LDAPServiceException ex) {
        debug.error("Error initializing connection pool " + ex.getMessage());
    }
    // Check if svrCfg was successfully obtained
    if (svrCfg == null) {
        debug.error("Error getting server config.");
        String[] args = new String[1];
        args[0] = hostName == null ? "default" : hostName;
        throw new UMSException(i18n.getString(IUMSConstants.NEW_INSTANCE_FAILED, args));
    }
    int poolMin = svrCfg.getMinConnections();
    int poolMax = svrCfg.getMaxConnections();
    m_releaseConnectionBeforeSearchCompletes = svrCfg.getBooleanValue(LDAP_RELEASECONNBEFORESEARCH, false);
    if (debug.messageEnabled()) {
        debug.message("Creating ldap connection pool with: poolMin {}, poolMax {}", poolMin, poolMax);
    }
    int idleTimeout = SystemProperties.getAsInt(Constants.LDAP_CONN_IDLE_TIME_IN_SECS, 0);
    if (idleTimeout == 0) {
        debug.warning("Idle timeout not set. Defaulting to 0.");
    }
    _ldapPool = Connections.newCachedConnectionPool(Connections.newNamedConnectionFactory(baseFactory, "DataLayer"), poolMin, poolMax, idleTimeout, TimeUnit.SECONDS);
    ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
    shutdownMan.addShutdownListener(new ShutdownListener() {

        public void shutdown() {
            if (_ldapPool != null) {
                _ldapPool.close();
            }
        }
    });
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ByteString(org.forgerock.opendj.ldap.ByteString) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 7 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class DataLayer method getInstance.

/**
     * Create the singleton DataLayer object if it doesn't exist already.
     * Assumes the server instance for "LDAPUser.Type.AUTH_PROXY".
     *
     * @supported.api
     */
public static DataLayer getInstance() throws UMSException {
    // Make sure only one instance of this class is created.
    if (m_instance == null) {
        try {
            DSConfigMgr cfgMgr = DSConfigMgr.getDSConfigMgr();
            ServerInstance serverCfg = cfgMgr.getServerInstance(LDAPUser.Type.AUTH_PROXY);
            m_instance = getInstance(serverCfg);
        } catch (LDAPServiceException ex) {
            debug.error("Error:  Unable to get server config instance " + ex.getMessage());
        }
    }
    return m_instance;
}
Also used : DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 8 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class LDAPEventManager method getBase.

/**
     * Returns the base DN for the persistent searches. Since this function
     * can be called asynchronously by the EventService, should not have
     * dependency on any classes in SMS package.
     * @see com.iplanet.services.ldap.event.IDSEventListener#getBase()
     */
public String getBase() {
    if (baseDN != null) {
        return (baseDN);
    }
    try {
        // Obtain server instance for SMS, group=sms get baseDN
        // else use the default group
        ServerInstance serverInstance = null;
        DSConfigMgr mgr = DSConfigMgr.getDSConfigMgr();
        if (mgr != null) {
            // Try SMS first
            serverInstance = mgr.getServerInstance("sms", LDAPUser.Type.AUTH_PROXY);
            if (serverInstance == null) {
                serverInstance = mgr.getServerInstance(LDAPUser.Type.AUTH_PROXY);
                if (debug.messageEnabled()) {
                    debug.message("LDAPEventManager: SMS servergroup " + "not available. Using default AMSDK DN");
                }
            }
            if (serverInstance != null) {
                baseDN = serverInstance.getBaseDN();
            } else {
                if (debug.warningEnabled()) {
                    debug.warning("LDAPEventManager: SMS & AMSDK " + "servergroup not available. Using hardcoded value");
                }
            }
        } else {
            if (debug.warningEnabled()) {
                debug.warning("LDAPEventManager: DSConfigMgr is NULL " + "Using hardcoded value");
            }
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("LDAPEventManager: Exception obtaing baseDN " + "from DSConfigMgr and ServerInstances", e);
        }
    }
    if (baseDN == null) {
        debug.error("LDAPEventManager.getBase(): Unable to get base DN " + " from serverconfig.xml");
    }
    return ((baseDN == null) ? "o=isp" : baseDN);
}
Also used : DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ServerInstance(com.iplanet.services.ldap.ServerInstance) EventException(com.iplanet.services.ldap.event.EventException) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 9 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class SMDataLayer method initLdapPool.

/**
     * Initialize the pool shared by all SMDataLayer object(s).
     */
private synchronized void initLdapPool() {
    // Dont' do anything if pool is already initialized
    if (_ldapPool != null)
        return;
    // Initialize the pool with minimum and maximum connections settings
    // retrieved from configuration
    ServerInstance svrCfg;
    try {
        DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
        // Get "sms" ServerGroup if present
        ServerGroup sg = dsCfg.getServerGroup("sms");
        final ConnectionFactory baseFactory;
        if (sg != null) {
            baseFactory = dsCfg.getNewConnectionFactory("sms", LDAPUser.Type.AUTH_ADMIN);
            svrCfg = sg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        } else {
            baseFactory = dsCfg.getNewAdminConnectionFactory();
            svrCfg = dsCfg.getServerInstance(LDAPUser.Type.AUTH_ADMIN);
        }
        if (svrCfg == null) {
            debug.error("SMDataLayer:initLdapPool()-" + "Error getting server config.");
        }
        int poolMin = 1;
        int poolMax = 2;
        // Initialize the Connection Pool size only for the server
        if (SystemProperties.isServerMode()) {
            poolMin = svrCfg.getMinConnections();
            poolMax = svrCfg.getMaxConnections();
        }
        debug.message("SMDataLayer:initLdapPool(): Creating ldap connection pool with: poolMin {} poolMax {}", poolMin, poolMax);
        int idleTimeout = SystemProperties.getAsInt(LDAP_CONN_IDLE_TIME_IN_SECS, 0);
        if (idleTimeout == 0 && StringUtils.isNotBlank(SystemProperties.get(LDAP_CONN_IDLE_TIME_IN_SECS))) {
            debug.error("SMDataLayer: Idle timeout could not be parsed, connection reaping is disabled");
        } else if (idleTimeout == 0) {
            debug.message("SMDataLayer: Idle timeout is set to 0 - connection reaping is disabled");
        }
        _ldapPool = Connections.newCachedConnectionPool(baseFactory, poolMin, poolMax, idleTimeout, TimeUnit.SECONDS);
        ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
        shutdownMan.addShutdownListener(new ShutdownListener() {

            public void shutdown() {
                if (_ldapPool != null) {
                    _ldapPool.close();
                }
            }
        });
    } catch (LDAPServiceException ex) {
        debug.error("SMDataLayer:initLdapPool()-" + "Error initializing connection pool " + ex.getMessage());
        ex.printStackTrace();
    }
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) ServerGroup(com.iplanet.services.ldap.ServerGroup) DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) ServerInstance(com.iplanet.services.ldap.ServerInstance)

Example 10 with ServerInstance

use of com.iplanet.services.ldap.ServerInstance in project OpenAM by OpenRock.

the class ServerConfigurationFactoryTest method shouldIndicateInvalidIfServerGroupIsNull.

@Test(expectedExceptions = ServerConfigurationNotFound.class)
public void shouldIndicateInvalidIfServerGroupIsNull() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound {
    // Given
    ServerInstance mockInstance = mock(ServerInstance.class);
    DSConfigMgr mockConfig = mock(DSConfigMgr.class);
    given(mockConfig.getServerGroup(anyString())).willReturn(null);
    given(mockConfig.getServerInstance(anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance);
    ServerConfigurationFactory parser = new ServerConfigurationFactory(mockConfig);
    // When / Then
    parser.getServerConfiguration("", LDAPUser.Type.AUTH_ADMIN);
}
Also used : DSConfigMgr(com.iplanet.services.ldap.DSConfigMgr) ServerConfigurationFactory(org.forgerock.openam.sm.ServerConfigurationFactory) ServerInstance(com.iplanet.services.ldap.ServerInstance) Test(org.testng.annotations.Test)

Aggregations

ServerInstance (com.iplanet.services.ldap.ServerInstance)22 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)13 ServerGroup (com.iplanet.services.ldap.ServerGroup)11 Test (org.testng.annotations.Test)8 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)7 Server (com.iplanet.services.ldap.Server)4 IdRepoException (com.sun.identity.idm.IdRepoException)3 ServerConfigurationFactory (org.forgerock.openam.sm.ServerConfigurationFactory)3 LdapException (org.forgerock.opendj.ldap.LdapException)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 LoginException (javax.security.auth.login.LoginException)2 LDAPURL (org.forgerock.openam.ldap.LDAPURL)2 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)2 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)2 ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)2 Matchers.anyString (org.mockito.Matchers.anyString)2 EventException (com.iplanet.services.ldap.event.EventException)1 SSOToken (com.iplanet.sso.SSOToken)1