Search in sources :

Example 6 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifyFindUserAndDisabled.

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

Example 7 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifyMultipleRecords.

@Test
public void verifyMultipleRecords() {
    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("user0", "psw0")));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 8 with QueryJdbcAuthenticationProperties

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

the class NamedQueryDatabaseAuthenticationHandlerTests method verifySuccessWithCount.

@Test
public void verifySuccessWithCount() throws Exception {
    val sql = "SELECT count(*) as total FROM CAS_NAMED_USERS where username=:username AND password=:password";
    val map = CoreAuthenticationUtils.transformPrincipalAttributesListIntoMultiMap(List.of("phone:phoneNumber"));
    val properties = new QueryJdbcAuthenticationProperties().setSql(sql);
    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());
    assertFalse(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 9 with QueryJdbcAuthenticationProperties

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

the class NamedQueryDatabaseAuthenticationHandlerTests method verifyFailsWithMissingTotalField.

@Test
public void verifyFailsWithMissingTotalField() {
    val sql = "SELECT count(*) FROM CAS_NAMED_USERS where username=:username AND password=:password";
    val properties = new QueryJdbcAuthenticationProperties().setSql(sql).setFieldPassword("password");
    properties.setName("namedHandler");
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, new HashMap<>());
    assertThrows(FailedLoginException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("whatever", "psw0")));
}
Also used : lombok.val(lombok.val) QueryJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 10 with QueryJdbcAuthenticationProperties

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

the class QueryDatabaseAuthenticationHandlerTests method verifyBadQuery.

@Test
public void verifyBadQuery() {
    val properties = new QueryJdbcAuthenticationProperties().setSql(SQL.replace("*", "error")).setFieldPassword(PASSWORD_FIELD);
    val q = new QueryDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), this.dataSource, new HashMap<>(0));
    assertThrows(PreventedException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("user0", "psw0")));
}
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