Search in sources :

Example 11 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifySuccess.

@Test
public void verifySuccess() throws Exception {
    val map = CoreAuthenticationUtils.transformPrincipalAttributesListIntoMultiMap(List.of("phone:phoneNumber"));
    val properties = new QueryJdbcAuthenticationProperties().setSql(SQL).setFieldPassword(PASSWORD_FIELD);
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, CollectionUtils.wrap(map));
    val result = q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("user3", "psw3"));
    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 12 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifyFindUserAndExpired.

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

Example 13 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifyPasswordInvalid.

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

Example 14 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifyBCryptFail.

/**
 * This test proves that in case BCRYPT is used authentication using encoded password always fail
 * with FailedLoginException
 */
@Test
public void verifyBCryptFail() {
    val encoder = new BCryptPasswordEncoder(8, RandomUtils.getNativeInstance());
    val sql = SQL.replace("*", '\'' + encoder.encode("pswbc1") + "' 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);
    assertThrows(FailedLoginException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("user0", "pswbc1")));
}
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)

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