[java-oidc-common] branch main updated: Perform custom policy operator merging solely for recognized custom operators

Codeberg noreply at shibboleth.net
Fri Nov 13 06:48:29 UTC 2026


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

codeberg pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
https://codeberg.org/Shibboleth/java-oidc-common/commit/0f7f4aedc54cb644a8784318888074272c1aa9bf

The following commit(s) were added to refs/heads/main by this push:
     new 0f7f4aed Perform custom policy operator merging solely for recognized custom operators
0f7f4aed is described below

commit 0f7f4aedc54cb644a8784318888074272c1aa9bf
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Nov 13 08:48:05 2026 +0200

    Perform custom policy operator merging solely for recognized custom operators
    
    - If the custom operators are not recognized, their merging shouldn't break the policy merging
---
 .../impl/DefaultMetadataPolicyMergingStrategy.java |  5 +-
 .../metadata/policy/impl/MetadataPolicyHelper.java | 75 ++++++++++++++++++----
 2 files changed, 68 insertions(+), 12 deletions(-)

diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyMergingStrategy.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyMergingStrategy.java
index 54a7d8a7..8a795dc7 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyMergingStrategy.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/DefaultMetadataPolicyMergingStrategy.java
@@ -86,6 +86,9 @@ public class DefaultMetadataPolicyMergingStrategy extends AbstractIdentifiableIn
         if (firstMap == null && secondMap == null) {
             return new Pair<>(null, Boolean.TRUE);
         }
+        final List<String> recognizedOperators = operators.stream()
+                .map(operator -> operator.getOperatorName())
+                .toList();
         final Map<String,MetadataPolicy> first = firstMap != null ? firstMap : CollectionSupport.emptyMap();
         final Map<String,MetadataPolicy> second = secondMap != null ? secondMap : CollectionSupport.emptyMap();
         final Set<String> combinedKeys = Stream.concat(first.keySet().stream(), 
@@ -110,7 +113,7 @@ public class DefaultMetadataPolicyMergingStrategy extends AbstractIdentifiableIn
                 }
                 log.debug("Claim {}: Attempting to merge {} with {}", key, firstPolicy, secondPolicy);
                 final MetadataPolicy merged =
-                        MetadataPolicyHelper.mergeMetadataPolicies(firstPolicy, secondPolicy);
+                        MetadataPolicyHelper.mergeMetadataPolicies(firstPolicy, secondPolicy, recognizedOperators);
                 log.debug("Claim {}: Merging result of {} with {}: {}", key, firstPolicy, secondPolicy, merged);
                 if (merged != null) {
                     result.put(key, merged);
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyHelper.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyHelper.java
index ae058da0..b619d2ec 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyHelper.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/policy/impl/MetadataPolicyHelper.java
@@ -70,8 +70,7 @@ public final class MetadataPolicyHelper {
                 ? values.containsAll((Collection<?>) candidate)
                 : false;
     }
-    
- // Checkstyle: CyclomaticComplexity OFF
+
     /**
      * <p>Merges two metadata policies with the rules defined in the OID Federation 1.0 spec 6.1.3.1:</p>
      * <ul>
@@ -101,7 +100,7 @@ public final class MetadataPolicyHelper {
      * </li>
      * </ul>
      * 
-     * <p>In addition to the list above, all custom operators are treated in the same way as value' and 'default'.</p>
+     * <p>In addition to the list above, all custom operators are treated in the same way as 'value' and 'default'.</p>
      * 
      * @param superior The superior metadata policy.
      * @param subordinate The subordinate metadata policy.
@@ -112,6 +111,56 @@ public final class MetadataPolicyHelper {
      */
     @Nullable public static MetadataPolicy mergeMetadataPolicies(@Nullable final MetadataPolicy superior,
             @Nullable final MetadataPolicy subordinate) throws ConstraintViolationException {
+        return mergeMetadataPolicies(superior, subordinate, null);
+    }
+
+ // Checkstyle: CyclomaticComplexity OFF
+    /**
+     * <p>Merges two metadata policies with the rules defined in the OID Federation 1.0 spec 6.1.3.1:</p>
+     * <ul>
+     * <li>
+     * subset_of: The result of merging the values of two subset_of operators is the intersection of the operator
+     * values.
+     * </li>
+     * <li>
+     * one_of: The result of merging the values of two one_of operators is the intersection of the operator values.
+     * </li>
+     * <li>
+     * superset_of: The result of merging the values of two superset_of operators is the union of the operator values.
+     * </li>
+     * <li>
+     * add: The result of merging the values of two add operators is the union of the values.
+     * </li>
+     * <li>
+     * value: Merging two value operators is NOT allowed unless the two operator values are equal.
+     * </li>
+     * <li>
+     * default: Merging two default operators is NOT allowed unless the two operator values are equal.
+     * </li>
+     * <li>
+     * essential: If a superior has specified essential=true, then a subordinate cannot change that. If a superior has
+     * specified essential=false, then a subordinate is allowed to change that to essential=true. If a superior has not
+     * specified essential, then a subordinate can set essential to true or false.
+     * </li>
+     * </ul>
+     * 
+     * <p>In addition to the list above, recognized custom operators are treated in the same way as 'value' and
+     * 'default'.</p>
+     * 
+     * @param superior The superior metadata policy.
+     * @param subordinate The subordinate metadata policy.
+     * @param recognizedOperators The list of operators names for which to apply the custom merging rule, or null if
+     * it's applied to all.
+     * @return The merged metadata policy.
+     * @throws ConstraintViolationException If two 'value' or 'default' operators with different values are attempted
+     * to be merged, merging of 'one_of' produces an empty intersection or non-equal custom operators are attempted to
+     * be merged.
+     * 
+     * @since 4.0.0
+     */
+    @Nullable public static MetadataPolicy mergeMetadataPolicies(@Nullable final MetadataPolicy superior,
+            @Nullable final MetadataPolicy subordinate, @Nullable final List<String> recognizedOperators)
+                    throws ConstraintViolationException {
         if (superior == null) {
             return subordinate;
         }
@@ -132,7 +181,6 @@ public final class MetadataPolicyHelper {
             if (anotherValue != null && !value.equals(anotherValue)) {
                 throw new ConstraintViolationException(
                         "Merging two value operators is NOT allowed unless the two operator values are equal.");
-                
             }
         }
         final List<Object> oneOf = doMergeForTwoLists(superior.getOneOfValues(), subordinate.getOneOfValues(), false);
@@ -141,13 +189,15 @@ public final class MetadataPolicyHelper {
                     "Merging of two one_of operators cannot produce an empty intersection");
         }
         for (final String customOperator : superior.getCustomOperators().keySet()) {
-            if (subordinate.getCustomOperators().containsKey(customOperator)) {
-                final Object superiorValue = superior.getCustomOperators().get(customOperator);
-                final Object subordinateValue = subordinate.getCustomOperators().get(customOperator);
-                if ((superiorValue != null && !superiorValue.equals(subordinateValue)) ||
-                        (superiorValue == null && subordinateValue != null)) {
-                    throw new ConstraintViolationException(
-                            "Merging two custom operators is not allowed unless the values are equal.");
+            if (recognizedOperators == null || recognizedOperators.contains(customOperator)) {
+                if (subordinate.getCustomOperators().containsKey(customOperator)) {
+                    final Object superiorValue = superior.getCustomOperators().get(customOperator);
+                    final Object subordinateValue = subordinate.getCustomOperators().get(customOperator);
+                    if ((superiorValue != null && !superiorValue.equals(subordinateValue)) ||
+                            (superiorValue == null && subordinateValue != null)) {
+                        throw new ConstraintViolationException(
+                                "Merging two custom operators is not allowed unless the values are equal.");
+                    }
                 }
             }
         }
@@ -172,6 +222,7 @@ public final class MetadataPolicyHelper {
         return builder.build();
     }
  // Checkstyle: CyclomaticComplexity ON
+
     /**
      * Merges two metadata policy values that can be either single valued or lists.
      * 
@@ -334,6 +385,8 @@ public final class MetadataPolicyHelper {
      * 
      * @param policy metadata policy to be verified
      * @throws ConstraintViolationException if any standard rule is violated with the message describing the issue
+     * 
+     * @since 4.0.0
      */
     public static void verifyStandardCombinations(@Nonnull final MetadataPolicy policy)
             throws ConstraintViolationException {

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


More information about the commits mailing list