Search in sources :

Example 1 with CachingPersonAttributeDaoImpl

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

the class CasPersonDirectoryConfiguration method cachingAttributeRepository.

@Bean
@ConditionalOnMissingBean(name = "cachingAttributeRepository")
public IPersonAttributeDao cachingAttributeRepository() {
    final CachingPersonAttributeDaoImpl impl = new CachingPersonAttributeDaoImpl();
    impl.setCacheNullResults(false);
    final PrincipalAttributesProperties props = casProperties.getAuthn().getAttributeRepository();
    final Cache graphs = Caffeine.newBuilder().maximumSize(props.getMaximumCacheSize()).expireAfterWrite(props.getExpirationTime(), TimeUnit.valueOf(props.getExpirationTimeUnit().toUpperCase())).build();
    impl.setUserInfoCache(graphs.asMap());
    impl.setCachedPersonAttributesDao(aggregatingAttributeRepository());
    LOGGER.debug("Configured cache expiration policy for merging attribute sources to be [{}] minute(s)", props.getExpirationTime());
    return impl;
}
Also used : CachingPersonAttributeDaoImpl(org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl) GrouperPrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.GrouperPrincipalAttributesProperties) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) Cache(com.github.benmanes.caffeine.cache.Cache) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with CachingPersonAttributeDaoImpl

use of org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl 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 3 with CachingPersonAttributeDaoImpl

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

the class PersonDirectoryConfiguration method getCachingPersonAttributeDao.

/**
 * Defines the order that the data providing DAOs are called, results are cached by the outer
 * caching DAO.
 */
@Bean(name = "cachingPersonAttributeDao")
@Qualifier("uPortalInternal")
public IPersonAttributeDao getCachingPersonAttributeDao() {
    final CachingPersonAttributeDaoImpl rslt = new CachingPersonAttributeDaoImpl();
    rslt.setUsernameAttributeProvider(getUsernameAttributeProvider());
    rslt.setCacheNullResults(true);
    rslt.setCacheKeyGenerator(getUserAttributeCacheKeyGenerator());
    rslt.setUserInfoCache(new MapCacheProvider<>(userInfoCache));
    rslt.setCachedPersonAttributesDao(getMergingPersonAttributeDao());
    return rslt;
}
Also used : CachingPersonAttributeDaoImpl(org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean)

Aggregations

CachingPersonAttributeDaoImpl (org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl)3 Bean (org.springframework.context.annotation.Bean)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 Cache (com.google.common.cache.Cache)1 GrouperPrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.GrouperPrincipalAttributesProperties)1 PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)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 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1