Search in sources :

Example 6 with ShutdownManager

use of org.forgerock.util.thread.listener.ShutdownManager 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 7 with ShutdownManager

use of org.forgerock.util.thread.listener.ShutdownManager in project OpenAM by OpenRock.

the class ShutdownMonitorTest method setup.

@BeforeTest
public void setup() {
    ShutdownManager shutdownManagerWrapper = mock(ShutdownManager.class);
    ArgumentCaptor<ShutdownListener> captor = ArgumentCaptor.forClass(ShutdownListener.class);
    monitor = new ShutdownMonitor(shutdownManagerWrapper);
    verify(shutdownManagerWrapper).addShutdownListener(captor.capture());
    listener = captor.getValue();
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with ShutdownManager

use of org.forgerock.util.thread.listener.ShutdownManager in project OpenAM by OpenRock.

the class ServerConfigMgr method main.

public static void main(String[] args) {
    try {
        Bootstrap.load();
        if (VersionCheck.isVersionValid() == 1) {
            System.exit(1);
        }
        debug = Debug.getInstance(IUMSConstants.UMS_DEBUG);
        validateArguments(args);
        boolean proceeded = printHelpMessage(args) || encryptPassword(args) || changePassword(args);
    } catch (ConfiguratorException ex) {
        System.err.println(ex.getL10NMessage(Locale.getDefault()));
        System.exit(1);
    } catch (Exception ex) {
        System.err.println(ex.getMessage());
        System.exit(1);
    } finally {
        ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
        shutdownMan.shutdown();
    }
}
Also used : ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager) ConfiguratorException(com.sun.identity.setup.ConfiguratorException) LoginException(javax.security.auth.login.LoginException) FileNotFoundException(java.io.FileNotFoundException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) XMLException(com.iplanet.services.util.XMLException) IOException(java.io.IOException) ConfiguratorException(com.sun.identity.setup.ConfiguratorException)

Example 9 with ShutdownManager

use of org.forgerock.util.thread.listener.ShutdownManager in project OpenAM by OpenRock.

the class PolicyEvaluator method init.

/**
     * Initializes an instance of client policy evaluator object
     *
     * @param serviceName name of the service for which to create 
     *        policy evaluator
     * @param appSSOTokenProvider an object where application single sign on
     *        token can be obtained.
     *
     * @throws PolicyException if required properties cannot be retrieved.
     * @throws SSOException if application single sign on token is invalid.
     *
     */
private void init(final String serviceName, AppSSOTokenProvider appSSOTokenProvider) throws PolicyException, SSOException {
    this.ssoTokenManager = SSOTokenManager.getInstance();
    this.serviceName = serviceName;
    this.appSSOTokenProvider = appSSOTokenProvider;
    this.policyProperties = new PolicyProperties();
    this.logActions = policyProperties.getLogActions();
    this.resourceResultCache = ResourceResultCache.getInstance(policyProperties);
    appSSOToken = getNewAppSSOToken();
    if (PolicyProperties.previouslyNotificationEnabled()) {
        if (policyProperties.useRESTProtocol()) {
            resourceResultCache.removeRESTRemotePolicyListener(appSSOToken, serviceName, PolicyProperties.getPreviousNotificationURL());
        } else {
            resourceResultCache.removeRemotePolicyListener(appSSOToken, serviceName, PolicyProperties.getPreviousNotificationURL());
        }
    }
    if (policyProperties.notificationEnabled()) {
        // register remote policy listener policy service
        if (debug.messageEnabled()) {
            debug.message("PolicyEvaluator.init():" + "adding remote policy listener with policy " + "service " + serviceName);
        }
        if (policyProperties.useRESTProtocol()) {
            resourceResultCache.addRESTRemotePolicyListener(appSSOToken, serviceName, policyProperties.getRESTNotificationURL());
        } else {
            resourceResultCache.addRemotePolicyListener(appSSOToken, serviceName, policyProperties.getNotificationURL());
        }
        // Add a hook to remove our listener on shutdown.
        ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
        shutdownMan.addShutdownListener(new ShutdownListener() {

            @Override
            public void shutdown() {
                if (policyProperties.useRESTProtocol()) {
                    resourceResultCache.removeRESTRemotePolicyListener(appSSOToken, serviceName, policyProperties.getRESTNotificationURL());
                    if (debug.messageEnabled()) {
                        debug.message("PolicyEvaluator: called removeRESTRemotePolicyListener, service " + serviceName + ", URL " + policyProperties.getRESTNotificationURL());
                    }
                } else {
                    resourceResultCache.removeRemotePolicyListener(appSSOToken, serviceName, policyProperties.getNotificationURL());
                    if (debug.messageEnabled()) {
                        debug.message("PolicyEvaluator: called removeRemotePolicyListener, service " + serviceName + ", URL " + policyProperties.getNotificationURL());
                    }
                }
            }
        });
    }
    ActionDecision.setClientClockSkew(policyProperties.getClientClockSkew());
    if (debug.messageEnabled()) {
        debug.message("PolicyEvaluator:" + "initialized PolicyEvaluator");
    }
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager)

Example 10 with ShutdownManager

use of org.forgerock.util.thread.listener.ShutdownManager in project OpenAM by OpenRock.

the class SessionPollerPool method initPollerPool.

/**
     * Configures the threadpool, and registers the threadpool with the shutdown manager so that it correctly
     * shuts down when the server is brought down.
     */
private synchronized void initPollerPool() {
    if (!pollerPoolInitialized) {
        if (pollingEnabled) {
            int poolSize = SystemProperties.getAsInt(Constants.POLLING_THREADPOOL_SIZE, DEFAULT_POOL_SIZE);
            int threshold = SystemProperties.getAsInt(Constants.POLLING_THREADPOOL_THRESHOLD, DEFAULT_THRESHOLD);
            final ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
            threadPool = new ThreadPool("amSessionPoller", poolSize, threshold, true, debug);
            shutdownMan.addShutdownListener(new ShutdownListener() {

                public void shutdown() {
                    threadPool.shutdown();
                    threadPool = null;
                    pollerPoolInitialized = false;
                }
            });
            pollerPoolInitialized = true;
        } else {
            if (debug.messageEnabled()) {
                debug.message("Session Cache cleanup is set to " + sessionCleanupEnabled);
            }
        }
    }
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ThreadPool(com.iplanet.am.util.ThreadPool) ShutdownManager(org.forgerock.util.thread.listener.ShutdownManager)

Aggregations

ShutdownManager (org.forgerock.util.thread.listener.ShutdownManager)11 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)10 ThreadPool (com.iplanet.am.util.ThreadPool)2 DSConfigMgr (com.iplanet.services.ldap.DSConfigMgr)2 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)2 ServerInstance (com.iplanet.services.ldap.ServerInstance)2 IOException (java.io.IOException)2 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)2 LDAPConnectionFactory (org.forgerock.opendj.ldap.LDAPConnectionFactory)2 SSLContextBuilder (org.forgerock.opendj.ldap.SSLContextBuilder)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 ServerGroup (com.iplanet.services.ldap.ServerGroup)1 XMLException (com.iplanet.services.util.XMLException)1 SSOException (com.iplanet.sso.SSOException)1 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 PolicyException (com.sun.identity.policy.PolicyException)1 ConfiguratorException (com.sun.identity.setup.ConfiguratorException)1 FileNotFoundException (java.io.FileNotFoundException)1 LoginException (javax.security.auth.login.LoginException)1