use of org.apereo.services.persondir.support.merger.IAttributeMerger 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.services.persondir.support.merger.IAttributeMerger in project cas by apereo.
the class CoreAuthenticationUtils method mergeAttributes.
/**
* Merge attributes map.
*
* @param currentAttributes the current attributes
* @param attributesToMerge the attributes to merge
* @param merger the merger
* @return the map
*/
public static Map<String, List<Object>> mergeAttributes(final Map<String, List<Object>> currentAttributes, final Map<String, List<Object>> attributesToMerge, final IAttributeMerger merger) {
val toModify = currentAttributes.entrySet().stream().map(entry -> Pair.of(entry.getKey(), CollectionUtils.toCollection(entry.getValue(), ArrayList.class))).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
val toMerge = attributesToMerge.entrySet().stream().map(entry -> Pair.of(entry.getKey(), CollectionUtils.toCollection(entry.getValue(), ArrayList.class))).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
LOGGER.trace("Merging current attributes [{}] with [{}]", toModify, toMerge);
val results = merger.mergeAttributes((Map) toModify, (Map) toMerge);
LOGGER.debug("Merged attributes with the final result as [{}]", results);
return results;
}
Aggregations