Search in sources :

Example 1 with LdapMonitorProperties

use of org.apereo.cas.configuration.model.core.monitor.LdapMonitorProperties 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

LinkedHashMap (java.util.LinkedHashMap)1 lombok.val (lombok.val)1 LdapMonitorProperties (org.apereo.cas.configuration.model.core.monitor.LdapMonitorProperties)1 PooledLdapConnectionFactoryHealthIndicator (org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator)1 SearchConnectionValidator (org.ldaptive.SearchConnectionValidator)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 Bean (org.springframework.context.annotation.Bean)1