Search in sources :

Example 1 with BeanContainer

use of org.apereo.cas.util.spring.beans.BeanContainer in project cas by apereo.

the class MongoDbMonitoringConfiguration method mongoHealthIndicator.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnEnabledHealthIndicator("mongoHealthIndicator")
@ConditionalOnMissingBean(name = "mongoHealthIndicator")
public HealthIndicator mongoHealthIndicator(final CasConfigurationProperties casProperties, @Qualifier("mongoHealthIndicatorTemplate") final BeanContainer<CasMongoOperations> mongoHealthIndicatorTemplate) {
    val warn = casProperties.getMonitor().getWarn();
    val results = mongoHealthIndicatorTemplate.toList().stream().map(template -> new MongoDbHealthIndicator(template, warn.getEvictionThreshold(), warn.getThreshold())).collect(Collectors.toList());
    return new CompositeHealthIndicator(results);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) MongoDbHealthIndicator(org.apereo.cas.monitor.MongoDbHealthIndicator) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) CasMongoOperations(org.apereo.cas.mongo.CasMongoOperations) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) Collectors(java.util.stream.Collectors) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Configuration(org.springframework.context.annotation.Configuration) BeanContainer(org.apereo.cas.util.spring.beans.BeanContainer) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) CasSSLContext(org.apereo.cas.authentication.CasSSLContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CompositeHealthIndicator(org.apereo.cas.monitor.CompositeHealthIndicator) Bean(org.springframework.context.annotation.Bean) CompositeHealthIndicator(org.apereo.cas.monitor.CompositeHealthIndicator) MongoDbHealthIndicator(org.apereo.cas.monitor.MongoDbHealthIndicator) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with BeanContainer

use of org.apereo.cas.util.spring.beans.BeanContainer in project cas by apereo.

the class RedisAuthenticationConfiguration method redisPersonAttributeDaos.

@ConditionalOnMissingBean(name = "redisPersonAttributeDaos")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public BeanContainer<IPersonAttributeDao> redisPersonAttributeDaos(final ConfigurableApplicationContext applicationContext, @Qualifier(CasSSLContext.BEAN_NAME) final CasSSLContext casSslContext, final CasConfigurationProperties casProperties) {
    return BeanSupplier.of(BeanContainer.class).when(CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
        val redis = casProperties.getAuthn().getAttributeRepository().getRedis();
        return BeanContainer.of(redis.stream().filter(r -> StringUtils.isNotBlank(r.getHost())).map(r -> {
            val conn = RedisObjectFactory.newRedisConnectionFactory(r, true, casSslContext);
            val template = RedisObjectFactory.newRedisTemplate(conn);
            template.initialize();
            val cb = new RedisPersonAttributeDao(template);
            cb.setOrder(r.getOrder());
            FunctionUtils.doIfNotNull(r.getId(), cb::setId);
            return cb;
        }).collect(Collectors.toList()));
    }).otherwise(BeanContainer::empty).get();
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) BeanCondition(org.apereo.cas.util.spring.beans.BeanCondition) PasswordEncoderUtils(org.apereo.cas.authentication.support.password.PasswordEncoderUtils) RedisPersonAttributeDao(org.apereo.cas.redis.RedisPersonAttributeDao) PersonDirectoryAttributeRepositoryPlanConfigurer(org.apereo.cas.persondir.PersonDirectoryAttributeRepositoryPlanConfigurer) StringUtils(org.apache.commons.lang3.StringUtils) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) BeanSupplier(org.apereo.cas.util.spring.beans.BeanSupplier) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) BeanContainer(org.apereo.cas.util.spring.beans.BeanContainer) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CasRedisTemplate(org.apereo.cas.redis.core.CasRedisTemplate) ServicesManager(org.apereo.cas.services.ServicesManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) PrincipalFactoryUtils(org.apereo.cas.authentication.principal.PrincipalFactoryUtils) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) RedisAuthenticationHandler(org.apereo.cas.redis.RedisAuthenticationHandler) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) ConditionalOnFeature(org.apereo.cas.util.spring.boot.ConditionalOnFeature) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisObjectFactory(org.apereo.cas.redis.core.RedisObjectFactory) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) CasFeatureModule(org.apereo.cas.configuration.support.CasFeatureModule) CasSSLContext(org.apereo.cas.authentication.CasSSLContext) PrincipalNameTransformerUtils(org.apereo.cas.authentication.principal.PrincipalNameTransformerUtils) Bean(org.springframework.context.annotation.Bean) AuthenticationEventExecutionPlanConfigurer(org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer) RedisPersonAttributeDao(org.apereo.cas.redis.RedisPersonAttributeDao) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Collectors (java.util.stream.Collectors)2 lombok.val (lombok.val)2 CasSSLContext (org.apereo.cas.authentication.CasSSLContext)2 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2 BeanContainer (org.apereo.cas.util.spring.beans.BeanContainer)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 Configuration (org.springframework.context.annotation.Configuration)2 ScopedProxyMode (org.springframework.context.annotation.ScopedProxyMode)2 StringUtils (org.apache.commons.lang3.StringUtils)1 AuthenticationEventExecutionPlanConfigurer (org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 PrincipalFactory (org.apereo.cas.authentication.principal.PrincipalFactory)1 PrincipalFactoryUtils (org.apereo.cas.authentication.principal.PrincipalFactoryUtils)1 PrincipalNameTransformerUtils (org.apereo.cas.authentication.principal.PrincipalNameTransformerUtils)1 PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)1 PasswordEncoderUtils (org.apereo.cas.authentication.support.password.PasswordEncoderUtils)1