use of org.apereo.services.persondir.support.ldap.LdaptivePersonAttributeDao 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(Beans.newLdaptivePooledConnectionFactory(ldap));
ldapDao.setBaseDN(ldap.getBaseDn());
LOGGER.debug("LDAP attributes are fetched from [{}] via filter [{}]", ldap.getLdapUrl(), ldap.getUserFilter());
ldapDao.setSearchFilter(ldap.getUserFilter());
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;
}
Aggregations