use of org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService in project wildfly-camel by wildfly-extras.
the class LdapIntegrationTest method getWiredContext.
private LdapContext getWiredContext(int port) throws Exception {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://" + InetAddress.getLocalHost().getHostName() + ":" + port);
env.put(Context.SECURITY_PRINCIPAL, ServerDNConstants.ADMIN_SYSTEM_DN);
env.put(Context.SECURITY_CREDENTIALS, "secret");
LdapApiService ldapApiService = new StandaloneLdapApiService();
return new InitialLdapContext(env, JndiUtils.toJndiControls(ldapApiService));
}
use of org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService 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);
}
}
Aggregations