Search in sources :

Example 1 with NoncollidingAttributeAdder

use of org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder in project cas by apereo.

the class CasPersonDirectoryConfiguration method composeMergedAndCachedAttributeRepositories.

private IPersonAttributeDao composeMergedAndCachedAttributeRepositories(final List<IPersonAttributeDao> list) {
    final MergingPersonAttributeDaoImpl mergingDao = new MergingPersonAttributeDaoImpl();
    final String merger = StringUtils.defaultIfBlank(casProperties.getAuthn().getAttributeRepository().getMerger(), "replace".trim());
    LOGGER.debug("Configured merging strategy for attribute sources is [{}]", merger);
    switch(merger.toLowerCase()) {
        case "merge":
            mergingDao.setMerger(new MultivaluedAttributeMerger());
            break;
        case "add":
            mergingDao.setMerger(new NoncollidingAttributeAdder());
            break;
        case "replace":
        default:
            mergingDao.setMerger(new ReplacingAttributeAdder());
            break;
    }
    final CachingPersonAttributeDaoImpl impl = new CachingPersonAttributeDaoImpl();
    impl.setCacheNullResults(false);
    final Cache graphs = CacheBuilder.newBuilder().concurrencyLevel(2).weakKeys().maximumSize(casProperties.getAuthn().getAttributeRepository().getMaximumCacheSize()).expireAfterWrite(casProperties.getAuthn().getAttributeRepository().getExpireInMinutes(), TimeUnit.MINUTES).build();
    impl.setUserInfoCache(graphs.asMap());
    mergingDao.setPersonAttributeDaos(list);
    impl.setCachedPersonAttributesDao(mergingDao);
    if (list.isEmpty()) {
        LOGGER.debug("No attribute repository sources are available/defined to merge together.");
    } else {
        LOGGER.debug("Configured attribute repository sources to merge together: [{}]", list);
        LOGGER.debug("Configured cache expiration policy for merging attribute sources to be [{}] minute(s)", casProperties.getAuthn().getAttributeRepository().getExpireInMinutes());
    }
    return impl;
}
Also used : CachingPersonAttributeDaoImpl(org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl) ReplacingAttributeAdder(org.apereo.services.persondir.support.merger.ReplacingAttributeAdder) MergingPersonAttributeDaoImpl(org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl) NoncollidingAttributeAdder(org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder) MultivaluedAttributeMerger(org.apereo.services.persondir.support.merger.MultivaluedAttributeMerger) Cache(com.google.common.cache.Cache)

Example 2 with NoncollidingAttributeAdder

use of org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder in project cas by apereo.

the class CoreAuthenticationUtils method getAttributeMerger.

/**
 * Gets attribute merger.
 *
 * @param mergingPolicy the merging policy
 * @return the attribute merger
 */
public static IAttributeMerger getAttributeMerger(final PrincipalAttributesCoreProperties.MergingStrategyTypes mergingPolicy) {
    switch(mergingPolicy) {
        case MULTIVALUED:
            val merger = new MultivaluedAttributeMerger();
            merger.setDistinctValues(true);
            return merger;
        case ADD:
            return new NoncollidingAttributeAdder();
        case NONE:
            return new BaseAdditiveAttributeMerger() {

                @Override
                protected Map<String, List<Object>> mergePersonAttributes(final Map<String, List<Object>> toModify, final Map<String, List<Object>> toConsider) {
                    return new LinkedHashMap<>(toModify);
                }
            };
        case REPLACE:
        default:
            return new ReplacingAttributeAdder();
    }
}
Also used : lombok.val(lombok.val) ReplacingAttributeAdder(org.apereo.services.persondir.support.merger.ReplacingAttributeAdder) BaseAdditiveAttributeMerger(org.apereo.services.persondir.support.merger.BaseAdditiveAttributeMerger) List(java.util.List) ArrayList(java.util.ArrayList) NoncollidingAttributeAdder(org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MultivaluedAttributeMerger(org.apereo.services.persondir.support.merger.MultivaluedAttributeMerger) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with NoncollidingAttributeAdder

use of org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder in project uPortal by Jasig.

the class PersonDirectoryConfiguration method getMergingPersonAttributeDao.

@Bean(name = "mergingPersonAttributeDao")
@Qualifier("uPortalInternal")
public IPersonAttributeDao getMergingPersonAttributeDao() {
    final MergingPersonAttributeDaoImpl rslt = new MergingPersonAttributeDaoImpl();
    rslt.setUsernameAttributeProvider(getUsernameAttributeProvider());
    /*
         * This is a "first one wins" strategy. I.e. the first value found for any given result
         * attribute will be assigned to the user. Different values found in subsequently queried
         * attribute sources will be ignored. Suitable if uP-local attributes should always take
         * precedence.
         *
         * Other options (all in the same package):
         *   - MultivaluedAttributeMerger - Collects values from all DAOs into lists (does not
         *     filter out duplicate values, though)
         *   - ReplacingAttributeAdder - "Last one wins" strategy. I.e. the opposite of
         *     NoncollidingAttributeAdder.
         */
    rslt.setMerger(new NoncollidingAttributeAdder());
    return rslt;
}
Also used : MergingPersonAttributeDaoImpl(org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl) NoncollidingAttributeAdder(org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean)

Aggregations

NoncollidingAttributeAdder (org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder)3 MergingPersonAttributeDaoImpl (org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl)2 MultivaluedAttributeMerger (org.apereo.services.persondir.support.merger.MultivaluedAttributeMerger)2 ReplacingAttributeAdder (org.apereo.services.persondir.support.merger.ReplacingAttributeAdder)2 Cache (com.google.common.cache.Cache)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 lombok.val (lombok.val)1 CachingPersonAttributeDaoImpl (org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl)1 BaseAdditiveAttributeMerger (org.apereo.services.persondir.support.merger.BaseAdditiveAttributeMerger)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Bean (org.springframework.context.annotation.Bean)1