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")));
}
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")));
}
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"));
}
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")));
}
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")));
}
Aggregations