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();
}
}
});
}
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;
}
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);
}
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();
}
}
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);
}
Aggregations