[java-identity-provider] 02/02: IDP-1870: Detect duplicate entityIDs when ingesting metadata

Brent Putman putmanb at georgetown.edu
Thu Dec 2 03:56:27 UTC 2021


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

putmanb 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=9a54d786c2eea5c94d95fba55605e48ed2f5e1f6

commit 9a54d786c2eea5c94d95fba55605e48ed2f5e1f6
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Nov 19 15:03:46 2021 -0500

    IDP-1870: Detect duplicate entityIDs when ingesting metadata
    
    Update mdquery admin flow components.
---
 .../idp/profile/impl/MetadataQueryRequest.java     | 24 ++++++++++++++
 .../profile/impl/MetadataQueryRequestDecoder.java  | 37 ++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequest.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequest.java
index 9c5efe19e..d304b0076 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequest.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequest.java
@@ -20,6 +20,8 @@ package net.shibboleth.idp.profile.impl;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
+import org.opensaml.saml.metadata.resolver.DetectDuplicateEntityIDs;
+
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
@@ -38,6 +40,9 @@ public class MetadataQueryRequest {
     
     /** Protocol identifier for query. */
     @Nullable private String protocol;
+    
+    /** The strategy for duplicate entityID detection. */
+    @Nullable private DetectDuplicateEntityIDs detectDuplicateEntityIDs;
 
     /**
      * Constructor.
@@ -82,12 +87,31 @@ public class MetadataQueryRequest {
         protocol = StringSupport.trimOrNull(prot);
     }
 
+    /**
+     * Get the strategy for duplicate entityID detection.
+     * 
+     * @return strategy for duplicate entityID detection
+     */
+    @Nullable public DetectDuplicateEntityIDs getDetectDuplicateEntityIDs() {
+        return detectDuplicateEntityIDs;
+    }
+
+    /**
+     * Set the strategy for duplicate entityID detection.
+     * 
+     * @param strategy the strategy for duplicate entityID detection
+     */
+    public void setDetectDuplicateEntityIDs(@Nullable final DetectDuplicateEntityIDs strategy) {
+        detectDuplicateEntityIDs = strategy;
+    }
+
     /** {@inheritDoc} */
     @Override
     public String toString() {
         return MoreObjects.toStringHelper(this)
             .add("entityID", entityID)
             .add("protocol", protocol)
+            .add("detectDuplicateEntityIDs", detectDuplicateEntityIDs)
             .toString();
     }
     
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java
index 82e3f9f87..ab2cf5169 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java
@@ -27,9 +27,11 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
 import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.decoder.MessageDecodingException;
 import org.opensaml.messaging.decoder.servlet.AbstractHttpServletRequestMessageDecoder;
+import org.opensaml.saml.common.messaging.context.SAMLMetadataLookupParametersContext;
 import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
 import org.opensaml.saml.common.messaging.context.SAMLProtocolContext;
 import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.metadata.resolver.DetectDuplicateEntityIDs;
 import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,6 +56,9 @@ public class MetadataQueryRequestDecoder extends AbstractHttpServletRequestMessa
     /** Name of the query parameter for the CAS protocol: {@value} . */
     @Nonnull @NotEmpty public static final String CAS_PARAM = "cas";
     
+    /** Name of the query parameter carrying the detectDuplicateEntityIDs: {@value} . */
+    @Nonnull @NotEmpty public static final String DETECT_DUPLICATES_PARAM= "detectDuplicateEntityIDs";
+
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(MetadataQueryRequestDecoder.class);
     
@@ -68,6 +73,7 @@ public class MetadataQueryRequestDecoder extends AbstractHttpServletRequestMessa
         final MetadataQueryRequest message = new MetadataQueryRequest();
         message.setEntityID(getEntityID(request));
         message.setProtocol(getProtocol(request));
+        message.setDetectDuplicateEntityIDs(getDetectDuplicateEntityIDs(request));
         
         final MessageContext messageContext = new MessageContext();
         messageContext.setMessage(message);
@@ -81,6 +87,11 @@ public class MetadataQueryRequestDecoder extends AbstractHttpServletRequestMessa
         if (message.getProtocol() != null) {
             messageContext.getSubcontext(SAMLProtocolContext.class, true).setProtocol(message.getProtocol());
         }
+        
+        if (message.getDetectDuplicateEntityIDs() != null) {
+           messageContext.getSubcontext(SAMLMetadataLookupParametersContext.class, true)
+               .setDetectDuplicateEntityIDs(message.getDetectDuplicateEntityIDs());
+        }
     }
 
     /**
@@ -125,5 +136,31 @@ public class MetadataQueryRequestDecoder extends AbstractHttpServletRequestMessa
         
         return null;
     }
+    
+    /**
+     * Get the strategy for duplicate entityID detection.
+     * 
+     * @param request current HTTP request
+     * 
+     * @return the strategy, or null
+     * 
+     * @throws MessageDecodingException if the request request contains an invalid value
+     *                                  for <code>detectDuplicateEntityIDs</code>
+     */
+    @Nullable protected DetectDuplicateEntityIDs getDetectDuplicateEntityIDs(@Nonnull final HttpServletRequest request)
+            throws MessageDecodingException {
+        final String strategy = StringSupport.trimOrNull(request.getParameter(DETECT_DUPLICATES_PARAM));
+        if (strategy != null) {
+            try {
+                return DetectDuplicateEntityIDs.valueOf(strategy);
+            } catch (final IllegalArgumentException e) {
+                throw new MessageDecodingException("Saw invalid value for param: " + DETECT_DUPLICATES_PARAM, e);
+            }
+            
+        }
+        
+        return null;
+    }
+
 
 }
\ 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