use of org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer 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.util.transforms.PrefixSuffixPrincipalNameTransformer in project cas by apereo.
the class ConvertCasePrincipalNameTransformerTests method verifyUpperCaseTranformerWithTrimAndDelegate.
@Test
public void verifyUpperCaseTranformerWithTrimAndDelegate() {
final PrefixSuffixPrincipalNameTransformer suffixTrans = new PrefixSuffixPrincipalNameTransformer();
suffixTrans.setPrefix("a");
suffixTrans.setSuffix("z");
final ConvertCasePrincipalNameTransformer transformer = new ConvertCasePrincipalNameTransformer(suffixTrans);
transformer.setToUpperCase(true);
final String result = transformer.transform(" uid ");
assertEquals(result, "AUIDZ");
}
Aggregations