Search in sources :

Example 1 with BlockingPrincipalNameTransformer

use of org.apereo.cas.util.transforms.BlockingPrincipalNameTransformer 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 2 with BlockingPrincipalNameTransformer

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

the class BlockingPrincipalNameTransformerTests method verifyBlocked.

@Test
public void verifyBlocked() {
    val pt = new BlockingPrincipalNameTransformer("[abc]");
    assertThrows(PreventedException.class, () -> pt.transform("casuser"));
    assertEquals("helloworld", pt.transform("helloworld"));
}
Also used : lombok.val(lombok.val) BlockingPrincipalNameTransformer(org.apereo.cas.util.transforms.BlockingPrincipalNameTransformer) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)2 BlockingPrincipalNameTransformer (org.apereo.cas.util.transforms.BlockingPrincipalNameTransformer)2 ChainingPrincipalNameTransformer (org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer)1 ConvertCasePrincipalNameTransformer (org.apereo.cas.util.transforms.ConvertCasePrincipalNameTransformer)1 GroovyPrincipalNameTransformer (org.apereo.cas.util.transforms.GroovyPrincipalNameTransformer)1 PrefixSuffixPrincipalNameTransformer (org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer)1 RegexPrincipalNameTransformer (org.apereo.cas.util.transforms.RegexPrincipalNameTransformer)1 Test (org.junit.jupiter.api.Test)1