use of org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer 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));
}
use of org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer 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;
}
use of org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer in project cas by apereo.
the class CoreAuthenticationUtils method buildPrincipalResolutionContext.
/**
* New PrincipalResolutionContext.
*
* @param principalFactory the principal factory
* @param attributeRepository the attribute repository
* @param attributeMerger the attribute merger
* @param personDirectory the person directory properties
* @return the resolver
*/
public static PrincipalResolutionContext buildPrincipalResolutionContext(final PrincipalFactory principalFactory, final IPersonAttributeDao attributeRepository, final IAttributeMerger attributeMerger, final PersonDirectoryPrincipalResolverProperties... personDirectory) {
val transformers = Arrays.stream(personDirectory).map(p -> PrincipalNameTransformerUtils.newPrincipalNameTransformer(p.getPrincipalTransformation())).collect(Collectors.toList());
val transformer = new ChainingPrincipalNameTransformer(transformers);
return PrincipalResolutionContext.builder().attributeRepository(attributeRepository).attributeMerger(attributeMerger).principalFactory(principalFactory).returnNullIfNoAttributes(Arrays.stream(personDirectory).filter(p -> p.getReturnNull() != TriStateBoolean.UNDEFINED).map(p -> p.getReturnNull().toBoolean()).findFirst().orElse(Boolean.FALSE)).principalAttributeNames(Arrays.stream(personDirectory).map(PersonDirectoryPrincipalResolverProperties::getPrincipalAttribute).filter(StringUtils::isNotBlank).findFirst().orElse(StringUtils.EMPTY)).principalNameTransformer(transformer).useCurrentPrincipalId(Arrays.stream(personDirectory).filter(p -> p.getUseExistingPrincipalId() != TriStateBoolean.UNDEFINED).map(p -> p.getUseExistingPrincipalId().toBoolean()).findFirst().orElse(Boolean.FALSE)).resolveAttributes(Arrays.stream(personDirectory).filter(p -> p.getAttributeResolutionEnabled() != TriStateBoolean.UNDEFINED).map(p -> p.getAttributeResolutionEnabled().toBoolean()).findFirst().orElse(Boolean.TRUE)).activeAttributeRepositoryIdentifiers(Arrays.stream(personDirectory).filter(p -> StringUtils.isNotBlank(p.getActiveAttributeRepositoryIds())).map(p -> org.springframework.util.StringUtils.commaDelimitedListToSet(p.getActiveAttributeRepositoryIds())).filter(p -> !p.isEmpty()).findFirst().orElse(Collections.EMPTY_SET)).build();
}
use of org.apereo.cas.util.transforms.ChainingPrincipalNameTransformer 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");
}
Aggregations