Search in sources :

Example 1 with AbstractJdbcPersonAttributeDao

use of org.apereo.services.persondir.support.jdbc.AbstractJdbcPersonAttributeDao 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)

Aggregations

ArrayList (java.util.ArrayList)1 PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)1 IPersonAttributeDao (org.apereo.services.persondir.IPersonAttributeDao)1 AbstractJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.AbstractJdbcPersonAttributeDao)1 MultiRowJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.MultiRowJdbcPersonAttributeDao)1 SingleRowJdbcPersonAttributeDao (org.apereo.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1