Search in sources :

Example 6 with PrefixSuffixPrincipalNameTransformer

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());
}
Also used : lombok.val(lombok.val) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) QueryEncodeJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) Test(org.junit.jupiter.api.Test)

Example 7 with PrefixSuffixPrincipalNameTransformer

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");
}
Also used : ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) Test(org.junit.Test)

Aggregations

PrefixSuffixPrincipalNameTransformer (org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer)7 ConvertCasePrincipalNameTransformer (org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer)6 lombok.val (lombok.val)4 ChainingPrincipalNameTransformer (org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer)3 RegexPrincipalNameTransformer (org.apereo.cas.util.transforms.RegexPrincipalNameTransformer)3 Test (org.junit.jupiter.api.Test)3 Test (org.junit.Test)2 PrincipalNameTransformer (org.apereo.cas.authentication.handler.PrincipalNameTransformer)1 QueryEncodeJdbcAuthenticationProperties (org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties)1 BlockingPrincipalNameTransformer (org.apereo.cas.util.transforms.BlockingPrincipalNameTransformer)1 GroovyPrincipalNameTransformer (org.apereo.cas.util.transforms.GroovyPrincipalNameTransformer)1 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)1