Search in sources :

Example 26 with MongoDbConnectionFactory

use of org.apereo.cas.mongo.MongoDbConnectionFactory in project cas by apereo.

the class MongoDbMultifactorAuthenticationTrustConfiguration method mongoMfaTrustedAuthnTemplate.

@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@Bean
public MongoOperations mongoMfaTrustedAuthnTemplate(final CasConfigurationProperties casProperties, @Qualifier(CasSSLContext.BEAN_NAME) final CasSSLContext casSslContext) {
    val mongo = casProperties.getAuthn().getMfa().getTrusted().getMongo();
    val factory = new MongoDbConnectionFactory(casSslContext.getSslContext());
    val mongoTemplate = factory.buildMongoTemplate(mongo);
    MongoDbConnectionFactory.createCollection(mongoTemplate, mongo.getCollection(), mongo.isDropCollection());
    return mongoTemplate;
}
Also used : lombok.val(lombok.val) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 27 with MongoDbConnectionFactory

use of org.apereo.cas.mongo.MongoDbConnectionFactory in project cas by apereo.

the class CasMongoAuthenticationConfiguration method mongoAuthenticationHandler.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "mongoAuthenticationHandler")
public AuthenticationHandler mongoAuthenticationHandler(final CasConfigurationProperties casProperties, final ConfigurableApplicationContext applicationContext, @Qualifier("mongoPrincipalFactory") final PrincipalFactory mongoPrincipalFactory, @Qualifier(ServicesManager.BEAN_NAME) final ServicesManager servicesManager, @Qualifier(CasSSLContext.BEAN_NAME) final CasSSLContext casSslContext) {
    val mongo = casProperties.getAuthn().getMongo();
    val factory = new MongoDbConnectionFactory(casSslContext.getSslContext());
    val mongoTemplate = factory.buildMongoTemplate(mongo);
    val handler = new MongoDbAuthenticationHandler(mongo.getName(), servicesManager, mongoPrincipalFactory, mongo, mongoTemplate);
    handler.setPasswordEncoder(PasswordEncoderUtils.newPasswordEncoder(mongo.getPasswordEncoder(), applicationContext));
    handler.setPrincipalNameTransformer(PrincipalNameTransformerUtils.newPrincipalNameTransformer(mongo.getPrincipalTransformation()));
    return handler;
}
Also used : lombok.val(lombok.val) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) MongoDbAuthenticationHandler(org.apereo.cas.authentication.MongoDbAuthenticationHandler) 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)

Example 28 with MongoDbConnectionFactory

use of org.apereo.cas.mongo.MongoDbConnectionFactory in project cas by apereo.

the class MongoDbAuthenticationHandlerTests method initialize.

@BeforeEach
public void initialize() {
    val mongo = casProperties.getAuthn().getMongo();
    val factory = new MongoDbConnectionFactory();
    try (val mongoClient = factory.buildMongoDbClient(mongo)) {
        val database = mongoClient.getDatabase(mongo.getDatabaseName());
        database.drop();
        val col = database.getCollection(mongo.getCollection());
        var account = new Document();
        account.append(mongo.getUsernameAttribute(), "u1");
        account.append(mongo.getPasswordAttribute(), "p1");
        account.append("loc", "Apereo");
        account.append("state", "California");
        col.insertOne(account);
        account = new Document();
        account.append(mongo.getUsernameAttribute(), "userPlain");
        col.insertOne(account);
    }
}
Also used : lombok.val(lombok.val) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) Document(org.bson.Document) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with MongoDbConnectionFactory

use of org.apereo.cas.mongo.MongoDbConnectionFactory in project cas by apereo.

the class MongoDbConnectionFactoryTests method verifyClient.

@Test
public void verifyClient() {
    val props = new SingleCollectionMongoDbProperties();
    props.setClientUri(URI);
    val factory = new MongoDbConnectionFactory();
    val client = factory.buildMongoDbClient(props);
    assertNotNull(client);
}
Also used : lombok.val(lombok.val) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) SingleCollectionMongoDbProperties(org.apereo.cas.configuration.model.support.mongo.SingleCollectionMongoDbProperties) Test(org.junit.jupiter.api.Test)

Example 30 with MongoDbConnectionFactory

use of org.apereo.cas.mongo.MongoDbConnectionFactory in project cas by apereo.

the class MongoDbConnectionFactoryTests method verifyProps.

@Test
public void verifyProps() {
    val factory = new MongoDbConnectionFactory();
    val props = new SingleCollectionMongoDbProperties();
    props.setClientUri(URI);
    val template = factory.buildMongoTemplate(props);
    assertNotNull(template);
    factory.createCollection(template, getClass().getSimpleName(), true);
}
Also used : lombok.val(lombok.val) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) SingleCollectionMongoDbProperties(org.apereo.cas.configuration.model.support.mongo.SingleCollectionMongoDbProperties) Test(org.junit.jupiter.api.Test)

Aggregations

MongoDbConnectionFactory (org.apereo.cas.mongo.MongoDbConnectionFactory)37 Bean (org.springframework.context.annotation.Bean)32 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)23 lombok.val (lombok.val)21 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)13 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)13 SingleCollectionMongoDbProperties (org.apereo.cas.configuration.model.support.mongo.SingleCollectionMongoDbProperties)3 Test (org.junit.jupiter.api.Test)3 U2FMongoDbDeviceRepository (org.apereo.cas.adaptors.u2f.storage.U2FMongoDbDeviceRepository)2 MongoDbAuditTrailManager (org.apereo.cas.audit.MongoDbAuditTrailManager)2 AuditMongoDbProperties (org.apereo.cas.configuration.model.core.audit.AuditMongoDbProperties)2 MongoDbConsentRepository (org.apereo.cas.consent.MongoDbConsentRepository)2 OpenSamlConfigBean (org.apereo.cas.support.saml.OpenSamlConfigBean)2 MongoDbThrottledSubmissionHandlerInterceptorAdapter (org.apereo.cas.web.support.MongoDbThrottledSubmissionHandlerInterceptorAdapter)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)1 DBCollection (com.mongodb.DBCollection)1 Serializable (java.io.Serializable)1 Date (java.util.Date)1 TimeUnit (java.util.concurrent.TimeUnit)1