Search in sources :

Example 1 with PooledLdapConnectionFactoryHealthIndicator

use of org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator 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 2 with PooledLdapConnectionFactoryHealthIndicator

use of org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator in project cas by apereo.

the class LdapMonitorConfiguration method pooledLdapConnectionFactoryHealthIndicator.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnEnabledHealthIndicator("pooledLdapConnectionFactoryHealthIndicator")
public CompositeHealthContributor pooledLdapConnectionFactoryHealthIndicator(final CasConfigurationProperties casProperties, @Qualifier("pooledLdapConnectionFactoryHealthIndicatorListFactoryBean") final ListFactoryBean factoryBean) throws Exception {
    val ldaps = casProperties.getMonitor().getLdap();
    val connectionFactoryList = Objects.requireNonNull(factoryBean.getObject());
    val contributors = new LinkedHashMap<>();
    ldaps.stream().filter(LdapMonitorProperties::isEnabled).map(Unchecked.function(ldap -> {
        val executor = Beans.newThreadPoolExecutorFactoryBean(ldap.getPool());
        val connectionFactory = LdapUtils.newLdaptivePooledConnectionFactory(ldap);
        connectionFactoryList.add(connectionFactory);
        val healthIndicator = new PooledLdapConnectionFactoryHealthIndicator(Beans.newDuration(ldap.getMaxWait()).toMillis(), connectionFactory, executor.getObject(), new SearchConnectionValidator());
        val name = StringUtils.defaultIfBlank(ldap.getName(), UUID.randomUUID().toString());
        return Pair.of(name, healthIndicator);
    })).forEach(it -> contributors.put(it.getKey(), it.getValue()));
    return CompositeHealthContributor.fromMap((Map) contributors);
}
Also used : lombok.val(lombok.val) SearchConnectionValidator(org.ldaptive.SearchConnectionValidator) LdapMonitorProperties(org.apereo.cas.configuration.model.core.monitor.LdapMonitorProperties) PooledLdapConnectionFactoryHealthIndicator(org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator) LinkedHashMap(java.util.LinkedHashMap) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ListFactoryBean(org.springframework.beans.factory.config.ListFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PooledLdapConnectionFactoryHealthIndicator (org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator)2 Bean (org.springframework.context.annotation.Bean)2 LinkedHashMap (java.util.LinkedHashMap)1 lombok.val (lombok.val)1 LdapMonitorProperties (org.apereo.cas.configuration.model.core.monitor.LdapMonitorProperties)1 MonitorProperties (org.apereo.cas.configuration.model.core.monitor.MonitorProperties)1 SearchConnectionValidator (org.ldaptive.SearchConnectionValidator)1 PooledConnectionFactory (org.ldaptive.pool.PooledConnectionFactory)1 SearchValidator (org.ldaptive.pool.SearchValidator)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ListFactoryBean (org.springframework.beans.factory.config.ListFactoryBean)1 ConditionalOnEnabledHealthIndicator (org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 ThreadPoolExecutorFactoryBean (org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean)1