Search in sources :

Example 1 with PooledConnectionFactory

use of org.ldaptive.pool.PooledConnectionFactory in project cas by apereo.

the class Beans method getAuthenticatedOrAnonSearchAuthenticator.

private static Authenticator getAuthenticatedOrAnonSearchAuthenticator(final AbstractLdapAuthenticationProperties l) {
    if (StringUtils.isBlank(l.getBaseDn())) {
        throw new IllegalArgumentException("Base dn cannot be empty/blank for authenticated/anonymous authentication");
    }
    if (StringUtils.isBlank(l.getUserFilter())) {
        throw new IllegalArgumentException("User filter cannot be empty/blank for authenticated/anonymous authentication");
    }
    final PooledConnectionFactory connectionFactoryForSearch = Beans.newLdaptivePooledConnectionFactory(l);
    final PooledSearchDnResolver resolver = new PooledSearchDnResolver();
    resolver.setBaseDn(l.getBaseDn());
    resolver.setSubtreeSearch(l.isSubtreeSearch());
    resolver.setAllowMultipleDns(l.isAllowMultipleDns());
    resolver.setConnectionFactory(connectionFactoryForSearch);
    resolver.setUserFilter(l.getUserFilter());
    final Authenticator auth;
    if (StringUtils.isBlank(l.getPrincipalAttributePassword())) {
        auth = new Authenticator(resolver, getPooledBindAuthenticationHandler(l, Beans.newLdaptivePooledConnectionFactory(l)));
    } else {
        auth = new Authenticator(resolver, getPooledCompareAuthenticationHandler(l, Beans.newLdaptivePooledConnectionFactory(l)));
    }
    if (l.isEnhanceWithEntryResolver()) {
        auth.setEntryResolver(Beans.newLdaptiveSearchEntryResolver(l, Beans.newLdaptivePooledConnectionFactory(l)));
    }
    return auth;
}
Also used : PooledConnectionFactory(org.ldaptive.pool.PooledConnectionFactory) PooledSearchDnResolver(org.ldaptive.auth.PooledSearchDnResolver) Authenticator(org.ldaptive.auth.Authenticator)

Example 2 with PooledConnectionFactory

use of org.ldaptive.pool.PooledConnectionFactory in project cas by apereo.

the class LdapMonitorConfiguration method pooledLdapConnectionFactoryHealthIndicator.

@Autowired
@Bean
public HealthIndicator pooledLdapConnectionFactoryHealthIndicator(@Qualifier("pooledConnectionFactoryMonitorExecutorService") final ExecutorService executor) {
    final MonitorProperties.Ldap ldap = casProperties.getMonitor().getLdap();
    final PooledConnectionFactory connectionFactory = LdapUtils.newLdaptivePooledConnectionFactory(ldap);
    return new PooledLdapConnectionFactoryHealthIndicator(Beans.newDuration(ldap.getMaxWait()).toMillis(), connectionFactory, executor, new SearchValidator());
}
Also used : SearchValidator(org.ldaptive.pool.SearchValidator) PooledConnectionFactory(org.ldaptive.pool.PooledConnectionFactory) PooledLdapConnectionFactoryHealthIndicator(org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator) MonitorProperties(org.apereo.cas.configuration.model.core.monitor.MonitorProperties) Autowired(org.springframework.beans.factory.annotation.Autowired) ThreadPoolExecutorFactoryBean(org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with PooledConnectionFactory

use of org.ldaptive.pool.PooledConnectionFactory in project cas by apereo.

the class Beans method getSaslAuthenticator.

private static Authenticator getSaslAuthenticator(final AbstractLdapAuthenticationProperties l) {
    if (StringUtils.isBlank(l.getUserFilter())) {
        throw new IllegalArgumentException("User filter cannot be empty/blank for sasl authentication");
    }
    final PooledConnectionFactory connectionFactoryForSearch = Beans.newLdaptivePooledConnectionFactory(l);
    final PooledSearchDnResolver resolver = new PooledSearchDnResolver();
    resolver.setBaseDn(l.getBaseDn());
    resolver.setSubtreeSearch(l.isSubtreeSearch());
    resolver.setAllowMultipleDns(l.isAllowMultipleDns());
    resolver.setConnectionFactory(connectionFactoryForSearch);
    resolver.setUserFilter(l.getUserFilter());
    return new Authenticator(resolver, getPooledBindAuthenticationHandler(l, Beans.newLdaptivePooledConnectionFactory(l)));
}
Also used : PooledConnectionFactory(org.ldaptive.pool.PooledConnectionFactory) PooledSearchDnResolver(org.ldaptive.auth.PooledSearchDnResolver) Authenticator(org.ldaptive.auth.Authenticator)

Example 4 with PooledConnectionFactory

use of org.ldaptive.pool.PooledConnectionFactory in project cas by apereo.

the class LdapMonitorConfiguration method pooledLdapConnectionFactoryMonitor.

@Autowired
@Bean
public Monitor pooledLdapConnectionFactoryMonitor(@Qualifier("pooledConnectionFactoryMonitorExecutorService") final ExecutorService executor) {
    final MonitorProperties.Ldap ldap = casProperties.getMonitor().getLdap();
    final PooledConnectionFactory connectionFactory = Beans.newLdaptivePooledConnectionFactory(ldap);
    return new PooledLdapConnectionFactoryMonitor(executor, Long.valueOf(ldap.getMaxWait()).intValue(), connectionFactory, new SearchValidator());
}
Also used : SearchValidator(org.ldaptive.pool.SearchValidator) PooledConnectionFactory(org.ldaptive.pool.PooledConnectionFactory) PooledLdapConnectionFactoryMonitor(org.apereo.cas.monitor.PooledLdapConnectionFactoryMonitor) MonitorProperties(org.apereo.cas.configuration.model.core.monitor.MonitorProperties) Autowired(org.springframework.beans.factory.annotation.Autowired) ThreadPoolExecutorFactoryBean(org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PooledConnectionFactory (org.ldaptive.pool.PooledConnectionFactory)4 MonitorProperties (org.apereo.cas.configuration.model.core.monitor.MonitorProperties)2 Authenticator (org.ldaptive.auth.Authenticator)2 PooledSearchDnResolver (org.ldaptive.auth.PooledSearchDnResolver)2 SearchValidator (org.ldaptive.pool.SearchValidator)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Bean (org.springframework.context.annotation.Bean)2 ThreadPoolExecutorFactoryBean (org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean)2 PooledLdapConnectionFactoryHealthIndicator (org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator)1 PooledLdapConnectionFactoryMonitor (org.apereo.cas.monitor.PooledLdapConnectionFactoryMonitor)1