[java-idp-plugin-oidc-op-oidfed] 02/03: Moved endpoint fetching from federation_entity metadata into EntityStatementHelper

Codeberg noreply at shibboleth.net
Thu Dec 4 07:24:05 UTC 2025


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

codeberg pushed a commit to branch main
in repository java-idp-plugin-oidc-op-oidfed.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-oidc-op-oidfed/commit/ab2f4c3a6286216b804a603d4847d29c6157db88

commit ab2f4c3a6286216b804a603d4847d29c6157db88
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Wed Dec 3 16:04:33 2025 +0200

    Moved endpoint fetching from federation_entity metadata into EntityStatementHelper
---
 .../op/oidfed/metadata/EntityStatementHelper.java  | 37 ++++++++++++++++++++++
 .../oidfed/profile/impl/CallResolveEntityApi.java  | 32 ++-----------------
 2 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/metadata/EntityStatementHelper.java b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/metadata/EntityStatementHelper.java
index a80a584..6b3444f 100644
--- a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/metadata/EntityStatementHelper.java
+++ b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/metadata/EntityStatementHelper.java
@@ -14,8 +14,10 @@
 
 package net.shibboleth.idp.plugin.oidc.op.oidfed.metadata;
 
+import java.net.URI;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -29,8 +31,11 @@ import com.fasterxml.jackson.databind.type.MapType;
 import com.nimbusds.oauth2.sdk.ParseException;
 import com.nimbusds.openid.connect.sdk.federation.entities.EntityStatement;
 
+import net.shibboleth.oidc.metadata.cache.MetadataCache;
+import net.shibboleth.oidc.metadata.cache.MetadataCacheException;
 import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.resolver.CriteriaSet;
 
 /**
  * Static utility method related to entity statements.
@@ -160,4 +165,36 @@ public class EntityStatementHelper {
         return entityStatement == null ? null : entityStatement.getSignedStatement().serialize();
     }
 
+    /**
+     * Fetch the endpoint URI for the given endpoint ID from a federation_entity metadata. The entity statement is
+     * fetched from the given cache by using the given entity ID as {@link SubjectEntityIDCriterion}.
+     * 
+     * @param cache metadata cache used for fetching the entity configuration
+     * @param entityId entity ID of the entity
+     * @param endpointId the endpoint ID
+     * @param objectMapper object mapper used for parsing
+     * @return endpoint URI
+     */
+    @Nullable public static URI fetchEndpointUriFromFederationEntity(@Nonnull MetadataCache<EntityStatement> cache,
+            @Nonnull final String entityId, @Nonnull final String endpointId,
+            @Nonnull final ObjectMapper objectMapper) {
+        final CriteriaSet criteria = new CriteriaSet(new SubjectEntityIDCriterion(entityId));
+        try {
+            final List<EntityStatement> result = cache.get(criteria);
+            if (!result.isEmpty()) {
+                return Optional.ofNullable(parseMetadata(objectMapper, result.get(0)).get("federation_entity"))
+                        .filter(Map.class::isInstance)
+                        .map(map -> (Map<String,Object>) map)
+                        .map(map -> map.get(endpointId))
+                        .filter(String.class::isInstance)
+                        .map(String.class::cast)
+                        .map(URI::create)
+                        .orElse(null);
+            }
+        } catch (final MetadataCacheException e) {
+            log.debug("Error while fetching entity configuration for {}", entityId, e);
+        }
+        log.warn("Could not fetch entity configuration for {}", entityId);
+        return null;
+    }
 }
\ No newline at end of file
diff --git a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/CallResolveEntityApi.java b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/CallResolveEntityApi.java
index a9adf43..c4f123b 100644
--- a/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/CallResolveEntityApi.java
+++ b/idp-oidfed-op-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/oidfed/profile/impl/CallResolveEntityApi.java
@@ -373,7 +373,8 @@ public class CallResolveEntityApi extends AbstractProfileAction {
                 trustChainContext.setAttemptedTrustedRemoteResolverEntities(
                         CollectionSupport.copyToList(alreadyAttemptedEntities));
             }
-            final URI uri = fetchResolveEntityEndpoint(trustedEntity);
+            final URI uri = EntityStatementHelper.fetchEndpointUriFromFederationEntity(entityConfigurationCache,
+                    trustedEntity.getEntityId(), "federation_resolve_endpoint", objectMapper);
             if (uri == null) {
                 log.warn("{} Could not fetch federation resolve endpoint for {}", getLogPrefix(), trustedEntity);
                 continue;
@@ -488,35 +489,6 @@ public class CallResolveEntityApi extends AbstractProfileAction {
 
     }
 
-    /**
-     * Fetch the resolve entity endpoint via entity configuration from the metadata cache.
-     * 
-     * @param trustedEntity the trusted entity
-     * @return the resolve entity endpoint, or null if could not be fetched
-     */
-    @Nullable protected URI fetchResolveEntityEndpoint(@Nonnull final TrustedRemoteResolverEntity trustedEntity) {
-        final String subject = trustedEntity.getEntityId();
-        final CriteriaSet criteria = new CriteriaSet(new SubjectEntityIDCriterion(subject));
-        try {
-            final List<EntityStatement> result = entityConfigurationCache.get(criteria);
-            if (!result.isEmpty()) {
-                return Optional.ofNullable(
-                        EntityStatementHelper.parseMetadata(objectMapper, result.get(0)).get("federation_entity"))
-                        .filter(Map.class::isInstance)
-                        .map(map -> (Map<String,Object>) map)
-                        .map(map -> map.get("federation_resolve_endpoint"))
-                        .filter(String.class::isInstance)
-                        .map(String.class::cast)
-                        .map(URI::create)
-                        .orElse(null);
-            }
-        } catch (final MetadataCacheException e) {
-            log.debug("{} Error while fetching entity configuration for {}", getLogPrefix(), subject, e);
-        }
-        log.warn("{} Could not fetch entity configuration for {}", getLogPrefix(), subject);
-        return null;
-    }
-
     /**
      * Parses the trust mark.
      * 

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


More information about the commits mailing list