Search in sources :

Example 1 with MongoProfileService

use of org.pac4j.mongo.profile.service.MongoProfileService in project cas by apereo.

the class MongoDbAuthenticationHandler method close.

@PreDestroy
@Override
public void close() {
    try {
        final MongoProfileService service = MongoProfileService.class.cast(authenticator);
        service.getMongoClient().close();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : MongoProfileService(org.pac4j.mongo.profile.service.MongoProfileService) PreDestroy(javax.annotation.PreDestroy)

Example 2 with MongoProfileService

use of org.pac4j.mongo.profile.service.MongoProfileService 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)

Aggregations

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