Search in sources :

Example 1 with DataConnector

use of net.shibboleth.idp.attribute.resolver.DataConnector in project cas by apereo.

the class ShibbolethAttributeResolverConfiguration method attributeRepository.

@Bean
public IPersonAttributeDao attributeRepository() {
    try {
        final PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
        final Map<String, Object> result = new HashMap<>();
        environment.getPropertySources().forEach(s -> {
            if (s instanceof EnumerablePropertySource<?>) {
                final EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) s;
                Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
            }
        });
        final Properties p = new Properties();
        p.putAll(result);
        cfg.setProperties(p);
        registerBeanIntoApplicationContext(cfg, "shibboleth.PropertySourcesPlaceholderConfigurer");
        final ApplicationContext tempApplicationContext = SpringSupport.newContext(getClass().getName(), casProperties.getShibAttributeResolver().getResources(), Collections.singletonList(cfg), Collections.emptyList(), Collections.emptyList(), this.applicationContext);
        final Collection<DataConnector> values = BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, DataConnector.class).values();
        final Collection<DataConnector> connectors = new HashSet<>(values);
        final AttributeResolverImpl impl = new AttributeResolverImpl();
        impl.setId(getClass().getSimpleName());
        impl.setApplicationContext(tempApplicationContext);
        impl.setAttributeDefinitions(BeanFactoryUtils.beansOfTypeIncludingAncestors(tempApplicationContext, AttributeDefinition.class).values());
        impl.setDataConnectors(connectors);
        if (!impl.isInitialized()) {
            impl.initialize();
        }
        return new ShibbolethPersonAttributeDao(impl);
    } catch (final Exception e) {
        LOGGER.warn(e.getMessage(), e);
    }
    return Beans.newStubAttributeRepository(casProperties.getAuthn().getAttributeRepository());
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) EnumerablePropertySource(org.springframework.core.env.EnumerablePropertySource) HashMap(java.util.HashMap) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Properties(java.util.Properties) ApplicationContext(org.springframework.context.ApplicationContext) ShibbolethPersonAttributeDao(org.apereo.cas.persondir.support.ShibbolethPersonAttributeDao) AttributeResolverImpl(net.shibboleth.idp.attribute.resolver.impl.AttributeResolverImpl) DataConnector(net.shibboleth.idp.attribute.resolver.DataConnector) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 DataConnector (net.shibboleth.idp.attribute.resolver.DataConnector)1 AttributeResolverImpl (net.shibboleth.idp.attribute.resolver.impl.AttributeResolverImpl)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 ShibbolethPersonAttributeDao (org.apereo.cas.persondir.support.ShibbolethPersonAttributeDao)1 PropertyPlaceholderConfigurer (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer)1 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)1