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