Search in sources :

Example 1 with DefaultCouchbaseClientFactory

use of org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory in project cas by apereo.

the class CouchbaseAuthenticationHandlerTests method verifyBadRecord.

@Test
public void verifyBadRecord() {
    val props = casProperties.getAuthn().getCouchbase();
    val factory = new DefaultCouchbaseClientFactory(props);
    val handler = new CouchbaseAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), factory, props);
    handler.setPasswordEncoder(new SCryptPasswordEncoder());
    val c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("nopsw", "Mellon");
    assertThrows(FailedLoginException.class, () -> handler.authenticate(c));
}
Also used : lombok.val(lombok.val) DefaultCouchbaseClientFactory(org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory) ServicesManager(org.apereo.cas.services.ServicesManager) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DefaultCouchbaseClientFactory

use of org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory in project cas by apereo.

the class CouchbaseAuthenticationHandlerTests method verifyMissingUser.

@Test
public void verifyMissingUser() {
    val props = casProperties.getAuthn().getCouchbase();
    val factory = new DefaultCouchbaseClientFactory(props);
    val handler = new CouchbaseAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), factory, props);
    val c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser-missing", "Mellon");
    assertThrows(AccountNotFoundException.class, () -> handler.authenticate(c));
}
Also used : lombok.val(lombok.val) DefaultCouchbaseClientFactory(org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with DefaultCouchbaseClientFactory

use of org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory in project cas by apereo.

the class CouchbasePersonDirectoryConfiguration method couchbasePersonAttributeDao.

@ConditionalOnMissingBean(name = "couchbasePersonAttributeDao")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public IPersonAttributeDao couchbasePersonAttributeDao(final ConfigurableApplicationContext applicationContext, final CasConfigurationProperties casProperties) throws Exception {
    return BeanSupplier.of(IPersonAttributeDao.class).when(CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
        val couchbase = casProperties.getAuthn().getAttributeRepository().getCouchbase();
        val cb = new CouchbasePersonAttributeDao(couchbase, new DefaultCouchbaseClientFactory(couchbase));
        cb.setOrder(couchbase.getOrder());
        FunctionUtils.doIfNotNull(couchbase.getId(), cb::setId);
        return cb;
    }).otherwiseProxy().get();
}
Also used : lombok.val(lombok.val) DefaultCouchbaseClientFactory(org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory) CouchbasePersonAttributeDao(org.apereo.cas.persondir.support.CouchbasePersonAttributeDao) 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 4 with DefaultCouchbaseClientFactory

use of org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory in project cas by apereo.

the class CouchbaseAuthenticationHandlerTests method verify.

@Test
public void verify() throws Exception {
    val props = casProperties.getAuthn().getCouchbase();
    val factory = new DefaultCouchbaseClientFactory(props);
    val handler = new CouchbaseAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), factory, props);
    val c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon");
    val result = handler.authenticate(c);
    assertNotNull(result);
    val attributes = result.getPrincipal().getAttributes();
    assertEquals(2, attributes.size());
    assertTrue(attributes.containsKey("firstname"));
    assertTrue(attributes.containsKey("lastname"));
}
Also used : lombok.val(lombok.val) DefaultCouchbaseClientFactory(org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with DefaultCouchbaseClientFactory

use of org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory in project cas by apereo.

the class CouchbaseAuthenticationHandlerTests method verifyBadEncoding.

@Test
public void verifyBadEncoding() {
    val props = casProperties.getAuthn().getCouchbase();
    val factory = new DefaultCouchbaseClientFactory(props);
    val handler = new CouchbaseAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), factory, props);
    handler.setPasswordEncoder(new SCryptPasswordEncoder());
    val c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon");
    assertThrows(FailedLoginException.class, () -> handler.authenticate(c));
}
Also used : lombok.val(lombok.val) DefaultCouchbaseClientFactory(org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory) ServicesManager(org.apereo.cas.services.ServicesManager) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)5 DefaultCouchbaseClientFactory (org.apereo.cas.couchbase.core.DefaultCouchbaseClientFactory)5 ServicesManager (org.apereo.cas.services.ServicesManager)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 SCryptPasswordEncoder (org.springframework.security.crypto.scrypt.SCryptPasswordEncoder)2 CouchbasePersonAttributeDao (org.apereo.cas.persondir.support.CouchbasePersonAttributeDao)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1