[java-oidfed-common] 03/03: Exploit criteriaToSubjectEntityIdStrategy in trust chain fetching
Codeberg
noreply at shibboleth.net
Fri Nov 13 11:43:59 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-oidfed-common.
View the commit online:
https://codeberg.org/Shibboleth/java-oidfed-common/commit/000fabc2bcc7a53c6453bb2f04566268a95e921d
commit 000fabc2bcc7a53c6453bb2f04566268a95e921d
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Nov 13 13:43:17 2026 +0200
Exploit criteriaToSubjectEntityIdStrategy in trust chain fetching
- Cover in tests
- Improve Javadoc
---
.../DefaultTrustChainFetchingStrategy.java | 12 ++++++++-
.../oidfed/profile/impl/ResolveTrustChains.java | 11 +++++++-
.../DefaultTrustChainFetchingStrategyTest.java | 30 ++++++++++++++++++++++
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategy.java b/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategy.java
index d2e4c36..0b82608 100644
--- a/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategy.java
+++ b/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategy.java
@@ -55,7 +55,11 @@ import net.shibboleth.shared.resolver.CriteriaSet;
/**
* Default strategy for fetching trust chains for an entity specified in the criteria set. Caches for entity
* configurations and subordinate statements are exploited for actual fetching of the entity statements. The
- * entity configuration may also be delivered via {@link SubjectEntityStatementCriterion} in the criteria set.
+ * entity configuration may also be delivered via {@link SubjectEntityStatementCriterion} in the criteria set. In that
+ * case this strategy fetches the entity ID and compares it to the value fetched via function configured via
+ * {@link #setCriteriaToSubjectEntityIdStrategy(Function)}.
+ *
+ * The strategy returns {@link TrustChainsContainer}, containing the entity ID as the key.
*/
@ThreadSafeAfterInit
public class DefaultTrustChainFetchingStrategy extends AbstractIdentifiableInitializableComponent
@@ -286,6 +290,12 @@ public class DefaultTrustChainFetchingStrategy extends AbstractIdentifiableIniti
if (entityConfiguration == null) {
return null;
}
+ final String entityId = criteriaToSubjectEntityIdStrategy.apply(criteria);
+ if (entityId == null || !entityId.equals(entityConfiguration.getSubject())) {
+ log.warn("Entity configuration subject {} does not match with the value resolved via criteria {}",
+ entityConfiguration.getSubject(), entityId);
+ return null;
+ }
final TrustChainWrapper initialWrapper =
new TrustChainWrapper(CollectionSupport.listOf(entityConfiguration));
diff --git a/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/profile/impl/ResolveTrustChains.java b/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/profile/impl/ResolveTrustChains.java
index 6868c38..39b9325 100644
--- a/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/profile/impl/ResolveTrustChains.java
+++ b/oidfed-common-impl/src/main/java/net/shibboleth/oidfed/profile/impl/ResolveTrustChains.java
@@ -55,7 +55,16 @@ import org.opensaml.profile.action.ActionSupport;
/**
* Resolves metadata policy-compliant trust chains from the configurable trust chain cache, metadata policy merging
- * strategy and enforcer. The data is populated to the {@link RelyingPartyTrustChainContext}.
+ * strategy and enforcer.
+ *
+ * The trust chain metadata cache set via {@link #setTrustChainCache(MetadataCache)} is called with a criteria set that
+ * contains {@link SubjectEntityIDCriterion} and optionally {@link SubjectEntityStatementCriterion} if one is returned
+ * by the lookup set via {@link #setEntityConfigurationLookupStrategy(Function)}. When the statement criterion is
+ * available, it should be taken into account whether the trust chain cache should index its contents with the full
+ * contents of the entity configuration or just with the entity identifier. It may not be acceptable that the same
+ * cached trust chains are returned with varying entity configurations, even though their entity identifiers match.
+ *
+ * The data is populated to the {@link RelyingPartyTrustChainContext}.
*
* @event {@link EventIds#PROCEED_EVENT_ID}
* @event {@link EventIds#INVALID_MSG_CTX}
diff --git a/oidfed-common-impl/src/test/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategyTest.java b/oidfed-common-impl/src/test/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategyTest.java
index 77ae525..7dc943c 100644
--- a/oidfed-common-impl/src/test/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategyTest.java
+++ b/oidfed-common-impl/src/test/java/net/shibboleth/oidfed/metadata/cache/trustchain/DefaultTrustChainFetchingStrategyTest.java
@@ -104,6 +104,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("mockEntityId");
Assert.assertEquals(function.apply(new CriteriaSet()), null);
}
@@ -113,6 +114,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(null);
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("mockEntityId");
Assert.assertEquals(function.apply(new CriteriaSet()), null);
}
@@ -123,6 +125,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(entityConfigurationCache.get(any())).thenReturn(CollectionSupport.emptyList());
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("mockEntityId");
Assert.assertEquals(function.apply(new CriteriaSet()), null);
}
@@ -133,6 +136,20 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(entityConfigurationCache.get(any())).thenThrow(MetadataCacheException.class);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("mockEntityId");
+ Assert.assertEquals(function.apply(new CriteriaSet()), null);
+ }
+
+ @Test
+ public void entityConfigurationIdNotMatching_returnsNull() throws MetadataCacheException {
+ when(criteriaToValidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
+ when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
+ when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
+ when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("notMatching");
+ final EntityConfigurationContainer ecContainer =
+ ecContainer("mockEntityId", CollectionSupport.emptyList());
+ when(entityConfigurationCache.get(any())).thenReturn(CollectionSupport.listOf(ecContainer));
Assert.assertEquals(function.apply(new CriteriaSet()), null);
}
@@ -142,6 +159,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("mockEntityId");
final EntityConfigurationContainer ecContainer =
ecContainer("mockEntityId", CollectionSupport.emptyList());
when(entityConfigurationCache.get(any())).thenReturn(CollectionSupport.listOf(ecContainer));
@@ -154,6 +172,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn("mockEntityId");
final EntityConfigurationContainer ecContainer =
ecContainer("mockEntityId", CollectionSupport.listOf("https://federation.local/immediate"));
when(entityConfigurationCache.get(any())).thenReturn(CollectionSupport.listOf(ecContainer));
@@ -169,6 +188,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(anchor, "https://federation.local/other"));
final EntityConfigurationContainer authorityContainer =
@@ -198,6 +218,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(immediate, "https://federation.local/other"));
final EntityConfigurationContainer immediateContainer =
@@ -229,6 +250,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(immediate));
final EntityConfigurationContainer immediateContainer =
@@ -266,6 +288,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(3);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(immediate));
final EntityConfigurationContainer immediateContainer =
@@ -304,6 +327,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(5);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(workingIntermediate, anotherIntermediate));
final EntityConfigurationContainer workingIntermediateContainer =
@@ -364,6 +388,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(5);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(anotherIntermediate, workingIntermediate));
final EntityConfigurationContainer workingIntermediateContainer =
@@ -423,6 +448,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(intermediate, "https://federation.local/other"));
final EntityConfigurationContainer intermediateContainer =
@@ -460,6 +486,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(anchor, "https://federation.local/other"));
final EntityConfigurationContainer authorityContainer =
@@ -483,6 +510,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(anchor1, anchor2));
final EntityConfigurationContainer authorityContainer1 =
@@ -517,6 +545,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(1);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(anchor1, anchor2));
final EntityConfigurationContainer authorityContainer1 =
@@ -543,6 +572,7 @@ public class DefaultTrustChainFetchingStrategyTest {
when(criteriaToInvalidContainerLifetimeStrategy.apply(any())).thenReturn(Duration.ofMinutes(5));
when(criteriaToMaximumChainLengthStrategy.apply(any())).thenReturn(4);
when(criteriaToMaximumAuthorityHintsStrategy.apply(any())).thenReturn(2);
+ when(criteriaToSubjectEntityIdStrategy.apply(any())).thenReturn(leaf);
final EntityConfigurationContainer ecContainer =
ecContainer(leaf, CollectionSupport.listOf(anchor1));
final EntityConfigurationContainer authorityContainer1 =
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list