org.apereo.cas.config.CasConsentRedisAutoConfiguration Maven / Gradle / Ivy
package org.apereo.cas.config;
import org.apereo.cas.authentication.CasSSLContext;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.configuration.features.CasFeatureModule;
import org.apereo.cas.consent.ConsentRepository;
import org.apereo.cas.consent.RedisConsentRepository;
import org.apereo.cas.redis.core.CasRedisTemplate;
import org.apereo.cas.redis.core.RedisObjectFactory;
import org.apereo.cas.util.spring.beans.BeanCondition;
import org.apereo.cas.util.spring.beans.BeanSupplier;
import org.apereo.cas.util.spring.boot.ConditionalOnFeatureEnabled;
import lombok.val;
import org.jooq.lambda.Unchecked;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* This is {@link CasConsentRedisAutoConfiguration}.
*
* @author Misagh Moayyed
* @since 5.2.0
*/
@EnableConfigurationProperties(CasConfigurationProperties.class)
@ConditionalOnFeatureEnabled(feature = CasFeatureModule.FeatureCatalog.Consent, module = "redis")
@AutoConfiguration
public class CasConsentRedisAutoConfiguration {
private static final BeanCondition CONDITION = BeanCondition.on("cas.consent.redis.enabled").isTrue().evenIfMissing();
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public ConsentRepository consentRepository(
final ConfigurableApplicationContext applicationContext,
@Qualifier("consentRedisTemplate")
final CasRedisTemplate consentRedisTemplate,
final CasConfigurationProperties casProperties) {
return BeanSupplier.of(ConsentRepository.class)
.when(CONDITION.given(applicationContext.getEnvironment()))
.supply(() -> new RedisConsentRepository(consentRedisTemplate))
.otherwiseProxy()
.get();
}
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "redisConsentConnectionFactory")
public RedisConnectionFactory redisConsentConnectionFactory(
final ConfigurableApplicationContext applicationContext,
@Qualifier(CasSSLContext.BEAN_NAME)
final CasSSLContext casSslContext,
final CasConfigurationProperties casProperties) {
return BeanSupplier.of(RedisConnectionFactory.class)
.when(CONDITION.given(applicationContext.getEnvironment()))
.supply(Unchecked.supplier(() -> {
val redis = casProperties.getConsent().getRedis();
return RedisObjectFactory.newRedisConnectionFactory(redis, casSslContext);
}))
.otherwiseProxy()
.get();
}
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "consentRedisTemplate")
public CasRedisTemplate consentRedisTemplate(
final ConfigurableApplicationContext applicationContext,
@Qualifier("redisConsentConnectionFactory")
final RedisConnectionFactory redisConsentConnectionFactory) {
return BeanSupplier.of(CasRedisTemplate.class)
.when(CONDITION.given(applicationContext.getEnvironment()))
.supply(() -> RedisObjectFactory.newRedisTemplate(redisConsentConnectionFactory))
.otherwiseProxy()
.get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy