Search in sources :

Example 1 with IPersonAttributeDao

use of org.apereo.services.persondir.IPersonAttributeDao 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;
}
Also used : IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) LdaptivePersonAttributeDao(org.apereo.services.persondir.support.ldap.LdaptivePersonAttributeDao) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) SearchControls(javax.naming.directory.SearchControls) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with IPersonAttributeDao

use of org.apereo.services.persondir.IPersonAttributeDao in project cas by apereo.

the class CasPersonDirectoryConfiguration method groovyAttributeRepositories.

@ConditionalOnMissingBean(name = "groovyAttributeRepositories")
@Bean
@RefreshScope
public List<IPersonAttributeDao> groovyAttributeRepositories() {
    final List<IPersonAttributeDao> list = new ArrayList<>();
    casProperties.getAuthn().getAttributeRepository().getGroovy().forEach(groovy -> {
        if (groovy.getConfig().getLocation() != null) {
            final GroovyPersonAttributeDao dao = new GroovyPersonAttributeDao(new InternalGroovyScriptDao(applicationContext, casProperties));
            dao.setCaseInsensitiveUsername(groovy.isCaseInsensitive());
            dao.setOrder(groovy.getOrder());
            LOGGER.debug("Configured Groovy attribute sources from [{}]", groovy.getConfig().getLocation());
            list.add(dao);
        }
    });
    return list;
}
Also used : IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) GroovyPersonAttributeDao(org.apereo.services.persondir.support.GroovyPersonAttributeDao) ArrayList(java.util.ArrayList) InternalGroovyScriptDao(org.apereo.cas.authentication.principal.resolvers.InternalGroovyScriptDao) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with IPersonAttributeDao

use of org.apereo.services.persondir.IPersonAttributeDao in project cas by apereo.

the class CasPersonDirectoryConfiguration method jsonAttributeRepositories.

@ConditionalOnMissingBean(name = "jsonAttributeRepositories")
@Bean
@RefreshScope
public List<IPersonAttributeDao> jsonAttributeRepositories() {
    final List<IPersonAttributeDao> list = new ArrayList<>();
    casProperties.getAuthn().getAttributeRepository().getJson().forEach(json -> {
        final Resource r = json.getConfig().getLocation();
        if (r != null) {
            final JsonBackedComplexStubPersonAttributeDao dao = new JsonBackedComplexStubPersonAttributeDao(r);
            dao.setOrder(json.getOrder());
            LOGGER.debug("Configured JSON attribute sources from [[{}]]", r);
            list.add(dao);
        }
    });
    return list;
}
Also used : IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) JsonBackedComplexStubPersonAttributeDao(org.apereo.services.persondir.support.JsonBackedComplexStubPersonAttributeDao) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with IPersonAttributeDao

use of org.apereo.services.persondir.IPersonAttributeDao 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(Beans.newHickariDataSource(jdbc), jdbc.getSql());
            } else {
                LOGGER.debug("Configured multi-row JDBC attribute repository for [{}]", jdbc.getUrl());
                jdbcDao = new MultiRowJdbcPersonAttributeDao(Beans.newHickariDataSource(jdbc), jdbc.getSql());
                LOGGER.debug("Configured multi-row JDBC column mappings for [{}] are [{}]", jdbc.getUrl(), jdbc.getColumnMappings());
                ((MultiRowJdbcPersonAttributeDao) jdbcDao).setNameValueColumnMappings(jdbc.getColumnMappings());
            }
            jdbcDao.setQueryAttributeMapping(Collections.singletonMap("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;
}
Also used : SingleRowJdbcPersonAttributeDao(org.apereo.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) MultiRowJdbcPersonAttributeDao(org.apereo.services.persondir.support.jdbc.MultiRowJdbcPersonAttributeDao) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) AbstractJdbcPersonAttributeDao(org.apereo.services.persondir.support.jdbc.AbstractJdbcPersonAttributeDao) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with IPersonAttributeDao

use of org.apereo.services.persondir.IPersonAttributeDao in project cas by apereo.

the class CasPersonDirectoryConfiguration method grouperAttributeRepositories.

@ConditionalOnMissingBean(name = "grouperAttributeRepositories")
@Bean
@RefreshScope
public List<IPersonAttributeDao> grouperAttributeRepositories() {
    final List<IPersonAttributeDao> list = new ArrayList<>();
    final PrincipalAttributesProperties.Grouper gp = casProperties.getAuthn().getAttributeRepository().getGrouper();
    if (gp.isEnabled()) {
        final GrouperPersonAttributeDao dao = new GrouperPersonAttributeDao();
        dao.setOrder(gp.getOrder());
        LOGGER.debug("Configured Grouper attribute source");
        list.add(dao);
    }
    return list;
}
Also used : GrouperPersonAttributeDao(org.apereo.services.persondir.support.GrouperPersonAttributeDao) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ArrayList (java.util.ArrayList)6 IPersonAttributeDao (org.apereo.services.persondir.IPersonAttributeDao)6 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)5 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)5 Bean (org.springframework.context.annotation.Bean)5 PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)3 HashMap (java.util.HashMap)1 List (java.util.List)1 SearchControls (javax.naming.directory.SearchControls)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CachingPrincipalAttributesRepository (org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)1 InternalGroovyScriptDao (org.apereo.cas.authentication.principal.resolvers.InternalGroovyScriptDao)1 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)1 GroovyPersonAttributeDao (org.apereo.services.persondir.support.GroovyPersonAttributeDao)1 GrouperPersonAttributeDao (org.apereo.services.persondir.support.GrouperPersonAttributeDao)1 JsonBackedComplexStubPersonAttributeDao (org.apereo.services.persondir.support.JsonBackedComplexStubPersonAttributeDao)1 StubPersonAttributeDao (org.apereo.services.persondir.support.StubPersonAttributeDao)1 AbstractJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.AbstractJdbcPersonAttributeDao)1 MultiRowJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.MultiRowJdbcPersonAttributeDao)1