use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.
the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationInvalidSql.
@Test
public void verifyAuthenticationInvalidSql() {
val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql("makesNoSenseInSql")).setPasswordFieldName(PASSWORD_FIELD_NAME).setSaltFieldName("salt").setDisabledFieldName("ops");
val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
assertThrows(PreventedException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
}
use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.
the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationSuccessfulWithAPasswordEncoder.
@Test
public void verifyAuthenticationSuccessfulWithAPasswordEncoder() throws Exception {
val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setNumberOfIterationsFieldName(NUM_ITERATIONS_FIELD_NAME).setStaticSalt(STATIC_SALT).setSaltFieldName("salt");
val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
q.setPasswordEncoder(new PasswordEncoder() {
@Override
public String encode(final CharSequence password) {
return password.toString().concat("1");
}
@Override
public boolean matches(final CharSequence rawPassword, final String encodedPassword) {
return true;
}
});
q.setPrincipalNameTransformer(new PrefixSuffixPrincipalNameTransformer("user", null));
val r = q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("1", "user"));
assertNotNull(r);
assertEquals("user1", r.getPrincipal().getId());
}
use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.
the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationWithDisabledField.
@Test
public void verifyAuthenticationWithDisabledField() {
val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setDisabledFieldName(DISABLED_FIELD_NAME).setStaticSalt(STATIC_SALT).setSaltFieldName("salt");
val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
assertThrows(AccountDisabledException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("user21")));
}
use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.
the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationWithExpiredField.
@Test
public void verifyAuthenticationWithExpiredField() {
val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setExpiredFieldName(EXPIRED_FIELD_NAME).setStaticSalt(STATIC_SALT).setSaltFieldName("salt");
val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
assertThrows(AccountPasswordMustChangeException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("user20")));
}
use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.
the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationSuccessful.
@Test
public void verifyAuthenticationSuccessful() throws Exception {
val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setSaltFieldName("salt").setDisabledFieldName("ops").setNumberOfIterationsFieldName(NUM_ITERATIONS_FIELD_NAME).setStaticSalt(STATIC_SALT);
val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("user1");
val r = q.authenticate(c);
assertNotNull(r);
assertEquals("user1", r.getPrincipal().getId());
}
Aggregations