Search in sources :

Example 1 with MongoAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mongo.MongoAuthenticationProperties in project cas by apereo.

the class CasMongoAuthenticationConfiguration method mongoAuthenticatorProfileService.

@ConditionalOnMissingBean(name = "mongoAuthenticatorProfileService")
@Bean
public MongoProfileService mongoAuthenticatorProfileService() {
    final MongoAuthenticationProperties mongo = casProperties.getAuthn().getMongo();
    final MongoClientURI uri = new MongoClientURI(mongo.getMongoHostUri());
    final MongoClient client = new MongoClient(uri);
    LOGGER.info("Connected to MongoDb instance @ [{}] using database [{}]", uri.getHosts(), uri.getDatabase());
    final SpringSecurityPasswordEncoder encoder = new SpringSecurityPasswordEncoder(PasswordEncoderUtils.newPasswordEncoder(mongo.getPasswordEncoder()));
    final MongoProfileService auth = new MongoProfileService(client, mongo.getAttributes());
    auth.setUsersCollection(mongo.getCollectionName());
    auth.setUsersDatabase(uri.getDatabase());
    auth.setUsernameAttribute(mongo.getUsernameAttribute());
    auth.setPasswordAttribute(mongo.getPasswordAttribute());
    auth.setPasswordEncoder(encoder);
    return auth;
}
Also used : MongoProfileService(org.pac4j.mongo.profile.service.MongoProfileService) MongoClient(com.mongodb.MongoClient) SpringSecurityPasswordEncoder(org.pac4j.core.credentials.password.SpringSecurityPasswordEncoder) MongoClientURI(com.mongodb.MongoClientURI) MongoAuthenticationProperties(org.apereo.cas.configuration.model.support.mongo.MongoAuthenticationProperties) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MongoAuthenticationProperties

use of org.apereo.cas.configuration.model.support.mongo.MongoAuthenticationProperties in project cas by apereo.

the class CasMongoAuthenticationConfiguration method mongoAuthenticationHandler.

@Bean
@RefreshScope
public AuthenticationHandler mongoAuthenticationHandler() {
    final MongoAuthenticationProperties mongo = casProperties.getAuthn().getMongo();
    final MongoDbAuthenticationHandler handler = new MongoDbAuthenticationHandler(mongo.getName(), servicesManager, mongoPrincipalFactory());
    handler.setAuthenticator(mongoAuthenticatorProfileService());
    handler.setPrincipalNameTransformer(PrincipalNameTransformerUtils.newPrincipalNameTransformer(mongo.getPrincipalTransformation()));
    return handler;
}
Also used : MongoAuthenticationProperties(org.apereo.cas.configuration.model.support.mongo.MongoAuthenticationProperties) MongoDbAuthenticationHandler(org.apereo.cas.authentication.MongoDbAuthenticationHandler) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MongoAuthenticationProperties (org.apereo.cas.configuration.model.support.mongo.MongoAuthenticationProperties)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 MongoDbAuthenticationHandler (org.apereo.cas.authentication.MongoDbAuthenticationHandler)1 SpringSecurityPasswordEncoder (org.pac4j.core.credentials.password.SpringSecurityPasswordEncoder)1 MongoProfileService (org.pac4j.mongo.profile.service.MongoProfileService)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1