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; }
/** * Gets the admin pool. * * @param ldapServer the ldap server * @return the admin pool */ private static LdapConnectionPool getAdminPool( LdapServer ldapServer ) { int port = ldapServer.getPort(); if ( !POOLS.containsKey( port ) ) { LdapConnectionConfig config = new LdapConnectionConfig(); config.setLdapHost( Network.LOOPBACK_HOSTNAME ); config.setLdapPort( port ); config.setName( DEFAULT_ADMIN ); config.setCredentials( DEFAULT_PASSWORD ); DefaultPoolableLdapConnectionFactory factory = new DefaultPoolableLdapConnectionFactory( config ); LdapConnectionPool pool = new LdapConnectionPool( factory ); pool.setTestOnBorrow( true ); POOLS.put( port, pool ); } return POOLS.get( port ); }
public LdapUserDAO(SecurityServiceConfiguration config, boolean useCache) { this.connConfig = config.getLdapConnectionConfig(); this.requests = config.getLdapSearch(); this.useBindTemplate = config.isUseLdapBindTemplate(); this.bindTemplate = config.getLdapBindTemplate(); this.ldapBindAttribute = config.getLdapBindAttribute(); this.ldapSearchAttribute = "%" + config.getLdapSearchAttribute() + "%"; PoolableObjectFactory<LdapConnection> userPoolFactory = new ValidatingPoolableLdapConnectionFactory (connConfig); this.usersPool = new LdapConnectionPool(userPoolFactory); PoolableObjectFactory<LdapConnection> searchPoolFactory = new ValidatingPoolableLdapConnectionFactory (connConfig); this.searchPool = new LdapConnectionPool(searchPoolFactory); this.useCache = useCache; this.ldapUseConnectionPool = config.isLdapUseConnectionPool(); }
@Override public void load() { config = new LdapConnectionConfig(); if (host != null) config.setLdapHost(host); if (port != null) config.setLdapPort(port); if (username != null) config.setName(username); if (password != null) config.setCredentials(password); if (usePool != null && usePool) { ValidatingPoolableLdapConnectionFactory factory = new ValidatingPoolableLdapConnectionFactory(config); connectionPool = new LdapConnectionPool(factory); connectionPool.setTestOnBorrow(true); } else connectionPool = null; }
return new LdapConnectionPool( poolableLdapConnectionFactory, poolConfig );
adminPool = new LdapConnectionPool(adminConnectionFactory); adminPool.setTestOnBorrow(true); adminPool.setMaxActive(config.getAdminPoolConfig().getMaxActive());
adminPool = new LdapConnectionPool( poolFactory ); adminPool.setTestOnBorrow( true ); adminPool.setWhenExhaustedAction( GenericObjectPool.WHEN_EXHAUSTED_GROW ); userPool = new LdapConnectionPool( poolFactory ); userPool.setTestOnBorrow( true ); userPool.setWhenExhaustedAction( GenericObjectPool.WHEN_EXHAUSTED_GROW ); logPool = new LdapConnectionPool( poolFactory ); logPool.setTestOnBorrow( true ); logPool.setWhenExhaustedAction( GenericObjectPool.WHEN_EXHAUSTED_GROW );
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; }