use of org.apache.directory.ldap.client.api.LdapConnectionPool in project Singularity by HubSpot.
the class SingularityLDAPDatastore method createConnectionPool.
private static LdapConnectionPool createConnectionPool(LDAPConfiguration configuration) throws IOException {
final LdapConnectionConfig config = new LdapConnectionConfig();
config.setLdapHost(configuration.getHostname());
config.setLdapPort(configuration.getPort());
config.setName(configuration.getBindDn());
config.setCredentials(configuration.getBindPassword());
final DefaultPoolableLdapConnectionFactory factory = new DefaultPoolableLdapConnectionFactory(config);
final LdapConnectionPool pool = new LdapConnectionPool(factory);
pool.setTestOnBorrow(configuration.isPoolTestOnBorrow());
pool.setTestOnReturn(configuration.isPoolTestOnReturn());
pool.setTestWhileIdle(configuration.isPoolTestWhileIdle());
pool.setMaxActive(configuration.getPoolMaxActive());
pool.setMaxIdle(configuration.getPoolMaxIdle());
pool.setMinIdle(configuration.getPoolMinIdle());
pool.setMaxWait(configuration.getPoolMaxWait());
switch(configuration.getPoolWhenExhaustedAction()) {
case BLOCK:
pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_BLOCK);
break;
case FAIL:
pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_FAIL);
break;
case GROW:
pool.setWhenExhaustedAction(LdapConnectionPool.WHEN_EXHAUSTED_GROW);
break;
default:
pool.setWhenExhaustedAction(LdapConnectionPool.DEFAULT_WHEN_EXHAUSTED_ACTION);
}
return pool;
}
use of org.apache.directory.ldap.client.api.LdapConnectionPool in project jackrabbit-oak by apache.
the class LdapIdentityProvider method init.
// ------------------------------------------------------------< private >---
/**
* Initializes the ldap identity provider.
*/
private void init() {
if (adminConnectionFactory != null) {
throw new IllegalStateException("Provider already initialized.");
}
// make sure the JVM supports the TLSv1.1
try {
enabledSSLProtocols = null;
SSLContext.getInstance("TLSv1.1");
} catch (NoSuchAlgorithmException e) {
log.warn("JDK does not support TLSv1.1. Disabling it.");
enabledSSLProtocols = new String[] { "TLSv1" };
}
// setup admin connection pool
LdapConnectionConfig cc = createConnectionConfig();
String bindDN = config.getBindDN();
if (bindDN != null && !bindDN.isEmpty()) {
cc.setName(bindDN);
cc.setCredentials(config.getBindPassword());
}
adminConnectionFactory = new ValidatingPoolableLdapConnectionFactory(cc);
if (config.getAdminPoolConfig().lookupOnValidate()) {
adminConnectionFactory.setValidator(new LookupLdapConnectionValidator());
} else {
adminConnectionFactory.setValidator(new DefaultLdapConnectionValidator());
}
if (config.getAdminPoolConfig().getMaxActive() != 0) {
adminPool = new LdapConnectionPool(adminConnectionFactory);
adminPool.setTestOnBorrow(true);
adminPool.setMaxActive(config.getAdminPoolConfig().getMaxActive());
adminPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
}
// setup unbound connection pool. let's create a new version of the config
cc = createConnectionConfig();
userConnectionFactory = new PoolableUnboundConnectionFactory(cc);
if (config.getUserPoolConfig().lookupOnValidate()) {
userConnectionFactory.setValidator(new UnboundLookupConnectionValidator());
} else {
userConnectionFactory.setValidator(new UnboundConnectionValidator());
}
if (config.getUserPoolConfig().getMaxActive() != 0) {
userPool = new UnboundLdapConnectionPool(userConnectionFactory);
userPool.setTestOnBorrow(true);
userPool.setMaxActive(config.getUserPoolConfig().getMaxActive());
userPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK);
}
log.info("LdapIdentityProvider initialized: {}", config);
}
use of org.apache.directory.ldap.client.api.LdapConnectionPool in project directory-fortress-core by apache.
the class LdapConnectionProvider method init.
/**
* Initialize the three connection pools using settings and coordinates contained in the config.
*/
private void init() {
IS_SSL = (Config.getInstance().getProperty(GlobalIds.ENABLE_LDAP_SSL) != null && Config.getInstance().getProperty(GlobalIds.ENABLE_LDAP_SSL).equalsIgnoreCase("true") && Config.getInstance().getProperty(GlobalIds.TRUST_STORE) != null && Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW, true) != null);
String host = Config.getInstance().getProperty(GlobalIds.LDAP_HOST, "localhost");
int port = Config.getInstance().getInt(GlobalIds.LDAP_PORT, 389);
int min = Config.getInstance().getInt(GlobalIds.LDAP_ADMIN_POOL_MIN, 1);
int max = Config.getInstance().getInt(GlobalIds.LDAP_ADMIN_POOL_MAX, 10);
int logmin = Config.getInstance().getInt(LDAP_LOG_POOL_MIN, 1);
int logmax = Config.getInstance().getInt(LDAP_LOG_POOL_MAX, 10);
LOG.info("LDAP POOL: host=[{}], port=[{}], min=[{}], max=[{}]", host, port, min, max);
LdapConnectionConfig config = new LdapConnectionConfig();
config.setLdapHost(host);
config.setLdapPort(port);
config.setName(Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_UID, ""));
config.setUseSsl(IS_SSL);
if (Config.getInstance().getBoolean(ENABLE_LDAP_STARTTLS, false)) {
config.setUseTls(true);
}
if (IS_SSL && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE)) && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW))) {
// validate certificates but allow self-signed certs if within this truststore:
config.setTrustManagers(new LdapClientTrustStoreManager(Config.getInstance().getProperty(GlobalIds.TRUST_STORE), Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW).toCharArray(), null, true));
}
String adminPw;
if (EncryptUtil.isEnabled()) {
adminPw = EncryptUtil.getInstance().decrypt(Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_PW, true));
} else {
adminPw = Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_PW, true);
}
config.setCredentials(adminPw);
try {
List<String> listExOps = new ArrayList<>();
listExOps.add("org.openldap.accelerator.impl.createSession.RbacCreateSessionFactory");
listExOps.add("org.openldap.accelerator.impl.checkAccess.RbacCheckAccessFactory");
listExOps.add("org.openldap.accelerator.impl.addRole.RbacAddRoleFactory");
listExOps.add("org.openldap.accelerator.impl.dropRole.RbacDropRoleFactory");
listExOps.add("org.openldap.accelerator.impl.deleteSession.RbacDeleteSessionFactory");
listExOps.add("org.openldap.accelerator.impl.sessionRoles.RbacSessionRolesFactory");
LdapApiService ldapApiService = new StandaloneLdapApiService(new ArrayList<String>(), listExOps);
if (!LdapApiServiceFactory.isInitialized()) {
LdapApiServiceFactory.initialize(ldapApiService);
}
config.setLdapApiService(ldapApiService);
} catch (Exception ex) {
String error = "Exception caught initializing Admin Pool: " + ex;
throw new CfgRuntimeException(GlobalErrIds.FT_APACHE_LDAP_POOL_INIT_FAILED, error, ex);
}
PoolableObjectFactory<LdapConnection> poolFactory = new ValidatingPoolableLdapConnectionFactory(config);
// Create the Admin pool
adminPool = new LdapConnectionPool(poolFactory);
adminPool.setTestOnBorrow(true);
adminPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
adminPool.setMaxActive(max);
adminPool.setMinIdle(min);
adminPool.setMaxIdle(-1);
// adminPool.setMaxWait( 0 );
// Create the User pool
userPool = new LdapConnectionPool(poolFactory);
userPool.setTestOnBorrow(true);
userPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
userPool.setMaxActive(max);
userPool.setMinIdle(min);
userPool.setMaxIdle(-1);
// To enable, set {@code log.admin.user} && {@code log.admin.pw} inside fortress.properties file:
if (StringUtils.isNotEmpty(LDAP_LOG_POOL_UID) && StringUtils.isNotEmpty(LDAP_LOG_POOL_PW)) {
// Initializing the log pool in static block requires static props set within fortress.properties.
// To make this dynamic requires moving this code outside of static block AND storing the connection
// metadata inside fortress config node (in ldap).
LdapConnectionConfig logConfig = new LdapConnectionConfig();
logConfig.setLdapHost(host);
logConfig.setLdapPort(port);
logConfig.setName(Config.getInstance().getProperty(GlobalIds.LDAP_ADMIN_POOL_UID, ""));
logConfig.setUseSsl(IS_SSL);
if (IS_SSL && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE)) && StringUtils.isNotEmpty(Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW, true))) {
// validate certificates but allow self-signed certs if within this truststore:
logConfig.setTrustManagers(new LdapClientTrustStoreManager(Config.getInstance().getProperty(GlobalIds.TRUST_STORE), Config.getInstance().getProperty(GlobalIds.TRUST_STORE_PW, true).toCharArray(), null, true));
}
logConfig.setName(Config.getInstance().getProperty(LDAP_LOG_POOL_UID, ""));
String logPw;
if (EncryptUtil.isEnabled()) {
logPw = EncryptUtil.getInstance().decrypt(Config.getInstance().getProperty(LDAP_LOG_POOL_PW, true));
} else {
logPw = Config.getInstance().getProperty(LDAP_LOG_POOL_PW, true);
}
logConfig.setCredentials(logPw);
poolFactory = new ValidatingPoolableLdapConnectionFactory(logConfig);
logPool = new LdapConnectionPool(poolFactory);
logPool.setTestOnBorrow(true);
logPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
logPool.setMaxActive(logmax);
logPool.setMinIdle(logmin);
}
}
use of org.apache.directory.ldap.client.api.LdapConnectionPool in project directory-ldap-api by apache.
the class ApiLdapClientApiOsgiTest method useBundleClasses.
@Override
protected void useBundleClasses() throws Exception {
new LdapNetworkConnection().close();
new SaslGssApiRequest();
new Krb5LoginConfiguration();
new AddFuture(new LdapNetworkConnection(), 2);
new LdapConnectionTemplate(new LdapConnectionPool(new DefaultPoolableLdapConnectionFactory(new LdapConnectionConfig())));
FilterBuilder.and(FilterBuilder.not(FilterBuilder.contains("cn", "a", "b"))).toString();
// Test for DIRAPI-239
PoolableObjectFactory<LdapConnection> factory = new DefaultPoolableLdapConnectionFactory(new LdapConnectionConfig());
Config config = new Config();
LdapConnectionPool ldapConnectionPool = new LdapConnectionPool(factory, config);
ldapConnectionPool.getLdapApiService();
ldapConnectionPool.getTestOnBorrow();
}
Aggregations