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;
}
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();
}
}
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;
}
Aggregations