[java-idp-oidc] branch main updated: JOIDC-26 Revisit sector identifier lookup

Henri Mikkonen henri.mikkonen at iki.fi
Thu Feb 18 15:29:19 UTC 2021


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

hjmikkon pushed a commit to branch main
in repository java-idp-oidc.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-oidc.git;a=commit;h=9fe825387bf0e78c459af8a5157e954cefc61a9e

The following commit(s) were added to refs/heads/main by this push:
       new  9fe82538  JOIDC-26 Revisit sector identifier lookup
9fe82538 is described below

commit 9fe825387bf0e78c459af8a5157e954cefc61a9e
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Thu Feb 18 17:28:40 2021 +0200

    JOIDC-26 Revisit sector identifier lookup
    
    https://issues.shibboleth.net/jira/browse/JOIDC-26
---
 .../navigate/SectorIdentifierLookupFunction.java   | 33 ++++++++++++----------
 .../SectorIdentifierLookupFunctionTest.java        | 16 +++++++++--
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunction.java b/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunction.java
index fc88a368..1409452a 100644
--- a/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunction.java
+++ b/idp-oidc-extension-api/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunction.java
@@ -18,7 +18,9 @@
 package net.shibboleth.idp.plugin.oidc.op.profile.context.navigate;
 
 import java.net.URI;
+import java.util.Set;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -78,25 +80,26 @@ public class SectorIdentifierLookupFunction extends AbstractIdentifiableInitiali
         if (input == null) {
             return null;
         }
-        String sectorIdentifier = null;
         final OIDCMetadataContext ctx = oidcMetadataContextLookupStrategy.apply(input);
         if (ctx == null || ctx.getClientInformation() == null || ctx.getClientInformation().getOIDCMetadata() == null) {
-            log.warn("oidc metadata context not available");
+            log.warn("OIDC metadata not available, no sector identifier can be resolved");
+            return null;
         } else if (ctx.getClientInformation().getOIDCMetadata().getSectorIDURI() != null) {
-            sectorIdentifier = ctx.getClientInformation().getOIDCMetadata().getSectorIDURI().getHost();
-            log.debug("sector identifier by sector uri {}", sectorIdentifier);
-        } else if (ctx.getClientInformation().getOIDCMetadata().getRedirectionURIs() != null
-                && ctx.getClientInformation().getOIDCMetadata().getRedirectionURIs().size() > 1) {
-            log.warn("multiple registered redirection uris, unable to determine sector identifier");
-        } else {
-            final URI redirection = ctx.getClientInformation().getOIDCMetadata().getRedirectionURI();
-            if (redirection != null) {
-                sectorIdentifier = redirection.getHost();
-                log.debug("sector identifier by redirect uri {}", sectorIdentifier);
-            } else {
-                log.warn("redirection uri not available");
-            }
+            final String sectorIdentifier = ctx.getClientInformation().getOIDCMetadata().getSectorIDURI().getHost();
+            log.debug("Sector identifier resolved by registered sector uri {}", sectorIdentifier);
+            return sectorIdentifier;
+        } else if (ctx.getClientInformation().getOIDCMetadata().getRedirectionURIs() == null) {
+            log.warn("Redirection uri not available, unable to determine sector identifier");
+            return null;
+        }
+        final Set<String> hosts = ctx.getClientInformation().getOIDCMetadata().getRedirectionURIs().stream()
+                .map(URI::getHost).collect(Collectors.toSet());
+        if (hosts.size() > 1) {
+            log.warn("Multiple hosts found from the redirection uris but no registered sector uri");
+            return null;
         }
+        final String sectorIdentifier = hosts.stream().findFirst().get();
+        log.debug("Sector identifier by single host from redirect uris: {}", sectorIdentifier);
         return sectorIdentifier;
     }
 
diff --git a/idp-oidc-extension-api/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunctionTest.java b/idp-oidc-extension-api/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunctionTest.java
index 15648b1b..02a2c316 100644
--- a/idp-oidc-extension-api/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunctionTest.java
+++ b/idp-oidc-extension-api/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/context/navigate/SectorIdentifierLookupFunctionTest.java
@@ -24,7 +24,6 @@ import java.util.HashSet;
 import java.util.Set;
 
 import net.shibboleth.idp.plugin.oidc.op.messaging.context.OIDCMetadataContext;
-import net.shibboleth.idp.plugin.oidc.op.profile.context.navigate.SectorIdentifierLookupFunction;
 import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
 import net.shibboleth.idp.profile.testing.RequestContextBuilder;
 
@@ -83,11 +82,22 @@ public class SectorIdentifierLookupFunctionTest {
     public void testSuccessRedirectURIs() {
         final Set<URI> redirectURIs = new HashSet<URI>();
         redirectURIs.add(sector);
-        ctx.getClientInformation().getOIDCMetadata().setRedirectionURIs(redirectURIs );
+        ctx.getClientInformation().getOIDCMetadata().setRedirectionURIs(redirectURIs);
         final String locatedSector = lookup.apply(prc);
         Assert.assertEquals(locatedSector, sector.getHost());
     }
-    
+
+    @Test
+    public void testSuccessMultipleRedirectURIs() throws URISyntaxException {
+        final Set<URI> redirectURIs = new HashSet<URI>();
+        redirectURIs.add(sector);
+        redirectURIs.add(new URI("https://example.org/uri2"));
+        redirectURIs.add(new URI("https://example.org/uri3"));
+        ctx.getClientInformation().getOIDCMetadata().setRedirectionURIs(redirectURIs);
+        final String locatedSector = lookup.apply(prc);
+        Assert.assertEquals(locatedSector, sector.getHost());
+    }
+
     @Test
     public void testFailRedirectURIs() throws URISyntaxException {
         final Set<URI> redirectURIs = new HashSet<>();

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


More information about the commits mailing list