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);
}
Aggregations