use of org.apereo.cas.configuration.model.core.authentication.PersonDirectoryPrincipalResolverProperties 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.configuration.model.core.authentication.PersonDirectoryPrincipalResolverProperties in project cas by apereo.
the class CoreAuthenticationUtilsTests method verifyPrincipalConflictResolution.
@Test
public void verifyPrincipalConflictResolution() {
val r1 = CoreAuthenticationUtils.newPrincipalElectionStrategyConflictResolver(new PersonDirectoryPrincipalResolverProperties().setPrincipalResolutionConflictStrategy("LAST"));
assertNotNull(r1);
val r2 = CoreAuthenticationUtils.newPrincipalElectionStrategyConflictResolver(new PersonDirectoryPrincipalResolverProperties().setPrincipalResolutionConflictStrategy("FIRST"));
assertNotNull(r2);
val r3 = CoreAuthenticationUtils.newPrincipalElectionStrategyConflictResolver(new PersonDirectoryPrincipalResolverProperties().setPrincipalResolutionConflictStrategy("INVALID"));
assertEquals(r3, r1);
}
use of org.apereo.cas.configuration.model.core.authentication.PersonDirectoryPrincipalResolverProperties in project cas by apereo.
the class CoreAuthenticationUtilsTests method verifyPersonDirectoryOverrides.
@Test
public void verifyPersonDirectoryOverrides() {
val principal = new PersonDirectoryPrincipalResolverProperties();
val personDirectory = new PersonDirectoryPrincipalResolverProperties();
val principalResolutionContext = CoreAuthenticationUtils.buildPrincipalResolutionContext(PrincipalFactoryUtils.newPrincipalFactory(), new StubPersonAttributeDao(Collections.EMPTY_MAP), CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.ADD), principal, personDirectory);
assertFalse(principalResolutionContext.isUseCurrentPrincipalId());
assertTrue(principalResolutionContext.isResolveAttributes());
assertFalse(principalResolutionContext.isReturnNullIfNoAttributes());
assertTrue(principalResolutionContext.getActiveAttributeRepositoryIdentifiers().isEmpty());
assertTrue(principalResolutionContext.getPrincipalAttributeNames().isEmpty());
personDirectory.setUseExistingPrincipalId(TriStateBoolean.TRUE);
personDirectory.setAttributeResolutionEnabled(TriStateBoolean.TRUE);
personDirectory.setReturnNull(TriStateBoolean.TRUE);
personDirectory.setAttributeResolutionEnabled(TriStateBoolean.FALSE);
personDirectory.setActiveAttributeRepositoryIds("test1,test2");
personDirectory.setPrincipalAttribute("principalAttribute");
val principalResolutionContext2 = CoreAuthenticationUtils.buildPrincipalResolutionContext(PrincipalFactoryUtils.newPrincipalFactory(), new StubPersonAttributeDao(Collections.EMPTY_MAP), CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.ADD), principal, personDirectory);
assertTrue(principalResolutionContext2.isUseCurrentPrincipalId());
assertFalse(principalResolutionContext2.isResolveAttributes());
assertTrue(principalResolutionContext2.isReturnNullIfNoAttributes());
assertEquals(2, principalResolutionContext2.getActiveAttributeRepositoryIdentifiers().size());
assertEquals("principalAttribute", principalResolutionContext2.getPrincipalAttributeNames());
principal.setUseExistingPrincipalId(TriStateBoolean.FALSE);
principal.setAttributeResolutionEnabled(TriStateBoolean.FALSE);
principal.setReturnNull(TriStateBoolean.FALSE);
principal.setAttributeResolutionEnabled(TriStateBoolean.TRUE);
principal.setActiveAttributeRepositoryIds("test1,test2,test3");
principal.setPrincipalAttribute("principalAttribute2");
val principalResolutionContext3 = CoreAuthenticationUtils.buildPrincipalResolutionContext(PrincipalFactoryUtils.newPrincipalFactory(), new StubPersonAttributeDao(Collections.EMPTY_MAP), CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.ADD), principal, personDirectory);
assertFalse(principalResolutionContext3.isUseCurrentPrincipalId());
assertTrue(principalResolutionContext3.isResolveAttributes());
assertFalse(principalResolutionContext3.isReturnNullIfNoAttributes());
assertEquals(3, principalResolutionContext3.getActiveAttributeRepositoryIdentifiers().size());
assertEquals("principalAttribute2", principalResolutionContext3.getPrincipalAttributeNames());
val principalResolutionContext4 = CoreAuthenticationUtils.buildPrincipalResolutionContext(PrincipalFactoryUtils.newPrincipalFactory(), new StubPersonAttributeDao(Collections.EMPTY_MAP), CoreAuthenticationUtils.getAttributeMerger(PrincipalAttributesCoreProperties.MergingStrategyTypes.ADD), personDirectory);
assertTrue(principalResolutionContext4.isUseCurrentPrincipalId());
assertFalse(principalResolutionContext4.isResolveAttributes());
assertTrue(principalResolutionContext4.isReturnNullIfNoAttributes());
assertEquals(2, principalResolutionContext4.getActiveAttributeRepositoryIdentifiers().size());
assertEquals("principalAttribute", principalResolutionContext4.getPrincipalAttributeNames());
}
Aggregations