[java-identity-provider] 19/27: Switch to services strategy to instantiate registry.
Scott Cantor
cantor.2 at osu.edu
Fri May 3 14:32:09 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch feature/IDP-1434
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=4ca32234b9b84da9171bd3b717231c0f9fad1b63
commit 4ca32234b9b84da9171bd3b717231c0f9fad1b63
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Apr 30 08:58:33 2019 -0400
Switch to services strategy to instantiate registry.
---
.../spring/impl/AttributeResolverParser.java | 4 +-
.../impl/AttributeRegistryServiceStrategy.java | 101 +++++++++++++++++++++
.../transcoding/spring/impl/package-info.java | 23 +++++
.../src/main/resources/conf/attribute-registry.xml | 5 -
.../main/resources/system/conf/services-system.xml | 23 +++--
5 files changed, 140 insertions(+), 16 deletions(-)
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverParser.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverParser.java
index 63b1f09..757dfc7 100644
--- a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverParser.java
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/impl/AttributeResolverParser.java
@@ -68,10 +68,10 @@ public class AttributeResolverParser implements BeanDefinitionParser {
List<Element> children;
children = configChildren.get(BaseAttributeDefinitionParser.ELEMENT_NAME);
- SpringSupport.parseCustomElements(children, context);
+ SpringSupport.parseLazyInitCustomElements(children, context);
children = configChildren.get(AbstractDataConnectorParser.ELEMENT_NAME);
- SpringSupport.parseCustomElements(children, context);
+ SpringSupport.parseLazyInitCustomElements(children, context);
return null;
}
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/transcoding/spring/impl/AttributeRegistryServiceStrategy.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/transcoding/spring/impl/AttributeRegistryServiceStrategy.java
new file mode 100644
index 0000000..18103d9
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/transcoding/spring/impl/AttributeRegistryServiceStrategy.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.attribute.transcoding.spring.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+
+import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
+import net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistryImpl;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.component.ComponentSupport;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.service.ServiceException;
+import net.shibboleth.utilities.java.support.service.ServiceableComponent;
+
+/**
+ * Strategy for summoning up an {@link AttributeTranscoderRegistryImpl} from a populated {@link ApplicationContext}.
+ */
+public class AttributeRegistryServiceStrategy extends AbstractIdentifiableInitializableComponent implements
+ Function<ApplicationContext,ServiceableComponent<AttributeTranscoderRegistry>> {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(AttributeRegistryServiceStrategy.class);
+
+ /** Name of bean to supply naming function registry property. */
+ @Nullable @NotEmpty private String namingRegistry;
+
+ /**
+ * Set the name of the bean providing the {@link AttributeTranscoderRegistryImpl#setNamingRegistry()} value.
+ *
+ * @param beanName name of bean of type {@link Map}
+ */
+ public void setNamingRegistry(@Nullable @NotEmpty final String beanName) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+ namingRegistry = StringSupport.trimOrNull(beanName);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable public ServiceableComponent<AttributeTranscoderRegistry> apply(
+ @Nullable final ApplicationContext appContext) {
+
+ final Map<Class<?>,Function<?,String>> namingRegistryBean = appContext.getBean(namingRegistry, Map.class);
+
+ final Collection<Collection> mappingBeans = appContext.getBeansOfType(Collection.class).values();
+
+ final Collection<Map<String,Object>> mappings = new ArrayList<>();
+
+ for (final Collection c : Collections2.filter(mappingBeans, Predicates.notNull())) {
+ for (final Object o : c) {
+ if (o instanceof Map) {
+ mappings.add((Map<String,Object>) o);
+ }
+ }
+ }
+
+ final AttributeTranscoderRegistryImpl registry = new AttributeTranscoderRegistryImpl();
+ registry.setNamingRegistry(namingRegistryBean);
+ registry.setTranscoderRegistry(mappings);
+ registry.setId(getId());
+ registry.setApplicationContext(appContext);
+
+ try {
+ registry.initialize();
+ } catch (final ComponentInitializationException e) {
+ throw new ServiceException("Unable to initialize attribute transcoder registry for "
+ + appContext.getDisplayName(), e);
+ }
+ return registry;
+ }
+
+}
\ No newline at end of file
diff --git a/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/transcoding/spring/impl/package-info.java b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/transcoding/spring/impl/package-info.java
new file mode 100644
index 0000000..1278015
--- /dev/null
+++ b/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/transcoding/spring/impl/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * For want of a better place. If there are additional classes needed, this
+ * may move to a dedicated module.
+ */
+
+package net.shibboleth.idp.attribute.transcoding.spring.impl;
\ No newline at end of file
diff --git a/idp-conf/src/main/resources/conf/attribute-registry.xml b/idp-conf/src/main/resources/conf/attribute-registry.xml
index ef2e1ec..aba47dd 100644
--- a/idp-conf/src/main/resources/conf/attribute-registry.xml
+++ b/idp-conf/src/main/resources/conf/attribute-registry.xml
@@ -12,11 +12,6 @@
default-init-method="initialize"
default-destroy-method="destroy">
- <bean id="AttributeTranscoderRegistry"
- class="net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistryImpl"
- p:namingRegistry-ref="DefaultNamingRegistry"
- p:transcoderRegistry-ref="DefaultAttributeRegistry" />
-
<bean id="SAML2StringTranscoder"
class="net.shibboleth.idp.saml.attribute.transcoding.impl.SAML2StringAttributeTranscoder" />
<bean id="SAML2ScopedStringTranscoder"
diff --git a/idp-conf/src/main/resources/system/conf/services-system.xml b/idp-conf/src/main/resources/system/conf/services-system.xml
index 67217fd..543d8a9 100644
--- a/idp-conf/src/main/resources/system/conf/services-system.xml
+++ b/idp-conf/src/main/resources/system/conf/services-system.xml
@@ -63,15 +63,20 @@
p:beanFactoryPostProcessors-ref="shibboleth.PropertySourcesPlaceholderConfigurer" />
<bean id="shibboleth.AttributeRegistryService" class="net.shibboleth.ext.spring.service.ReloadableSpringService"
- c:claz="net.shibboleth.idp.attribute.transcoding.impl.AttributeTranscoderRegistryImpl"
- p:serviceConfigurations-ref="#{
- getObject('%{idp.service.attribute.registry.resources:shibboleth.AttributeRegistryResources}'.trim()) != null
- ? '%{idp.service.attribute.registry.resources:shibboleth.AttributeRegistryResources}'.trim()
- : 'shibboleth.DefaultAttributeRegistryResources' }"
- p:failFast="%{idp.service.attribute.registry.failFast:%{idp.service.failFast:false}}"
- p:reloadCheckDelay="%{idp.service.attribute.registry.checkInterval:PT0S}"
- p:beanPostProcessors-ref="shibboleth.IdentifiableBeanPostProcessor"
- p:beanFactoryPostProcessors-ref="shibboleth.PropertySourcesPlaceholderConfigurer" />
+ p:serviceConfigurations-ref="#{
+ getObject('%{idp.service.attribute.registry.resources:shibboleth.AttributeRegistryResources}'.trim()) != null
+ ? '%{idp.service.attribute.registry.resources:shibboleth.AttributeRegistryResources}'.trim()
+ : 'shibboleth.DefaultAttributeRegistryResources' }"
+ p:failFast="%{idp.service.attribute.registry.failFast:%{idp.service.failFast:false}}"
+ p:reloadCheckDelay="%{idp.service.attribute.registry.checkInterval:PT0S}"
+ p:beanPostProcessors-ref="shibboleth.IdentifiableBeanPostProcessor"
+ p:beanFactoryPostProcessors-ref="shibboleth.PropertySourcesPlaceholderConfigurer">
+ <constructor-arg name="claz" value="net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry" />
+ <constructor-arg name="strategy">
+ <bean class="net.shibboleth.idp.attribute.transcoding.spring.impl.AttributeRegistryServiceStrategy"
+ p:namingRegistry="DefaultNamingRegistry" />
+ </constructor-arg>
+ </bean>
<util:list id ="shibboleth.DefaultAttributeRegistryResources">
<value>%{idp.home}/conf/attribute-registry.xml</value>
</util:list>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list