[java-idp-oidc] 03/03: JOIDC-312 - Include type-parameter in the default PAR claims set
Codeberg
noreply at shibboleth.net
Mon Nov 23 10:53:31 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/59ce56e5f4267d3290a4ff864c2bf238345ee94c
commit 59ce56e5f4267d3290a4ff864c2bf238345ee94c
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Mon Nov 23 12:52:16 2026 +0200
JOIDC-312 - Include type-parameter in the default PAR claims set
https://shibboleth.atlassian.net/browse/JOIDC-312
- Always include the "type" claim with value "par" by the default serializer
- Log on INFO if it was overwritten (i.e. existing in the request to the PAR endpoint)
- Require it in the default deserializer
- Customizable via 'shibboleth.oidc.par.TypeValueValidationCondition' (BiPredicate<ProfileRequestContext,Object>)
- New global beans:
- shibboleth.oidc.par.DefaultTypeValueValidationCondition (default)
- shibboleth.oidc.par.AllowMissingTypeValueValidationCondition (allows type to be missing for backwards compatibility)
---
...orizationRequestUriDeserializationFunction.java | 26 ++++++-
...thorizationRequestUriSerializationFunction.java | 9 +++
.../META-INF/net.shibboleth.idp/postconfig.xml | 7 ++
.../idp/flows/oidc/authorize/authorize-beans.xml | 3 +-
.../oidc/op/profile/flow/AuthorizeFlowTest.java | 83 ++++++++++++++++++++++
.../net/shibboleth/idp/module/conf/global.xml | 11 +++
6 files changed, 137 insertions(+), 2 deletions(-)
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriDeserializationFunction.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriDeserializationFunction.java
index 1bf38f1c..a6484408 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriDeserializationFunction.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriDeserializationFunction.java
@@ -20,6 +20,7 @@ import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BiFunction;
+import java.util.function.BiPredicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -32,6 +33,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import net.shibboleth.idp.plugin.oidc.op.token.support.TokenClaimsSet;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
@@ -64,6 +66,9 @@ public class DefaultPushedAuthorizationRequestUriDeserializationFunction
/** The lifetime for replay cache record. */
@Nonnull private Duration lifetime;
+ /** The validation condition for the type value validation. */
+ @Nonnull private BiPredicate<ProfileRequestContext,Object> typeValueValidationCondition;
+
/**
* Constructor.
*/
@@ -71,6 +76,8 @@ public class DefaultPushedAuthorizationRequestUriDeserializationFunction
final Duration fiveMins = Duration.ofMinutes(5);
assert fiveMins != null;
lifetime = fiveMins;
+ typeValueValidationCondition = (prc, type) ->
+ DefaultPushedAuthorizationRequestUriSerializationFunction.VALUE_TYPE.equals(type);
}
/**
@@ -114,6 +121,18 @@ public class DefaultPushedAuthorizationRequestUriDeserializationFunction
Constraint.isTrue(!lifetime.isZero() && !lifetime.isNegative(), "Lifetime must be greater than 0");
}
+ /**
+ * Set the validation condition for the type value validation.
+ *
+ * @param condition validation condition
+ * @since 4.4.0
+ */
+ public void setTypeValueValidationCondition(@Nonnull final BiPredicate<ProfileRequestContext,Object> condition) {
+ checkSetterPreconditions();
+ typeValueValidationCondition =
+ Constraint.isNotNull(condition, "Type value validation condition cannot be null");
+ }
+
/** {@inheritDoc} */
@Override
protected void doInitialize() throws ComponentInitializationException {
@@ -146,9 +165,14 @@ public class DefaultPushedAuthorizationRequestUriDeserializationFunction
final String unsealedValue = dataSealer.unwrap(sealedValue);
final Map<String,Object> result = objectMapper.readValue(unsealedValue,
new TypeReference<LinkedHashMap<String, Object>>() {});
+ final Object type = result.get(TokenClaimsSet.KEY_TYPE);
+ if (!typeValueValidationCondition.test(profileRequestContext, type)) {
+ log.warn("The type validation failed for incoming type {}", type);
+ return null;
+ }
final String jti = StringSupport.trimOrNull((String) result.get("jti"));
if (jti == null) {
- log.error("No token identifier (jti) found from the claims set");
+ log.warn("No token identifier (jti) found from the claims set");
return null;
}
final String cacheContext = getClass().getName();
diff --git a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriSerializationFunction.java b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriSerializationFunction.java
index fe37bcd1..ff101405 100644
--- a/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriSerializationFunction.java
+++ b/idp-oidc-extension-impl/src/main/java/net/shibboleth/idp/plugin/oidc/op/profile/logic/DefaultPushedAuthorizationRequestUriSerializationFunction.java
@@ -32,7 +32,9 @@ import org.slf4j.Logger;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import net.shibboleth.idp.plugin.oidc.op.token.support.TokenClaimsSet;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.logic.FunctionSupport;
@@ -49,6 +51,9 @@ public class DefaultPushedAuthorizationRequestUriSerializationFunction
extends AbstractPushedAuthorizationRequestComponent
implements BiFunction<ProfileRequestContext,Map<String,Object>,URI> {
+ /** Value of claims set type. */
+ @Nonnull @NotEmpty public static final String VALUE_TYPE = "par";
+
/** Class logger. */
@Nonnull private final Logger log =
LoggerFactory.getLogger(DefaultPushedAuthorizationRequestUriSerializationFunction.class);
@@ -160,6 +165,10 @@ public class DefaultPushedAuthorizationRequestUriSerializationFunction
}
final Map<String, Object> input = new HashMap<String, Object>(claimsSet);
input.put("jti", idGenerator.generateIdentifier(xmlSafeIdentifier));
+ if (input.containsKey(TokenClaimsSet.KEY_TYPE)) {
+ log.info("Replacing existing type value {} with {}", input.get(TokenClaimsSet.KEY_TYPE), VALUE_TYPE);
+ }
+ input.put(TokenClaimsSet.KEY_TYPE, VALUE_TYPE);
assert expiration != null;
try {
final String serializedClaimsSet = objectMapper.writeValueAsString(input);
diff --git a/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index 42a0b745..ad249b88 100644
--- a/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/idp-oidc-extension-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -961,4 +961,11 @@
<bean id="DefaultMetadataSkeleton" class="org.springframework.core.io.FileSystemResource" lazy-init="true"
c:path="%{idp.oidc.discovery.template:%{idp.home}/static/openid-configuration.json}" />
+ <bean id="shibboleth.oidc.par.DefaultTypeValueValidationCondition" parent="shibboleth.BiConditions.Expression"
+ c:expression="T(net.shibboleth.idp.plugin.oidc.op.profile.logic.DefaultPushedAuthorizationRequestUriSerializationFunction).VALUE_TYPE.equals(#input2)"/>
+
+ <bean id="shibboleth.oidc.par.AllowMissingTypeValueValidationCondition" parent="shibboleth.BiConditions.Expression"
+ c:expression="#input2 == null ? true : #custom.test(#input1, #input2)"
+ p:customObject-ref="shibboleth.oidc.par.DefaultTypeValueValidationCondition"/>
+
</beans>
diff --git a/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/authorize/authorize-beans.xml b/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/authorize/authorize-beans.xml
index 3d9d3b54..7e761ab7 100644
--- a/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/authorize/authorize-beans.xml
+++ b/idp-oidc-extension-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oidc/authorize/authorize-beans.xml
@@ -179,7 +179,8 @@
scope="prototype"
p:dataSealer-ref="#{'%{idp.oidc.tokenSealer:shibboleth.oidc.TokenSealer}'.trim()}"
p:objectMapper-ref="shibboleth.oidc.JSONObjectMapper"
- p:replayCache-ref="shibboleth.ReplayCache" />
+ p:replayCache-ref="shibboleth.ReplayCache"
+ p:typeValueValidationCondition="#{getObject('shibboleth.oidc.par.TypeValueValidationCondition') ?: getObject('shibboleth.oidc.par.DefaultTypeValueValidationCondition')}" />
<bean id="DefaultStorageServicePushedAuthorizationRequestUriDeserializerFactory"
parent="shibboleth.oidc.PushedAuthorizationRequestUriDeserializerFactory"
diff --git a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java
index 67a92511..ae540230 100644
--- a/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java
+++ b/idp-oidc-extension-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/AuthorizeFlowTest.java
@@ -29,6 +29,7 @@ import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -46,6 +47,7 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jose.EncryptionMethod;
import com.nimbusds.jose.JOSEException;
@@ -104,6 +106,7 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
String clientIdFragmentResponseMode = "mockClientIdFragmentResponseMode";
String clientIdQueryFragmentResponseMode = "mockClientIdQueryFragmentResponseMode";
String clientIdRequirePAR = "mockClientIdRequirePAR";
+ String clientIdAllowLegacyPAR = "mockClientIdAllowLegacyPAR";
String clientSecret = "mockClientSecretmockClientSecretmockClientSecretmockClientSecretmockClientSecret";
Scope scope = Scope.parse("openid profile email");
@@ -359,6 +362,62 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
assertDecoratedAuthorizeCodeClaimsSet(successResponse);
}
+ @Test
+ public void testWithAuthorizationCodeFlow_parRequiredByProfileLegacyParNotAllowed() throws IOException,
+ SessionException, URISyntaxException {
+ final String clientId = clientIdRequirePAR;
+ setRequestParameters(List.of(new Pair<>("client_id", clientId),
+ new Pair<>("response_type", "code"),
+ new Pair<>("scope", "openid profile"),
+ new Pair<>("request_uri", createLegacyParGeneratedRequestUri(Map.of(
+ "client_id", clientId, "redirect_uri", redirectUri,
+ "response_type", "code", "scope", "openid profile")).toString()),
+ new Pair<>("redirect_uri", redirectUri)));
+ request.setMethod("GET");
+ final OIDCClientMetadata metadata = buildMetadataSkeleton();
+ metadata.setRedirectionURIs(Set.of(new URI(redirectUri)));
+ metadata.setScope(scope);
+ metadata.requiresPushedAuthorizationRequests(true);
+ storeMetadataObject(storageService, clientId, clientSecret, metadata);
+
+ initializeThreadLocals();
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertErrorCode(result, "invalid_request");
+ }
+
+ @Test
+ public void testWithAuthorizationCodeFlow_legacyParAllowed() throws IOException,
+ SessionException, URISyntaxException {
+ final String clientId = clientIdAllowLegacyPAR;
+ setRequestParameters(List.of(new Pair<>("client_id", clientId),
+ new Pair<>("response_type", "code"),
+ new Pair<>("scope", "openid profile"),
+ new Pair<>("request_uri", createLegacyParGeneratedRequestUri(Map.of(
+ "client_id", clientId, "redirect_uri", redirectUri,
+ "response_type", "code", "scope", "openid profile")).toString()),
+ new Pair<>("redirect_uri", redirectUri)));
+ request.setMethod("GET");
+ final OIDCClientMetadata metadata = buildMetadataSkeleton();
+ metadata.setRedirectionURIs(Set.of(new URI(redirectUri)));
+ metadata.setScope(scope);
+ metadata.requiresPushedAuthorizationRequests(true);
+ storeMetadataObject(storageService, clientId, clientSecret, metadata);
+
+ initializeThreadLocals();
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ final AuthenticationResponse responseMessage = parseSuccessResponse(result, AuthenticationResponse.class);
+ final AuthenticationSuccessResponse successResponse = responseMessage.toSuccessResponse();
+ Assert.assertEquals(successResponse.getRedirectionURI().toString(), redirectUri);
+ Assert.assertNull(successResponse.getIDToken());
+ Assert.assertNull(successResponse.getAccessToken());
+ Assert.assertNotNull(successResponse.getAuthorizationCode());
+ Assert.assertNotNull(getSidFromAuthorizeCodeClaimsSet(successResponse));
+ Assert.assertNull(successResponse.getIssuer());
+ assertDecoratedAuthorizeCodeClaimsSet(successResponse);
+ }
+
@Test
public void testWithAuthorizationCodeFlow_parRequiredByMetadataNotProvided() throws IOException, SessionException,
URISyntaxException {
@@ -419,6 +478,29 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
return parGenerator.apply(null, parameters);
}
+ protected URI createLegacyParGeneratedRequestUri(final Map<String, Object> parameters) {
+ final DefaultPushedAuthorizationRequestUriSerializationFunction parGenerator =
+ new DefaultPushedAuthorizationRequestUriSerializationFunction();
+ parGenerator.setObjectMapper(new ObjectMapper());
+ parGenerator.setDataSealer(getDataSealer());
+ parGenerator.setIdentifierGeneratorLookupStrategy(prc -> idGenerator);
+ parGenerator.setId("mockPar");
+ // type is missing
+ final Map<String, Object> params = new HashMap<>(parameters);
+ params.put("jti", idGenerator.generateIdentifier());
+ try {
+ final String serializedClaimsSet = new ObjectMapper().writeValueAsString(params);
+ assert serializedClaimsSet != null;
+ final String sealedClaimsSet = getDataSealer().wrap(serializedClaimsSet, Instant.now().plusSeconds(300));
+ final String result = DefaultPushedAuthorizationRequestUriSerializationFunction.PAR_REQUEST_URI_PREFIX
+ + sealedClaimsSet;
+ return new URI(result);
+ } catch (JsonProcessingException | DataSealerException | URISyntaxException e) {
+ Assert.fail();
+ }
+ return null;
+ }
+
protected URI createStorageParGeneratedRequestUri(final Map<String, Object> parameters) {
final StorageServicePushedAuthorizationRequestUriSerializationFunction parGenerator =
new StorageServicePushedAuthorizationRequestUriSerializationFunction();
@@ -2991,6 +3073,7 @@ public class AuthorizeFlowTest extends AbstractOidcFlowTest {
removeMetadata(storageService, clientIdQueryFragmentResponseMode);
removeMetadata(storageService, clientIdFragmentResponseMode);
removeMetadata(storageService, clientIdRequirePAR);
+ removeMetadata(storageService, clientIdAllowLegacyPAR);
}
}
diff --git a/idp-oidc-extension-impl/src/test/resources/net/shibboleth/idp/module/conf/global.xml b/idp-oidc-extension-impl/src/test/resources/net/shibboleth/idp/module/conf/global.xml
index bec49b6d..dfb69330 100644
--- a/idp-oidc-extension-impl/src/test/resources/net/shibboleth/idp/module/conf/global.xml
+++ b/idp-oidc-extension-impl/src/test/resources/net/shibboleth/idp/module/conf/global.xml
@@ -172,4 +172,15 @@
<bean class="net.shibboleth.idp.plugin.oidc.op.profile.flow.support.TestAccessTokenClaimsSetDecorator" />
<bean class="net.shibboleth.idp.plugin.oidc.op.profile.flow.support.TestRefreshTokenClaimsSetDecorator" />
<bean class="net.shibboleth.idp.plugin.oidc.op.profile.flow.support.TestAuthorizationCodeClaimsSetDecorator" />
+
+ <bean id="shibboleth.oidc.par.TypeValueValidationCondition" parent="shibboleth.BiConditions.Expression"
+ c:expression="#input1.getInboundMessageContext().getMessage().getClientID().getValue().equals('mockClientIdAllowLegacyPAR') ? #custom.get(1).test(#input1, #input2) : #custom.get(0).test(#input1, #input2)">
+ <property name="customObject">
+ <util:list>
+ <ref bean="shibboleth.oidc.par.DefaultTypeValueValidationCondition"/>
+ <ref bean="shibboleth.oidc.par.AllowMissingTypeValueValidationCondition"/>
+ </util:list>
+ </property>
+ </bean>
+
</beans>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list