use of org.forgerock.util.thread.listener.ShutdownListener in project OpenAM by OpenRock.
the class LDAPConnectionPools method initConnectionPool.
/**
* Create a Ldap Connection Pool for a ldap server
* @param host the name of the LDAP server host and its port number.
* For example, dsame.sun.com:389
* Alternatively, this can be a space-delimited list of
* host names.
* @param ssl if the connection is in ssl
* @param minPoolSize minimal pool size
* @param maxPoolSize maximum pool size
*/
static void initConnectionPool(String host, String authDN, String authPasswd, boolean ssl, int minPoolSize, int maxPoolSize, Options options) throws PolicyException {
if (host.length() < 1) {
debug.message("Invalid host name");
throw new PolicyException(ResBundleUtils.rbName, "invalid_ldap_server_host", null, null);
}
try {
synchronized (connectionPools) {
if (connectionPools.get(host) == null) {
if (debug.messageEnabled()) {
debug.message("Create LDAPConnectionPool: " + host);
}
if (ssl) {
options.set(LDAPConnectionFactory.SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
}
ConnectionFactory ldc = LDAPUtils.createFailoverConnectionFactory(host, DEFAULT_PORT, authDN, authPasswd, options);
if (minPoolSize < 1) {
minPoolSize = MIN_CONNECTION_POOL_SIZE;
}
if (maxPoolSize < 1) {
maxPoolSize = MAX_CONNECTION_POOL_SIZE;
}
debug.message("LDAPConnectionPools.initConnectionPool(): minPoolSize={}, maxPoolSize={}", minPoolSize, maxPoolSize);
ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
int idleTimeout = SystemProperties.getAsInt(Constants.LDAP_CONN_IDLE_TIME_IN_SECS, 0);
if (idleTimeout == 0) {
debug.error("LDAPConnectionPools: Idle timeout could not be parsed, connection reaping is disabled");
}
final ConnectionFactory cPool = Connections.newCachedConnectionPool(ldc, minPoolSize, maxPoolSize, idleTimeout, TimeUnit.SECONDS);
debug.message("LDAPConnectionPools.initConnectionPool(): host: {}", host);
shutdownMan.addShutdownListener(new ShutdownListener() {
public void shutdown() {
cPool.close();
}
});
connectionPools.put(host, cPool);
}
}
} catch (Exception e) {
debug.message("Unable to create LDAPConnectionPool", e);
throw new PolicyException(e.getMessage(), e);
}
}
use of org.forgerock.util.thread.listener.ShutdownListener in project OpenAM by OpenRock.
the class UserIdRepo method getConnectionFactory.
private synchronized ConnectionFactory getConnectionFactory(String hostname, int port, Options options) {
if (factory == null) {
factory = new LDAPConnectionFactory(hostname, port, options);
ShutdownManager.getInstance().addShutdownListener(new ShutdownListener() {
@Override
public void shutdown() {
if (factory != null) {
factory.close();
}
}
});
}
return factory;
}
use of org.forgerock.util.thread.listener.ShutdownListener 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;
}
use of org.forgerock.util.thread.listener.ShutdownListener 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();
}
use of org.forgerock.util.thread.listener.ShutdownListener 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");
}
}
Aggregations