Search in sources :

Example 1 with PrincipalAttributesProperties

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;
}
Also used : IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) LdaptivePersonAttributeDao(org.apereo.services.persondir.support.ldap.LdaptivePersonAttributeDao) GrouperPrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.GrouperPrincipalAttributesProperties) 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 PrincipalAttributesProperties

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;
}
Also used : CachingPersonAttributeDaoImpl(org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl) GrouperPrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.GrouperPrincipalAttributesProperties) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) Cache(com.github.benmanes.caffeine.cache.Cache) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with PrincipalAttributesProperties

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);
}
Also used : lombok.val(lombok.val) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) Test(org.junit.jupiter.api.Test)

Example 4 with PrincipalAttributesProperties

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);
}
Also used : DefaultPrincipalAttributesRepository(org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository) 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 PrincipalAttributesProperties

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;
}
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) GrouperPrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.GrouperPrincipalAttributesProperties) 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

PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)5 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)4 Bean (org.springframework.context.annotation.Bean)4 GrouperPrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.GrouperPrincipalAttributesProperties)3 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)3 ArrayList (java.util.ArrayList)2 IPersonAttributeDao (org.apereo.services.persondir.IPersonAttributeDao)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 SearchControls (javax.naming.directory.SearchControls)1 lombok.val (lombok.val)1 DefaultPrincipalAttributesRepository (org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository)1 CachingPrincipalAttributesRepository (org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)1 CachingPersonAttributeDaoImpl (org.apereo.services.persondir.support.CachingPersonAttributeDaoImpl)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 LdaptivePersonAttributeDao (org.apereo.services.persondir.support.ldap.LdaptivePersonAttributeDao)1 Test (org.junit.jupiter.api.Test)1