[java-identity-provider] branch main updated: IDP-1652 - Support easier integration into configuration by plugins

Scott Cantor cantor.2 at osu.edu
Mon Sep 21 22:36:01 UTC 2020


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=3b35985f94b2b86eb3eac4c3b820c3d2cfbd0c9b

The following commit(s) were added to refs/heads/main by this push:
       new  3b35985f9 IDP-1652 - Support easier integration into configuration by plugins
3b35985f9 is described below

commit 3b35985f94b2b86eb3eac4c3b820c3d2cfbd0c9b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Sep 21 18:35:57 2020 -0400

    IDP-1652 - Support easier integration into configuration by plugins
    
    https://issues.shibboleth.net/jira/browse/IDP-1652
    
    Auto-wire SPSessionSerializers.
---
 .../shibboleth/idp/conf/session-manager-system.xml | 60 +++++++++++--------
 .../idp/session/SPSessionSerializerRegistry.java   | 68 +++++++++++++++++++++-
 2 files changed, 101 insertions(+), 27 deletions(-)

diff --git a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/session-manager-system.xml b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/session-manager-system.xml
index 643daa159..e6c23d84d 100644
--- a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/session-manager-system.xml
+++ b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/session-manager-system.xml
@@ -16,31 +16,43 @@
         class="net.shibboleth.utilities.java.support.security.impl.SecureRandomIdentifierGenerationStrategy"
         c:identifierSize="%{idp.session.idSize:32}" />
 
-    <bean id="shibboleth.DefaultSPSessionSerializerRegistry"
-            class="net.shibboleth.idp.session.SPSessionSerializerRegistry">
-        <property name="mappings">
-            <map>
-                <entry key="#{ T(net.shibboleth.idp.session.BasicSPSession) }">
-                    <bean class="net.shibboleth.idp.session.impl.BasicSPSessionSerializer"
-                        c:offset="%{idp.session.slop:PT0S}" />
-                </entry>
-                <entry key="#{ T(net.shibboleth.idp.saml.session.SAML1SPSession) }">
-                    <bean class="net.shibboleth.idp.saml.session.impl.SAML1SPSessionSerializer"
-                        c:offset="%{idp.session.slop:PT0S}" />
-                </entry>
-                <entry key="#{ T(net.shibboleth.idp.saml.session.SAML2SPSession) }">
-                    <bean class="net.shibboleth.idp.saml.session.impl.SAML2SPSessionSerializer"
-                        c:offset="%{idp.session.slop:PT0S}"
-                        p:parserPool-ref="shibboleth.ParserPool"
-                        depends-on="shibboleth.OpenSAMLConfig" />
-                </entry>
-                <entry key="#{T(net.shibboleth.idp.cas.session.impl.CASSPSession)}">
-                    <bean class="net.shibboleth.idp.cas.session.impl.CASSPSessionSerializer"
-                        c:offset="%{idp.session.slop:PT0S}" />
-                </entry>
-            </map>
-        </property>
+    <!-- SPSession serializers. -->
+    
+    <bean id="shibboleth.SPSessionSerializer" abstract="true"
+        class="net.shibboleth.idp.session.SPSessionSerializerRegistry.Entry" />
+
+    <bean parent="shibboleth.SPSessionSerializer" c:claz="net.shibboleth.idp.session.BasicSPSession">
+        <constructor-arg name="object">
+            <bean class="net.shibboleth.idp.session.impl.BasicSPSessionSerializer"
+                c:offset="%{idp.session.slop:PT0S}" />
+        </constructor-arg>
+    </bean>
+
+    <bean parent="shibboleth.SPSessionSerializer" c:claz="net.shibboleth.idp.saml.session.SAML1SPSession">
+        <constructor-arg name="object">
+            <bean class="net.shibboleth.idp.saml.session.impl.SAML1SPSessionSerializer"
+                c:offset="%{idp.session.slop:PT0S}" />
+        </constructor-arg>
+    </bean>
+
+    <bean parent="shibboleth.SPSessionSerializer" c:claz="net.shibboleth.idp.saml.session.SAML2SPSession">
+        <constructor-arg name="object">
+            <bean class="net.shibboleth.idp.saml.session.impl.SAML2SPSessionSerializer"
+                c:offset="%{idp.session.slop:PT0S}"
+                p:parserPool-ref="shibboleth.ParserPool"
+                depends-on="shibboleth.OpenSAMLConfig" />
+        </constructor-arg>
     </bean>
+
+    <bean parent="shibboleth.SPSessionSerializer" c:claz="net.shibboleth.idp.cas.session.impl.CASSPSession">
+        <constructor-arg name="object">
+            <bean class="net.shibboleth.idp.cas.session.impl.CASSPSessionSerializer"
+                c:offset="%{idp.session.slop:PT0S}" />
+        </constructor-arg>
+    </bean>
+
+    <bean id="shibboleth.DefaultSPSessionSerializerRegistry" class="net.shibboleth.idp.session.SPSessionSerializerRegistry" />
+    
     
     <bean id="shibboleth.DefaultSessionTypeProtocolMap"
             class="org.springframework.beans.factory.config.MapFactoryBean">
diff --git a/idp-session-api/src/main/java/net/shibboleth/idp/session/SPSessionSerializerRegistry.java b/idp-session-api/src/main/java/net/shibboleth/idp/session/SPSessionSerializerRegistry.java
index fc2043566..fb3e288e9 100644
--- a/idp-session-api/src/main/java/net/shibboleth/idp/session/SPSessionSerializerRegistry.java
+++ b/idp-session-api/src/main/java/net/shibboleth/idp/session/SPSessionSerializerRegistry.java
@@ -17,7 +17,7 @@
 
 package net.shibboleth.idp.session;
 
-import java.util.Collections;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -27,7 +27,9 @@ import javax.annotation.Nullable;
 import org.opensaml.storage.StorageSerializer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
@@ -48,7 +50,22 @@ public final class SPSessionSerializerRegistry extends AbstractInitializableComp
 
     /** Constructor. */
     public SPSessionSerializerRegistry() {
-        registry = Collections.emptyMap();
+        this(null);
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param serializers auto-wired serializer entries
+     * 
+     * @since 4.1.0
+     */
+    @Autowired
+    public SPSessionSerializerRegistry(@Nullable @NonnullElements final Collection<Entry<?>> serializers) {
+        registry = new HashMap<>();
+        if (serializers != null) {
+            serializers.forEach(e -> registry.put(e.getType(), e.getSerializer()));
+        }
     }
     
     /**
@@ -61,7 +78,6 @@ public final class SPSessionSerializerRegistry extends AbstractInitializableComp
         ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
         Constraint.isNotNull(map, "Map cannot be null");
         
-        registry = new HashMap<>(map.size());
         for (final Map.Entry<Class<? extends SPSession>,StorageSerializer<? extends SPSession>> entry
                 : map.entrySet()) {
             if (entry.getKey() != null && entry.getValue() != null) {
@@ -91,4 +107,50 @@ public final class SPSessionSerializerRegistry extends AbstractInitializableComp
         return null;
     }
 
+    /**
+     * Wrapper type for auto-wiring serializers.
+     * 
+     * @param <T> session type
+     * 
+     * @since 4.1.0
+     */
+    public static class Entry<T extends SPSession> {
+        
+        /** Session type. */
+        @Nonnull private final Class<T> sessionType;
+        
+        /** Serializer. */
+        @Nonnull private final StorageSerializer<T> serializer;
+        
+        /**
+         * Constructor.
+         *
+         * @param claz session type
+         * @param object serializer
+         */
+        public Entry(@Nonnull @ParameterName(name="claz") final Class<T> claz,
+                @Nullable @ParameterName(name="object") final StorageSerializer<T> object) {
+            sessionType = Constraint.isNotNull(claz, "Session type cannot be null");
+            serializer = object;
+        }
+        
+        /**
+         * Gets session type.
+         * 
+         * @return session type
+         */
+        @Nonnull Class<T> getType() {
+            return sessionType;
+        }
+        
+        /**
+         * Gets {@link StorageSerializer}.
+         * 
+         * @return serializer
+         */
+        @Nullable StorageSerializer<T> getSerializer() {
+            return serializer;
+        }
+    }
+
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list