use of org.apache.directory.fortress.core.CfgRuntimeException 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.fortress.core.CfgRuntimeException in project directory-fortress-core by apache.
the class Config method loadRemoteConfig.
/**
* Load the properties contained within ou=Config node in LDAP.
*/
private void loadRemoteConfig() {
try {
// Retrieve parameters from the config node stored in target LDAP DIT:
String realmName = config.getString(GlobalIds.CONFIG_REALM, "DEFAULT");
if (realmName != null && realmName.length() > 0) {
LOG.info("static init: load config realm [{}]", realmName);
Properties props = getRemoteConfig(realmName);
if (props != null) {
for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
String val = props.getProperty(key);
config.setProperty(key, val);
}
}
// init ldap util vals since config is stored on server
boolean ldapfilterSizeFound = (getProperty(GlobalIds.LDAP_FILTER_SIZE_PROP) != null);
LdapUtil.getInstance().setLdapfilterSizeFound(ldapfilterSizeFound);
LdapUtil.getInstance().setLdapMetaChars(loadLdapEscapeChars());
LdapUtil.getInstance().setLdapReplVals(loadValidLdapVals());
try {
String lenProp = getProperty(GlobalIds.LDAP_FILTER_SIZE_PROP);
if (ldapfilterSizeFound) {
LdapUtil.getInstance().setLdapFilterSize(Integer.valueOf(lenProp));
}
} catch (java.lang.NumberFormatException nfe) {
String error = "loadRemoteConfig caught NumberFormatException=" + nfe;
LOG.warn(error);
}
remoteConfigLoaded = true;
} else {
LOG.info("static init: config realm not setup");
}
} catch (SecurityException se) {
String error = "static init: Error loading from remote config: SecurityException=" + se;
LOG.error(error);
throw new CfgRuntimeException(GlobalErrIds.FT_CONFIG_INITIALIZE_FAILED, error, se);
}
}
use of org.apache.directory.fortress.core.CfgRuntimeException in project directory-fortress-core by apache.
the class Config method loadLocalConfig.
/**
* Load the config parameters from fortress.properties file.
*/
private void loadLocalConfig() {
try {
// Load the system config file.
URL fUrl = Config.class.getClassLoader().getResource(PROP_FILE);
config.setDelimiterParsingDisabled(true);
if (fUrl == null) {
String error = "static init: Error, null cfg file: " + PROP_FILE;
LOG.warn(error);
} else {
LOG.info("static init: found from: {} path: {}", PROP_FILE, fUrl.getPath());
config.load(fUrl);
LOG.info("static init: loading from: {}", PROP_FILE);
}
URL fUserUrl = Config.class.getClassLoader().getResource(USER_PROP_FILE);
if (fUserUrl != null) {
LOG.info("static init: found user properties from: {} path: {}", USER_PROP_FILE, fUserUrl.getPath());
config.load(fUserUrl);
}
} catch (org.apache.commons.configuration.ConfigurationException ex) {
String error = "static init: Error loading from cfg file: [" + PROP_FILE + "] ConfigurationException=" + ex;
LOG.error(error);
throw new CfgRuntimeException(GlobalErrIds.FT_CONFIG_BOOTSTRAP_FAILED, error, ex);
}
}
use of org.apache.directory.fortress.core.CfgRuntimeException in project directory-fortress-core by apache.
the class CacheFactory method createInstance.
/**
* Create and return a reference to {@link Cache} object.
*
* @return instance of {@link Cache}.
*/
public static Cache createInstance(String name, net.sf.ehcache.CacheManager cacheManager) {
net.sf.ehcache.Ehcache cache = cacheManager.getEhcache(name);
if (cache == null) {
String error = "createInstance cache: " + name + " is null";
throw new CfgRuntimeException(GlobalErrIds.FT_CACHE_NOT_CONFIGURED, error);
}
BlockingCache blockingCache = new BlockingCache(cache);
blockingCache.setTimeoutMillis(60000);
cacheManager.replaceCacheWithDecoratedCache(cache, blockingCache);
return new EhCacheImpl(name, blockingCache);
}
Aggregations