Search in sources :

Example 1 with PrefixSuffixPrincipalNameTransformer

use of org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer in project cas by apereo.

the class Beans method newPrincipalNameTransformer.

/**
     * New principal name transformer.
     *
     * @param p the p
     * @return the principal name transformer
     */
public static PrincipalNameTransformer newPrincipalNameTransformer(final PrincipalTransformationProperties p) {
    final PrincipalNameTransformer res;
    if (StringUtils.isNotBlank(p.getPrefix()) || StringUtils.isNotBlank(p.getSuffix())) {
        final PrefixSuffixPrincipalNameTransformer t = new PrefixSuffixPrincipalNameTransformer();
        t.setPrefix(p.getPrefix());
        t.setSuffix(p.getSuffix());
        res = t;
    } else {
        res = formUserId -> formUserId;
    }
    switch(p.getCaseConversion()) {
        case UPPERCASE:
            final ConvertCasePrincipalNameTransformer t = new ConvertCasePrincipalNameTransformer(res);
            t.setToUpperCase(true);
            return t;
        case LOWERCASE:
            final ConvertCasePrincipalNameTransformer t1 = new ConvertCasePrincipalNameTransformer(res);
            t1.setToUpperCase(false);
            return t1;
        default:
    }
    return res;
}
Also used : ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) PrincipalNameTransformer(org.apereo.cas.authentication.handler.PrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer)

Example 2 with PrefixSuffixPrincipalNameTransformer

use of org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer in project cas by apereo.

the class ChainingPrincipalNameTransformerTests method verifyChain.

@Test
public void verifyChain() {
    final ChainingPrincipalNameTransformer t = new ChainingPrincipalNameTransformer();
    t.addTransformer(new RegexPrincipalNameTransformer("(.+)@example.org"));
    t.addTransformer(new PrefixSuffixPrincipalNameTransformer("prefix-", "-suffix"));
    t.addTransformer(new ConvertCasePrincipalNameTransformer(true));
    final String uid = t.transform("casuser@example.org");
    assertTrue("PREFIX-CASUSER-SUFFIX".equals(uid));
}
Also used : RegexPrincipalNameTransformer(org.apereo.cas.util.transforms.RegexPrincipalNameTransformer) ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) ChainingPrincipalNameTransformer(org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) Test(org.junit.Test)

Example 3 with PrefixSuffixPrincipalNameTransformer

use of org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer in project cas by apereo.

the class PrincipalNameTransformerUtils method newPrincipalNameTransformer.

/**
 * New principal name transformer.
 *
 * @param p the p
 * @return the principal name transformer
 */
public static PrincipalNameTransformer newPrincipalNameTransformer(final PrincipalTransformationProperties p) {
    val chain = new ChainingPrincipalNameTransformer();
    if (p.getGroovy().getLocation() != null) {
        val t = new GroovyPrincipalNameTransformer(p.getGroovy().getLocation());
        chain.addTransformer(t);
    }
    if (StringUtils.isNotBlank(p.getPattern())) {
        val t = new RegexPrincipalNameTransformer(p.getPattern());
        chain.addTransformer(t);
    }
    if (StringUtils.isNotBlank(p.getPrefix()) || StringUtils.isNotBlank(p.getSuffix())) {
        val t = new PrefixSuffixPrincipalNameTransformer();
        t.setPrefix(p.getPrefix());
        t.setSuffix(p.getSuffix());
        chain.addTransformer(t);
    }
    if (p.getCaseConversion() == PrincipalTransformationProperties.CaseConversion.UPPERCASE) {
        val t = new ConvertCasePrincipalNameTransformer();
        t.setToUpperCase(true);
        chain.addTransformer(t);
    }
    if (p.getCaseConversion() == PrincipalTransformationProperties.CaseConversion.LOWERCASE) {
        val t = new ConvertCasePrincipalNameTransformer();
        t.setToUpperCase(false);
        chain.addTransformer(t);
    }
    if (StringUtils.isNotBlank(p.getBlockingPattern())) {
        val t = new BlockingPrincipalNameTransformer(p.getBlockingPattern());
        chain.addTransformer(t);
    }
    return chain;
}
Also used : lombok.val(lombok.val) RegexPrincipalNameTransformer(org.apereo.cas.util.transforms.RegexPrincipalNameTransformer) ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) GroovyPrincipalNameTransformer(org.apereo.cas.util.transforms.GroovyPrincipalNameTransformer) BlockingPrincipalNameTransformer(org.apereo.cas.util.transforms.BlockingPrincipalNameTransformer) ChainingPrincipalNameTransformer(org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer)

Example 4 with PrefixSuffixPrincipalNameTransformer

use of org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer in project cas by apereo.

the class ChainingPrincipalNameTransformerTests method verifyChain.

@Test
public void verifyChain() {
    val t = new ChainingPrincipalNameTransformer();
    t.addTransformer(new RegexPrincipalNameTransformer("(.+)@example.org"));
    t.addTransformer(new PrefixSuffixPrincipalNameTransformer("prefix-", "-suffix"));
    t.addTransformer(new ConvertCasePrincipalNameTransformer(true));
    val uid = t.transform("casuser@example.org");
    assertEquals(uid, "PREFIX-CASUSER-SUFFIX");
}
Also used : lombok.val(lombok.val) RegexPrincipalNameTransformer(org.apereo.cas.util.transforms.RegexPrincipalNameTransformer) ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) ChainingPrincipalNameTransformer(org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) Test(org.junit.jupiter.api.Test)

Example 5 with PrefixSuffixPrincipalNameTransformer

use of org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer in project cas by apereo.

the class ConvertCasePrincipalNameTransformerTests method verifyUpperCaseTransformerWithTrimAndDelegate.

@Test
public void verifyUpperCaseTransformerWithTrimAndDelegate() {
    val suffixTrans = new PrefixSuffixPrincipalNameTransformer();
    suffixTrans.setPrefix("a");
    suffixTrans.setSuffix("z");
    val transformer = new ConvertCasePrincipalNameTransformer();
    transformer.setToUpperCase(true);
    val result = transformer.transform(suffixTrans.transform("   uid  "));
    assertEquals("A   UID  Z", result);
}
Also used : lombok.val(lombok.val) ConvertCasePrincipalNameTransformer(org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) Test(org.junit.jupiter.api.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