use of org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties in project cas by apereo.
the class CasPersonDirectoryConfiguration method ldapAttributeRepositories.
@ConditionalOnMissingBean(name = "ldapAttributeRepositories")
@Bean
@RefreshScope
public List<IPersonAttributeDao> ldapAttributeRepositories() {
final List<IPersonAttributeDao> list = new ArrayList<>();
final PrincipalAttributesProperties attrs = casProperties.getAuthn().getAttributeRepository();
attrs.getLdap().forEach(ldap -> {
if (StringUtils.isNotBlank(ldap.getBaseDn()) && StringUtils.isNotBlank(ldap.getLdapUrl())) {
final LdaptivePersonAttributeDao ldapDao = new LdaptivePersonAttributeDao();
LOGGER.debug("Configured LDAP attribute source for [{}] and baseDn [{}]", ldap.getLdapUrl(), ldap.getBaseDn());
ldapDao.setConnectionFactory(LdapUtils.newLdaptivePooledConnectionFactory(ldap));
ldapDao.setBaseDN(ldap.getBaseDn());
LOGGER.debug("LDAP attributes are fetched from [{}] via filter [{}]", ldap.getLdapUrl(), ldap.getSearchFilter());
ldapDao.setSearchFilter(ldap.getSearchFilter());
final SearchControls constraints = new SearchControls();
if (ldap.getAttributes() != null && !ldap.getAttributes().isEmpty()) {
LOGGER.debug("Configured result attribute mapping for [{}] to be [{}]", ldap.getLdapUrl(), ldap.getAttributes());
ldapDao.setResultAttributeMapping(ldap.getAttributes());
final String[] attributes = ldap.getAttributes().keySet().toArray(new String[ldap.getAttributes().keySet().size()]);
constraints.setReturningAttributes(attributes);
} else {
LOGGER.debug("Retrieving all attributes as no explicit attribute mappings are defined for [{}]", ldap.getLdapUrl());
constraints.setReturningAttributes(null);
}
if (ldap.isSubtreeSearch()) {
LOGGER.debug("Configured subtree searching for [{}]", ldap.getLdapUrl());
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
}
constraints.setDerefLinkFlag(true);
ldapDao.setSearchControls(constraints);
ldapDao.setOrder(ldap.getOrder());
LOGGER.debug("Initializing LDAP attribute source for [{}]", ldap.getLdapUrl());
ldapDao.initialize();
list.add(ldapDao);
}
});
return list;
}
use of org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties 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;
}
use of org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties in project cas by apereo.
the class BeansTests method verifyOperation.
@Test
public void verifyOperation() {
val props = new PrincipalAttributesProperties();
props.getStub().setId("helloworld");
props.getStub().getAttributes().put("name", "true");
val input = Beans.newStubAttributeRepository(props);
assertNotNull(input);
}
use of org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties in project cas by apereo.
the class CasCoreAuthenticationPrincipalConfiguration method globalPrincipalAttributeRepository.
@Bean
@RefreshScope
@ConditionalOnMissingBean(name = "globalPrincipalAttributeRepository")
public PrincipalAttributesRepository globalPrincipalAttributeRepository() {
final PrincipalAttributesProperties props = casProperties.getAuthn().getAttributeRepository();
final long cacheTime = props.getExpirationTime();
if (cacheTime < 0) {
return new DefaultPrincipalAttributesRepository();
}
return new CachingPrincipalAttributesRepository(props.getExpirationTimeUnit().toUpperCase(), cacheTime);
}
use of org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties in project cas by apereo.
the class CasPersonDirectoryConfiguration method jdbcAttributeRepositories.
@ConditionalOnMissingBean(name = "jdbcAttributeRepositories")
@Bean
@RefreshScope
public List<IPersonAttributeDao> jdbcAttributeRepositories() {
final List<IPersonAttributeDao> list = new ArrayList<>();
final PrincipalAttributesProperties attrs = casProperties.getAuthn().getAttributeRepository();
attrs.getJdbc().forEach(jdbc -> {
if (StringUtils.isNotBlank(jdbc.getSql()) && StringUtils.isNotBlank(jdbc.getUrl())) {
final AbstractJdbcPersonAttributeDao jdbcDao;
if (jdbc.isSingleRow()) {
LOGGER.debug("Configured single-row JDBC attribute repository for [{}]", jdbc.getUrl());
jdbcDao = new SingleRowJdbcPersonAttributeDao(JpaBeans.newDataSource(jdbc), jdbc.getSql());
} else {
LOGGER.debug("Configured multi-row JDBC attribute repository for [{}]", jdbc.getUrl());
jdbcDao = new MultiRowJdbcPersonAttributeDao(JpaBeans.newDataSource(jdbc), jdbc.getSql());
LOGGER.debug("Configured multi-row JDBC column mappings for [{}] are [{}]", jdbc.getUrl(), jdbc.getColumnMappings());
((MultiRowJdbcPersonAttributeDao) jdbcDao).setNameValueColumnMappings(jdbc.getColumnMappings());
}
jdbcDao.setQueryAttributeMapping(CollectionUtils.wrap("username", jdbc.getUsername()));
final Map<String, String> mapping = jdbc.getAttributes();
if (mapping != null && !mapping.isEmpty()) {
LOGGER.debug("Configured result attribute mapping for [{}] to be [{}]", jdbc.getUrl(), jdbc.getAttributes());
jdbcDao.setResultAttributeMapping(mapping);
}
jdbcDao.setRequireAllQueryAttributes(jdbc.isRequireAllAttributes());
jdbcDao.setUsernameCaseCanonicalizationMode(jdbc.getCaseCanonicalization());
jdbcDao.setDefaultCaseCanonicalizationMode(jdbc.getCaseCanonicalization());
jdbcDao.setQueryType(jdbc.getQueryType());
jdbcDao.setOrder(jdbc.getOrder());
list.add(jdbcDao);
}
});
return list;
}
Aggregations