Search in sources :

Example 1 with PrincipalElectionStrategy

use of org.apereo.cas.authentication.PrincipalElectionStrategy in project cas by apereo.

the class ChainingPrincipalElectionStrategy method nominate.

@Override
public Principal nominate(final Collection<Authentication> authentications, final Map<String, List<Object>> principalAttributes) {
    val principal = this.chain.stream().sorted(Comparator.comparing(PrincipalElectionStrategy::getOrder)).map(strategy -> strategy.nominate(authentications, principalAttributes)).filter(Objects::nonNull).findFirst().orElseThrow();
    LOGGER.trace("Nominated principal [{}] from authentication chain [{}]", principal, authentications);
    return principal;
}
Also used : lombok.val(lombok.val) Setter(lombok.Setter) Getter(lombok.Getter) ReplacingAttributeAdder(org.apereo.services.persondir.support.merger.ReplacingAttributeAdder) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) IAttributeMerger(org.apereo.services.persondir.support.merger.IAttributeMerger) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) PrincipalElectionStrategy(org.apereo.cas.authentication.PrincipalElectionStrategy) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Authentication(org.apereo.cas.authentication.Authentication) Map(java.util.Map) Comparator(java.util.Comparator) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Objects(java.util.Objects)

Example 2 with PrincipalElectionStrategy

use of org.apereo.cas.authentication.PrincipalElectionStrategy in project cas by apereo.

the class ChainingPrincipalElectionStrategy method nominate.

@Override
public Principal nominate(final List<Principal> principals, final Map<String, List<Object>> attributes) {
    val principal = this.chain.stream().sorted(Comparator.comparing(PrincipalElectionStrategy::getOrder)).map(strategy -> strategy.nominate(principals, attributes)).findFirst().orElseThrow();
    LOGGER.trace("Nominated principal [{}] from principal chain [{}]", principal, principals);
    return principal;
}
Also used : lombok.val(lombok.val) PrincipalElectionStrategy(org.apereo.cas.authentication.PrincipalElectionStrategy)

Aggregations

lombok.val (lombok.val)2 PrincipalElectionStrategy (org.apereo.cas.authentication.PrincipalElectionStrategy)2 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Getter (lombok.Getter)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Setter (lombok.Setter)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Authentication (org.apereo.cas.authentication.Authentication)1 IAttributeMerger (org.apereo.services.persondir.support.merger.IAttributeMerger)1 ReplacingAttributeAdder (org.apereo.services.persondir.support.merger.ReplacingAttributeAdder)1 AnnotationAwareOrderComparator (org.springframework.core.annotation.AnnotationAwareOrderComparator)1