[java-shib-profile] branch main updated: Migrate RelyingPartyConfigurationSupport class into shared version.

Scott Cantor cantor.2 at osu.edu
Tue Feb 28 20:25:33 UTC 2023


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

scantor pushed a commit to branch main
in repository java-shib-profile.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-profile.git;a=commit;h=62b6631bc58e8079b180daad7b21a7ba98fb9b66

The following commit(s) were added to refs/heads/main by this push:
     new 62b6631  Migrate RelyingPartyConfigurationSupport class into shared version.
62b6631 is described below

commit 62b6631bc58e8079b180daad7b21a7ba98fb9b66
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Feb 28 15:25:30 2023 -0500

    Migrate RelyingPartyConfigurationSupport class into shared version.
---
 .../RelyingPartyConfigurationSupport.java          | 215 +++++++++++++++++++++
 .../shibboleth/saml/relyingparty/package-info.java |  21 ++
 2 files changed, 236 insertions(+)

diff --git a/shib-saml-profile-api/src/main/java/net/shibboleth/saml/relyingparty/RelyingPartyConfigurationSupport.java b/shib-saml-profile-api/src/main/java/net/shibboleth/saml/relyingparty/RelyingPartyConfigurationSupport.java
new file mode 100644
index 0000000..1297825
--- /dev/null
+++ b/shib-saml-profile-api/src/main/java/net/shibboleth/saml/relyingparty/RelyingPartyConfigurationSupport.java
@@ -0,0 +1,215 @@
+/*
+ * 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.saml.relyingparty;
+
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.common.messaging.context.navigate.EntityDescriptorLookupFunction;
+import org.opensaml.saml.common.profile.logic.EntityAttributesPredicate;
+import org.opensaml.saml.common.profile.logic.EntityAttributesPredicate.Candidate;
+import org.opensaml.saml.common.profile.logic.EntityGroupNamePredicate;
+import org.opensaml.saml.metadata.resolver.MetadataResolver;
+import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+
+import net.shibboleth.profile.relyingparty.RelyingPartyConfiguration;
+import net.shibboleth.profile.context.logic.RelyingPartyIdPredicate;
+import net.shibboleth.saml.profile.context.logic.MappedEntityAttributesPredicate;
+import net.shibboleth.saml.profile.context.navigate.SAMLMetadataContextLookupFunction;
+import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.StrategyIndirectedPredicate;
+
+/**
+ * Support functions for building {@link RelyingPartyConfiguration} objects with SAML-aware
+ * activation conditions.
+ */
+public final class RelyingPartyConfigurationSupport {
+    
+    /** Constructor. */
+    private RelyingPartyConfigurationSupport() {
+        
+    }
+    
+    /**
+     * A shorthand method for constructing a {@link RelyingPartyConfiguration} with an activation condition based on
+     * one or more relying party IDs.
+     * 
+     * <p>If a single ID is supplied, then the ID is also set as the identifier for the configuration.</p>
+     * 
+     * @param <T> type of configuration to manufacture
+     * 
+     * @param claz class type to manufacture
+     * @param relyingPartyIds the relying parties for which the configuration should be active
+     * 
+     * @return  a default-constructed configuration with the appropriate condition set
+     * 
+     * @throws Exception if the object cannot be constructed via a default constructor 
+     */
+    @Nonnull public static <T extends RelyingPartyConfiguration> T byName(@Nonnull final Class<T> claz,
+            @Nonnull @NonnullElements final Collection<String> relyingPartyIds) throws Exception {
+
+        Constraint.isNotNull(relyingPartyIds, "Relying Party ID list cannot be null");
+
+        final T config;
+        try {
+            config = claz.getDeclaredConstructor().newInstance();
+        } catch (final Exception e) {
+            throw e;
+        }
+        config.setActivationCondition(new RelyingPartyIdPredicate(relyingPartyIds));
+        
+        final StringBuffer name = new StringBuffer("EntityNames[");
+        for (final String rpId: relyingPartyIds) {
+            name.append(rpId).append(',');
+            
+        }
+        name.append(']');
+        config.setId(name.toString());
+        return config;
+    }
+
+    /**
+     * A shorthand method for constructing a {@link RelyingPartyConfiguration} with an activation condition based on
+     * one or more {@link org.opensaml.saml.saml2.metadata.EntitiesDescriptor} groups, and optionally via
+     * {@link org.opensaml.saml.saml2.metadata.AffiliationDescriptor} lookup.
+     * 
+     * @param <T> type of configuration to manufacture
+     * 
+     * @param claz class type to manufacture
+     * @param groupNames the group names
+     * @param resolver optional metadata source for affiliation lookup
+     * 
+     * @return  a default-constructed configuration with the appropriate condition set
+     * 
+     * @throws Exception if the object cannot be constructed via a default constructor 
+     */
+    @Nonnull public static <T extends RelyingPartyConfiguration> T byGroup(@Nonnull final Class<T> claz,
+            @Nonnull @NonnullElements final Collection<String> groupNames,
+            @Nullable final MetadataResolver resolver) throws Exception {
+        Constraint.isNotNull(groupNames, "Group name list cannot be null");
+        
+        // We adapt an OpenSAML Predicate applying to an EntityDescriptor by indirecting the lookup of the
+        // EntityDescriptor to a lookup sequence of PRC -> RPC -> SAMLMetadataContext -> EntityDescriptor.
+        
+        final StrategyIndirectedPredicate<ProfileRequestContext,EntityDescriptor> indirectPredicate =
+                new StrategyIndirectedPredicate<>(
+                        new EntityDescriptorLookupFunction().compose(new SAMLMetadataContextLookupFunction()),
+                        new EntityGroupNamePredicate(groupNames, resolver));
+        
+        final T config;
+        try {
+            config = claz.getDeclaredConstructor().newInstance();
+        } catch (final Exception e) {
+            throw e;
+        }
+        config.setActivationCondition(indirectPredicate);
+
+        final StringBuffer name = new StringBuffer("EntityGroups[");
+        for (final String group: groupNames) {
+            name.append(group).append(',');
+            
+        }
+        name.append(']');
+        config.setId(name.toString());
+        return config;
+    }
+
+    
+    /**
+     * A shorthand method for constructing a {@link RelyingPartyConfiguration} with an activation condition based on
+     * an {@link EntityAttributesPredicate}.
+     * 
+     * @param <T> type of configuration to manufacture
+     * 
+     * @param claz class type to manufacture
+     * @param candidates the candidate rules
+     * @param trim true iff tag values in metadata should be trimmed before comparison
+     * @param matchAll true iff all the candidate rules are required to match
+     * 
+     * @return  a default-constructed configuration with the appropriate condition set
+     * 
+     * @throws Exception if the object cannot be constructed via a default constructor 
+     */
+    @Nonnull public static <T extends RelyingPartyConfiguration> T byTag(@Nonnull final Class<T> claz,
+            @Nonnull @NonnullElements final Collection<Candidate> candidates, final boolean trim,
+            final boolean matchAll) throws Exception {
+        Constraint.isNotNull(candidates, "Candidate list cannot be null");
+        
+        // We adapt an OpenSAML Predicate applying to an EntityDescriptor by indirecting the lookup of the
+        // EntityDescriptor to a lookup sequence of PRC -> RPC -> SAMLMetadataContext -> EntityDescriptor.
+        
+        final StrategyIndirectedPredicate<ProfileRequestContext,EntityDescriptor> indirectPredicate =
+                new StrategyIndirectedPredicate<>(
+                        new EntityDescriptorLookupFunction().compose(new SAMLMetadataContextLookupFunction()),
+                        new EntityAttributesPredicate(candidates, trim, matchAll));
+        
+        final T config;
+        try {
+            config = claz.getDeclaredConstructor().newInstance();
+        } catch (final Exception e) {
+            throw e;
+        }
+        config.setActivationCondition(indirectPredicate);
+
+        return config;
+    }
+
+    /**
+     * A shorthand method for constructing a {@link RelyingPartyConfiguration} with an activation condition based on
+     * a {@link MappedEntityAttributesPredicate}.
+     * 
+     * @param <T> type of configuration to manufacture
+     * 
+     * @param claz class type to manufacture
+     * @param candidates the candidate rules
+     * @param trim true iff tag values in metadata should be trimmed before comparison
+     * @param matchAll true iff all the candidate rules are required to match
+     * 
+     * @return  a default-constructed configuration with the appropriate condition set
+     * 
+     * @throws Exception if the object cannot be constructed via a default constructor 
+     */
+    @Nonnull public static <T extends RelyingPartyConfiguration> T byMappedTag(@Nonnull final Class<T> claz,
+            @Nonnull @NonnullElements final Collection<Candidate> candidates, final boolean trim,
+            final boolean matchAll) throws Exception {
+        Constraint.isNotNull(candidates, "Candidate list cannot be null");
+        
+        // We adapt an OpenSAML Predicate applying to an EntityDescriptor by indirecting the lookup of the
+        // EntityDescriptor to a lookup sequence of PRC -> RPC -> SAMLMetadataContext -> EntityDescriptor.
+        
+        final StrategyIndirectedPredicate<ProfileRequestContext,EntityDescriptor> indirectPredicate =
+                new StrategyIndirectedPredicate<>(
+                        new EntityDescriptorLookupFunction().compose(new SAMLMetadataContextLookupFunction()),
+                        new MappedEntityAttributesPredicate(candidates, trim, matchAll));
+        
+        final T config;
+        try {
+            config = claz.getDeclaredConstructor().newInstance();
+        } catch (final Exception e) {
+            throw e;
+        }
+        config.setActivationCondition(indirectPredicate);
+
+        return config;
+    }
+
+}
\ No newline at end of file
diff --git a/shib-saml-profile-api/src/main/java/net/shibboleth/saml/relyingparty/package-info.java b/shib-saml-profile-api/src/main/java/net/shibboleth/saml/relyingparty/package-info.java
new file mode 100644
index 0000000..abe8843
--- /dev/null
+++ b/shib-saml-profile-api/src/main/java/net/shibboleth/saml/relyingparty/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * SAML-specific RelyingParty support classes.
+ */
+package net.shibboleth.saml.relyingparty;
\ 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