All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apereo.cas.syncope.SyncopePersonAttributeDao Maven / Gradle / Ivy

The newest version!
package org.apereo.cas.syncope;

import org.apereo.cas.authentication.attribute.BasePersonAttributeDao;
import org.apereo.cas.authentication.attribute.SimplePersonAttributes;
import org.apereo.cas.authentication.principal.attribute.PersonAttributeDaoFilter;
import org.apereo.cas.authentication.principal.attribute.PersonAttributes;
import org.apereo.cas.configuration.model.support.syncope.SyncopePrincipalAttributesProperties;
import lombok.RequiredArgsConstructor;
import lombok.val;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * This is {@link SyncopePersonAttributeDao}.
 *
 * @author Francesco Chicchiriccò
 * @since 6.5.0
 */
@RequiredArgsConstructor
public class SyncopePersonAttributeDao extends BasePersonAttributeDao {

    private final SyncopePrincipalAttributesProperties properties;

    @Override
    public PersonAttributes getPerson(final String uid, final Set resolvedPeople, final PersonAttributeDaoFilter filter) {
        val attributes = new HashMap>();
        val results = syncopeSearch(uid);
        results.forEach(attributes::putAll);
        return new SimplePersonAttributes(uid, attributes);
    }

    @Override
    public Set getPeople(final Map map, final PersonAttributeDaoFilter filter,
                                           final Set resolvedPeople) {
        return getPeopleWithMultivaluedAttributes(stuffAttributesIntoList(map, filter), filter);
    }

    @Override
    public Set getPeopleWithMultivaluedAttributes(
        final Map> map, final PersonAttributeDaoFilter filter,
        final Set resolvedPeople) {
        return map.entrySet()
            .stream()
            .filter(e -> Objects.nonNull(e.getValue()))
            .filter(e -> !e.getValue().isEmpty())
            .filter(e -> properties.getSearchFilter().contains(e.getKey()))
            .findFirst()
            .map(e -> Set.of(getPerson(e.getValue().getFirst().toString(), resolvedPeople, filter)))
            .orElseGet(() -> new LinkedHashSet<>(0));
    }

    protected List>> syncopeSearch(final String username) {
        return SyncopeUtils.syncopeUserSearch(properties, username);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy