org.apereo.cas.config.CassandraAuthenticationAutoConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cas-server-support-cassandra-authentication Show documentation
Show all versions of cas-server-support-cassandra-authentication Show documentation
cas-server-support-cassandra-authentication
package org.apereo.cas.config;
import org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer;
import org.apereo.cas.authentication.AuthenticationHandler;
import org.apereo.cas.authentication.CasSSLContext;
import org.apereo.cas.authentication.CassandraAuthenticationHandler;
import org.apereo.cas.authentication.CassandraRepository;
import org.apereo.cas.authentication.DefaultCassandraRepository;
import org.apereo.cas.authentication.principal.PrincipalFactory;
import org.apereo.cas.authentication.principal.PrincipalFactoryUtils;
import org.apereo.cas.authentication.principal.PrincipalNameTransformerUtils;
import org.apereo.cas.authentication.principal.PrincipalResolver;
import org.apereo.cas.authentication.support.password.PasswordEncoderUtils;
import org.apereo.cas.cassandra.CassandraSessionFactory;
import org.apereo.cas.cassandra.DefaultCassandraSessionFactory;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.configuration.features.CasFeatureModule;
import org.apereo.cas.services.ServicesManager;
import org.apereo.cas.util.spring.boot.ConditionalOnFeatureEnabled;
import lombok.val;
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;
/**
* This is {@link CassandraAuthenticationAutoConfiguration}.
*
* @author Misagh Moayyed
* @author Dmitriy Kopylenko
* @since 5.2.0
*/
@EnableConfigurationProperties(CasConfigurationProperties.class)
@ConditionalOnFeatureEnabled(feature = CasFeatureModule.FeatureCatalog.Authentication, module = "cassandra")
@AutoConfiguration
public class CassandraAuthenticationAutoConfiguration {
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public PrincipalFactory cassandraPrincipalFactory() {
return PrincipalFactoryUtils.newPrincipalFactory();
}
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "cassandraAuthnSessionFactory")
public CassandraSessionFactory cassandraAuthnSessionFactory(
final CasConfigurationProperties casProperties,
@Qualifier(CasSSLContext.BEAN_NAME)
final CasSSLContext casSslContext) {
val cassandra = casProperties.getAuthn().getCassandra();
return new DefaultCassandraSessionFactory(cassandra, casSslContext.getSslContext());
}
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public CassandraRepository cassandraRepository(final CasConfigurationProperties casProperties,
@Qualifier("cassandraAuthnSessionFactory")
final CassandraSessionFactory cassandraAuthnSessionFactory) {
val cassandra = casProperties.getAuthn().getCassandra();
return new DefaultCassandraRepository(cassandra, cassandraAuthnSessionFactory);
}
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public AuthenticationHandler cassandraAuthenticationHandler(
final CasConfigurationProperties casProperties, final ConfigurableApplicationContext applicationContext,
@Qualifier("cassandraPrincipalFactory")
final PrincipalFactory cassandraPrincipalFactory,
@Qualifier("cassandraRepository")
final CassandraRepository cassandraRepository,
@Qualifier(ServicesManager.BEAN_NAME)
final ServicesManager servicesManager) {
val cassandra = casProperties.getAuthn().getCassandra();
val handler = new CassandraAuthenticationHandler(cassandra.getName(), servicesManager, cassandraPrincipalFactory, cassandra.getOrder(), cassandra, cassandraRepository);
handler.setPrincipalNameTransformer(PrincipalNameTransformerUtils.newPrincipalNameTransformer(cassandra.getPrincipalTransformation()));
handler.setPasswordEncoder(PasswordEncoderUtils.newPasswordEncoder(cassandra.getPasswordEncoder(), applicationContext));
return handler;
}
@ConditionalOnMissingBean(name = "cassandraAuthenticationEventExecutionPlanConfigurer")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public AuthenticationEventExecutionPlanConfigurer cassandraAuthenticationEventExecutionPlanConfigurer(
@Qualifier("cassandraAuthenticationHandler")
final AuthenticationHandler cassandraAuthenticationHandler,
@Qualifier(PrincipalResolver.BEAN_NAME_PRINCIPAL_RESOLVER)
final PrincipalResolver defaultPrincipalResolver) {
return plan -> plan.registerAuthenticationHandlerWithPrincipalResolver(cassandraAuthenticationHandler, defaultPrincipalResolver);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy