[java-idp-oidc] 02/02: JOIDC-306 - Update support for metadata policies
Codeberg
noreply at shibboleth.net
Thu Nov 26 07:22:18 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-idp-oidc.
View the commit online:
https://codeberg.org/Shibboleth/java-idp-oidc/commit/0d7ad92809d5f476262225869634898b3a3a665c
commit 0d7ad92809d5f476262225869634898b3a3a665c
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Thu Nov 26 09:21:04 2026 +0200
JOIDC-306 - Update support for metadata policies
https://shibboleth.atlassian.net/browse/JOIDC-306
Modified scope handling in dynamic client registration to fail if policy (subset_of) emptied a requested scope
---
.../op/profile/impl/AddScopeToClientMetadata.java | 75 +++++++++++++++++++---
.../profile/impl/AddScopeToClientMetadataTest.java | 38 ++++++++++-
2 files changed, 101 insertions(+), 12 deletions(-)
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadata.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadata.java
index 9a67a80f..ece9bf62 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadata.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadata.java
@@ -14,8 +14,12 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
+import java.util.function.Function;
+
import javax.annotation.Nonnull;
+import org.opensaml.profile.action.ActionSupport;
+import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
@@ -23,6 +27,8 @@ import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.openid.connect.sdk.OIDCScopeValue;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
+import net.shibboleth.idp.plugin.oidc.op.messaging.context.navigate.DefaultRequestedMetadataLookupFunction;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -34,24 +40,34 @@ public class AddScopeToClientMetadata extends AbstractOIDCClientMetadataPopulati
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(AddScopeToClientMetadata.class);
-
+
/** The default {@link Scope} if it was not defined in the request. */
@Nonnull private Scope defaultScope;
+ /**
+ * Strategy used to locate the {@link OIDCClientMetadata} associated with the request with no policy enforcement.
+ */
+ @Nonnull private Function<ProfileRequestContext,OIDCClientMetadata> oidcRequestMetadataLookupStrategy;
+
+ /** The metadata associated with the request message. */
+ @NonnullBeforeExec private OIDCClientMetadata requestMetadata;
+
/** Constructor. */
public AddScopeToClientMetadata() {
defaultScope = new Scope();
defaultScope.add(OIDCScopeValue.OPENID);
+ oidcRequestMetadataLookupStrategy = new DefaultRequestedMetadataLookupFunction();
}
-
+
/**
* Set the default {@link Scope} to be used if it was not defined in the request.
* @param scope The default {@link Scope} to be used if it was not defined in the request.
*/
public void setDefaultScope(@Nonnull final Scope scope) {
+ checkSetterPreconditions();
defaultScope = Constraint.isNotNull(scope, "The default scope cannot be null");
}
-
+
/**
* Get the default {@link Scope} to be used if it was not defined in the request.
* @return The default {@link Scope} to be used if it was not defined in the request.
@@ -59,16 +75,57 @@ public class AddScopeToClientMetadata extends AbstractOIDCClientMetadataPopulati
@Nonnull public Scope getDefaultScope() {
return defaultScope;
}
-
+
+ /**
+ * Set the strategy used to locate the {@link OIDCClientMetadata} associated with the request with no policy
+ * enforcement.
+ *
+ * @param strategy lookup strategy
+ * @since 5.0.0
+ */
+ public void setOidcRequestMetadataLookupStrategy(
+ @Nonnull final Function<ProfileRequestContext,OIDCClientMetadata> strategy) {
+ checkSetterPreconditions();
+ oidcRequestMetadataLookupStrategy = Constraint.isNotNull(strategy,
+ "The request OIDCClientMetadata lookup strategy cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
+ requestMetadata = oidcRequestMetadataLookupStrategy.apply(profileRequestContext);
+ if (requestMetadata == null) {
+ log.debug("{} No request OIDCMetadata associated with this profile request", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MSG_CTX);
+ return false;
+ }
+ return true;
+ }
+
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- final Scope requestScope = getInputMetadata().getScope();
- if (requestScope == null || requestScope.isEmpty()) {
- log.debug("{} Scope in the request was null, adding default scope", getLogPrefix());
- getOutputMetadata().setScope(defaultScope);
+ final Scope inputScope = getInputMetadata().getScope();
+ final Scope requestScope = requestMetadata.getScope();
+ if (inputScope == null) {
+ if (requestScope == null) {
+ log.debug("{} Scope in the request was null, adding default scope", getLogPrefix());
+ getOutputMetadata().setScope(defaultScope);
+ } else {
+ log.debug("{} Scope nullified by the policy, ignoring it on output", getLogPrefix());
+ }
+ } else if (inputScope.isEmpty() && (requestScope != null && !requestScope.isEmpty())) {
+ log.warn("{} Scope in the request was not empty but now is, assuming it's emptied by the policy",
+ getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
+ return;
} else {
- getOutputMetadata().setScope(requestScope);
+ getOutputMetadata().setScope(inputScope);
}
}
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java
index bee2d981..33f53d96 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/impl/AddScopeToClientMetadataTest.java
@@ -14,6 +14,7 @@
package net.shibboleth.idp.plugin.oidc.op.profile.impl;
+import org.opensaml.profile.action.EventIds;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -22,7 +23,9 @@ import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.openid.connect.sdk.OIDCScopeValue;
import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
+import net.shibboleth.idp.profile.testing.ActionTestingSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.FunctionSupport;
/**
* Unit test for {@link AddScopeToClientMetadata}.
@@ -52,15 +55,44 @@ public class AddScopeToClientMetadataTest extends BaseOIDCClientMetadataPopulati
}
@Test
- public void testEmptyScope() throws ComponentInitializationException {
+ public void testEmptyScopeNoScopeInRequest() throws ComponentInitializationException {
OIDCClientMetadata input = new OIDCClientMetadata();
input.setScope(new Scope());
OIDCClientMetadata output = new OIDCClientMetadata();
setUpContext(input, output);
Assert.assertNull(action.execute(requestCtx));
- Assert.assertEquals(output.getScope(), action.getDefaultScope());
+ Assert.assertEquals(output.getScope(), Scope.parse(""));
}
-
+
+ @Test
+ public void testEmptyScopeEmptyScopeInRequest() throws ComponentInitializationException {
+ final OIDCClientMetadata metadata = new OIDCClientMetadata();
+ metadata.setScope(new Scope());
+ action = new AddScopeToClientMetadata();
+ action.setOidcRequestMetadataLookupStrategy(FunctionSupport.constant(metadata));
+ action.initialize();
+ OIDCClientMetadata input = new OIDCClientMetadata();
+ input.setScope(new Scope());
+ OIDCClientMetadata output = new OIDCClientMetadata();
+ setUpContext(input, output);
+ Assert.assertNull(action.execute(requestCtx));
+ Assert.assertEquals(output.getScope(), Scope.parse(""));
+ }
+
+ @Test
+ public void testEmptyScopeNonEmptyScopeInRequest() throws ComponentInitializationException {
+ final OIDCClientMetadata metadata = new OIDCClientMetadata();
+ metadata.setScope(new Scope("openid"));
+ action = new AddScopeToClientMetadata();
+ action.setOidcRequestMetadataLookupStrategy(FunctionSupport.constant(metadata));
+ action.initialize();
+ OIDCClientMetadata input = new OIDCClientMetadata();
+ input.setScope(new Scope());
+ OIDCClientMetadata output = new OIDCClientMetadata();
+ setUpContext(input, output);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_MESSAGE);
+ }
+
@Test
public void testNullScopeCustomDefault() throws ComponentInitializationException {
action = new AddScopeToClientMetadata();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list