Search in sources :

Example 1 with QueryJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties in project cas by apereo.

the class QueryDatabaseAuthenticationHandlerPostgresTests method verifySuccess.

@Test
public void verifySuccess() throws Exception {
    val map = CoreAuthenticationUtils.transformPrincipalAttributesListIntoMultiMap(List.of("locations"));
    val properties = new QueryJdbcAuthenticationProperties().setSql(SQL).setFieldPassword(PASSWORD_FIELD);
    properties.setName("DbHandler");
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, CollectionUtils.wrap(map));
    val c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon");
    val result = q.authenticate(c);
    assertNotNull(result);
    assertNotNull(result.getPrincipal());
    assertTrue(result.getPrincipal().getAttributes().containsKey("locations"));
    assertNotNull(SerializationUtils.serialize(result));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 2 with QueryJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties in project cas by apereo.

the class NamedQueryDatabaseAuthenticationHandlerTests method verifySuccess.

@Test
public void verifySuccess() throws Exception {
    val sql = "SELECT * FROM CAS_NAMED_USERS where username=:username";
    val map = CoreAuthenticationUtils.transformPrincipalAttributesListIntoMultiMap(List.of("phone:phoneNumber"));
    val properties = new QueryJdbcAuthenticationProperties().setSql(sql).setFieldPassword("password");
    properties.setName("namedHandler");
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, CollectionUtils.wrap(map));
    val result = q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("user0", "psw0"));
    assertNotNull(result);
    assertNotNull(result.getPrincipal());
    assertTrue(result.getPrincipal().getAttributes().containsKey("phoneNumber"));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 3 with QueryJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties in project cas by apereo.

the class QueryDatabaseAuthenticationHandlerMariaDbTests method verifySuccess.

@Test
public void verifySuccess() throws Exception {
    val map = CoreAuthenticationUtils.transformPrincipalAttributesListIntoMultiMap(List.of("location"));
    val properties = new QueryJdbcAuthenticationProperties().setSql(SQL).setFieldPassword(PASSWORD_FIELD).setFieldDisabled("disabled");
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, CollectionUtils.wrap(map));
    val c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "Mellon");
    val result = q.authenticate(c);
    assertNotNull(result);
    assertNotNull(result.getPrincipal());
    assertTrue(result.getPrincipal().getAttributes().containsKey("location"));
    assertNotNull(SerializationUtils.serialize(result));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 4 with QueryJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties in project cas by apereo.

the class QueryDatabaseAuthenticationHandlerTests method verifyBCryptSuccess.

/**
 * This test proves that in case BCRYPT and
 * using raw password test can authenticate
 */
@Test
public void verifyBCryptSuccess() throws Exception {
    val encoder = new BCryptPasswordEncoder(6, RandomUtils.getNativeInstance());
    val sql = SQL.replace("*", '\'' + encoder.encode("pswbc2") + "' password");
    val properties = new QueryJdbcAuthenticationProperties().setSql(sql).setFieldPassword(PASSWORD_FIELD);
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, new HashMap<>(0));
    q.setPasswordEncoder(encoder);
    assertNotNull(q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("user3", "pswbc2")));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Test(org.junit.jupiter.api.Test)

Example 5 with QueryJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties in project cas by apereo.

the class QueryDatabaseAuthenticationHandlerTests method verifyAuthenticationFailsToFindUser.

@Test
public void verifyAuthenticationFailsToFindUser() {
    val properties = new QueryJdbcAuthenticationProperties().setSql(SQL).setFieldPassword(PASSWORD_FIELD);
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, new HashMap<>(0));
    assertThrows(AccountNotFoundException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("usernotfound", "psw1")));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)14 QueryJdbcAuthenticationProperties (org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties)14 Test (org.junit.jupiter.api.Test)14 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)2