Search in sources :

Example 1 with MultivaluedAttributeMerger

use of org.apereo.services.persondir.support.merger.MultivaluedAttributeMerger 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)

Aggregations

Cache (com.google.common.cache.Cache)1 CachingPersonAttributeDaoImpl (org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl)1 MergingPersonAttributeDaoImpl (org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl)1 MultivaluedAttributeMerger (org.apereo.services.persondir.support.merger.MultivaluedAttributeMerger)1 NoncollidingAttributeAdder (org.apereo.services.persondir.support.merger.NoncollidingAttributeAdder)1 ReplacingAttributeAdder (org.apereo.services.persondir.support.merger.ReplacingAttributeAdder)1