[java-idp-plugin-vci] 01/01: credential-offer flow review, OP conventions, profile counter, client authentication is now must, mapped errors, OP client id lookup, no-cache headers set by the action

Codeberg noreply at shibboleth.net
Mon Nov 16 08:14:32 UTC 2026


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

codeberg pushed a commit to branch dev/REVIEWOFFERCALLERFLOW
in repository java-idp-plugin-vci.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-vci/commit/85f7762579f8a22b19f95b205a54b6016e970f8b

commit 85f7762579f8a22b19f95b205a54b6016e970f8b
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Mon Nov 16 10:13:51 2026 +0200

    credential-offer flow review, OP conventions, profile counter, client authentication is now must, mapped errors, OP client id lookup, no-cache headers set by the action
---
 README.md                                          |   1 -
 .../messaging/impl/CredentialOfferRequest.java     |  43 +------
 .../impl/CredentialOfferSuccessResponse.java       |   2 -
 ...faultOpenIDVCICredentialOfferConfiguration.java |  11 +-
 ...FormOutboundCredentialOfferResponseMessage.java |  10 ++
 .../credential-offer/credential-offer-beans.xml    |  29 ++++-
 .../messaging/impl/CredentialOfferRequestTest.java |  29 +++--
 ...tOpenIDVCICredentialOfferConfigurationTest.java |  48 +++++++
 ...OutboundCredentialOfferResponseMessageTest.java | 140 +++++++++++++++++++++
 9 files changed, 255 insertions(+), 58 deletions(-)

diff --git a/README.md b/README.md
index fb131e4..cc48206 100644
--- a/README.md
+++ b/README.md
@@ -4727,7 +4727,6 @@ Request, a `POST` of `application/json`:
 |---|---|---|
 | `preAuthorizedCredentials` | Object | Required. Keyed with credential configuration ID, each an array of `{"path": [...], "value": ...}`, or a list of datasets `{"dataset_id": ..., "claims": [...]}`. See [Several credentials of one configuration](#several-credentials-of-one-configuration). |
 | `txCode` | Object | `value`, and hints `input_mode` (`numeric` or `text`), `length` and `description`. `value` is not in the offer. |
-| `client_id` | String | Only where unauthenticated callers are accepted. |
 
 Response is the Credential Offer as an `openid-credential-offer://` deep link. An offer of a
 credential configuration whose `scope` is not in the `scope` of the client is refused with
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequest.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequest.java
index 6364cb3..83e0344 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequest.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequest.java
@@ -37,8 +37,6 @@ import com.nimbusds.oauth2.sdk.OAuth2Error;
 import com.nimbusds.oauth2.sdk.ParseException;
 import com.nimbusds.oauth2.sdk.auth.ClientAuthentication;
 import com.nimbusds.oauth2.sdk.http.HTTPRequest;
-import com.nimbusds.oauth2.sdk.id.ClientID;
-import com.nimbusds.oauth2.sdk.util.StringUtils;
 
 /**
  * Class implements proprietary Credential Offer Request.
@@ -79,28 +77,6 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
         this.credentialOfferTxCode = credentialOfferTxCode;
     }
 
-    /**
-     * Constructor.
-     * 
-     * @param uri                      The URI of the endpoint (HTTP or HTTPS) for
-     *                                 which the request is intended, {@code null}
-     *                                 if not specified (if, for example, the
-     *                                 {@link #toHTTPRequest()} method will not be
-     *                                 used).
-     * @param clientID                 The client identifier, {@code null} if not
-     *                                 specified.
-     * @param preAuthorizedCredentials Credentials offered in the pre-authorized
-     *                                 code flow.
-     * @param credentialOfferTxCode    Transaction Code the wallet must present.
-     */
-    public CredentialOfferRequest(@Nullable final URI uri, @Nullable final ClientID clientID,
-            @Nullable final Map<String, List<CredentialDataset>> preAuthorizedCredentials,
-            @Nullable final CredentialOfferTxCode credentialOfferTxCode) {
-        super(uri, clientID);
-        this.preAuthorizedCredentials = preAuthorizedCredentials;
-        this.credentialOfferTxCode = credentialOfferTxCode;
-    }
-
     /**
      * Get credential offer request content in pre-auth flow.
      * 
@@ -133,14 +109,16 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
         httpRequest.ensureMethod(HTTPRequest.Method.POST);
         httpRequest.ensureEntityContentType(ContentType.APPLICATION_JSON);
         final ClientAuthentication clientAuth;
-
-        // TODO: Implement additional client authentication parsing from JSON content
         try {
             clientAuth = ClientAuthentication.parse(httpRequest);
         } catch (final ParseException e) {
             throw new ParseException(e.getMessage(),
                     OAuth2Error.INVALID_REQUEST.appendDescription(": " + e.getMessage()));
         }
+        if (clientAuth == null) {
+            throw new ParseException("Missing client authentication",
+                    OAuth2Error.INVALID_CLIENT.appendDescription(": no client authentication"));
+        }
 
         final Map<String, Object> content;
         try {
@@ -178,18 +156,7 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
         } catch (final URISyntaxException e) {
             throw new ParseException(e.getMessage(), e);
         }
-        if (clientAuth != null) {
-            return new CredentialOfferRequest(uri, clientAuth, preAuthorizedCredentials, credentialOfferTxCode);
-
-        }
-        // We parse non authenticated client id from JSON content.
-        final String clientIDString = (String) content.get("client_id");
-        if (StringUtils.isBlank(clientIDString)) {
-            throw new ParseException(
-                    "Invalid credential offer request: No client authentication or client_id parameter found");
-        }
-        return new CredentialOfferRequest(uri, new ClientID(clientIDString), preAuthorizedCredentials,
-                credentialOfferTxCode);
+        return new CredentialOfferRequest(uri, clientAuth, preAuthorizedCredentials, credentialOfferTxCode);
     }
 // Checkstyle: CyclomaticComplexity ON
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java
index 2c98ccd..d9e3bba 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java
@@ -132,8 +132,6 @@ public class CredentialOfferSuccessResponse implements SuccessResponse {
     public HTTPResponse toHTTPResponse() {
         final HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK);
         httpResponse.setEntityContentType(ContentType.APPLICATION_JSON);
-        httpResponse.setCacheControl("no-store");
-        httpResponse.setPragma("no-cache");
         try {
             httpResponse.setContent(toOffer());
         } catch (final JsonProcessingException e) {
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfiguration.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfiguration.java
index db791b8..46db88a 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfiguration.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfiguration.java
@@ -16,10 +16,19 @@
 
 package org.geant.shibboleth.plugin.openidvci.profile.config.impl;
 
+import javax.annotation.Nonnull;
+
 import org.geant.shibboleth.plugin.openidvci.profile.config.OpenIDVCIConfiguration;
 
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
+
 /** Profile configuration for the Credential Offer endpoint. */
-public class DefaultOpenIDVCICredentialOfferConfiguration extends AbstractOpenIDVCIConfiguration{
+public class DefaultOpenIDVCICredentialOfferConfiguration extends AbstractOpenIDVCIConfiguration {
+
+    /** Credential Offer profile counter name. */
+    @Nonnull
+    @NotEmpty
+    public static final String PROFILE_COUNTER = "net.shibboleth.idp.profiles.openid.vci.credential-offer";
 
     /** Constructor. */
     public DefaultOpenIDVCICredentialOfferConfiguration() {
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java
index 9a36e85..3c9e1f2 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java
@@ -28,10 +28,13 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import jakarta.servlet.http.HttpServletResponse;
 import net.shibboleth.idp.profile.AbstractProfileAction;
+import net.shibboleth.idp.profile.IdPEventIds;
 import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.servlet.HttpServletSupport;
 
 /**
  * Action forming {@link CredentialOfferSuccessResponse}.
@@ -93,6 +96,13 @@ public class FormOutboundCredentialOfferResponseMessage extends AbstractProfileA
     /** {@inheritDoc} */
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+        final HttpServletResponse response = getHttpServletResponse();
+        if (response == null) {
+            log.error("{} Could not fetch HttpServletResponse", getLogPrefix());
+            ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+            return;
+        }
+        HttpServletSupport.addNoCacheHeaders(response);
         final CredentialOfferSuccessResponse offer = new CredentialOfferSuccessResponse(
                 issuerLookupStrategy.apply(profileRequestContext), ctx.getCredentialOfferToken(),
                 ctx.getValidatedPreAuthorizedCredentials(), ctx.getCredentialOfferTxCode());
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml
index 441d0b6..db3b8ff 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml
@@ -11,14 +11,18 @@
                            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" 
        default-init-method="initialize" default-destroy-method="destroy">
        
- <bean id="openidvci.profileId" class="java.lang.String" c:_0="http://geant.org/ns/profiles/openid/vci/credential-offer"/>
+ <bean id="openidvci.profileId" class="java.lang.String"
+       c:_0="#{T(org.geant.shibboleth.plugin.openidvci.profile.config.OpenIDVCIConfiguration).PROFILE_ID_CREDENTIAL_OFFER}"/>
  <bean id="openidvci.loggingId" class="java.lang.String"
        c:_0="%{openidvci.logging.credential-offer:OpenID.VCI.CredentialOffer}"/>
+ <util:constant id="shibboleth.metrics.ProfileCounter"
+       static-field="org.geant.shibboleth.plugin.openidvci.profile.config.impl.DefaultOpenIDVCICredentialOfferConfiguration.PROFILE_COUNTER"/>
  
  <bean id="OpenIDVCIDecodeMessage" class="org.opensaml.profile.action.impl.DecodeMessage" scope="prototype">
   <constructor-arg>
    <bean class="org.geant.shibboleth.plugin.openidvci.decoding.impl.CredentialOfferRequestDecoder"
-        scope="prototype" p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier"/>
+        scope="prototype" p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier"
+        p:removeIpAddressFromEndpointUri="%{idp.oidc.logging.removeIpAddressFromProtocolMessage:false}"/>
   </constructor-arg>
  </bean>
  
@@ -38,7 +42,8 @@
        
  <bean id="OpenIDVCIFormOutboundMessage" class="org.geant.shibboleth.plugin.openidvci.profile.impl.FormOutboundCredentialOfferResponseMessage"
     p:issuerLookupStrategy-ref="shibboleth.ResponderIdLookup.Simple"
-    p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier" scope="prototype"/>
+    p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier"
+    p:httpServletResponseSupplier-ref="shibboleth.HttpServletResponseSupplier" scope="prototype"/>
     
  <bean id="OpenIDVCIBuildErrorResponseFromEvent"
         class="net.shibboleth.oidc.profile.impl.BuildJSONErrorResponseFromEvent" scope="prototype"
@@ -49,15 +54,27 @@
   </property>
   <property name="mappedErrors">
       <map value-type="com.nimbusds.oauth2.sdk.ErrorObject">
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).AUTHN_EXCEPTION}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).SUBJECT_C14N_ERROR}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).UNKNOWN_USERNAME}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).NO_CREDENTIALS}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).INVALID_CREDENTIALS}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).ACCOUNT_LOCKED}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).ACCOUNT_ERROR}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).RESELECT_FLOW}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.authn.AuthnEventIds).NO_POTENTIAL_FLOW}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
         <entry key="#{T(org.opensaml.profile.action.EventIds).ACCESS_DENIED}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_CLIENT}" />
+        <entry key="#{T(net.shibboleth.idp.profile.IdPEventIds).INVALID_PROFILE_CONFIG}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).UNAUTHORIZED_CLIENT}" />
+        <entry key="#{T(org.opensaml.profile.action.EventIds).IO_ERROR}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).SERVER_ERROR}" />
         <entry key="#{T(net.shibboleth.oidc.profile.core.OidcEventIds).INVALID_SCOPE}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_SCOPE}" />
-        <entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).NO_CREDENTIAL_REQUEST}" value="#{T(org.geant.shibboleth.plugin.openidvci.messaging.error.OpenIDVCIError).CONF_ERROR}" />
-        <entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).NO_CREDENTIAL_CONFIGURATION}" value="#{T(org.geant.shibboleth.plugin.openidvci.messaging.error.OpenIDVCIError).CONF_ERROR}" />
+        <entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).NO_CREDENTIAL_REQUEST}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).SERVER_ERROR}" />
+        <entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).NO_CREDENTIAL_CONFIGURATION}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).SERVER_ERROR}" />
       </map>
     </property>
  </bean>
 
  <bean id="shibboleth.ClientIDLookupStrategy"
-        class="org.geant.shibboleth.plugin.openidvci.profile.context.navigate.APIRequestClientIDLookupFunction" />
+        class="net.shibboleth.idp.plugin.oidc.op.messaging.context.navigate.TokenRequestClientIDLookupFunction"
+        scope="prototype" />
         
 </beans>
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequestTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequestTest.java
index 1d6cfc5..9ee6c04 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequestTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferRequestTest.java
@@ -21,13 +21,14 @@ import java.net.URI;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import com.nimbusds.oauth2.sdk.OAuth2Error;
 import com.nimbusds.oauth2.sdk.ParseException;
 import com.nimbusds.oauth2.sdk.http.HTTPRequest;
 
 import org.testng.Assert;
 
 /**
- * Unit tests for {@link OAuth2DeviceAuthenticationRequest}.
+ * Unit tests for {@link CredentialOfferRequest}.
  */
 public class CredentialOfferRequestTest {
 
@@ -59,20 +60,28 @@ public class CredentialOfferRequestTest {
     }
 
     @Test
-    public void testNonAuthSuccess() throws ParseException {
+    public void testClientIdWithoutAuthenticationFailure() {
         httpRequest.setAuthorization(null);
         httpRequest.setBody(
-                "{\"client_id\":\"test\",\"preAuthorizedCredentials\":{\"GeantIncubatorSdJwt2\":[{\"path\":[\"mail\"],\"value\":\"incubatorUser at example.org\"},{\"path\":[\"edu\",\"eppn\"],\"value\":\"incubatorUser at example.org\"},{\"path\":[\"givenName\"],\"value\":\"Gemma Gemina Erasmus\"},{\"path\":[\"familyName\"],\"value\":\"Erasmus\"}]}}");
-        request = CredentialOfferRequest.parse(httpRequest);
-        Assert.assertEquals(request.getClientID().toString(), "test");
-        Assert.assertNull(request.getClientAuthentication());
-        Assert.assertTrue(request.getPreAuthorizedCredentials().containsKey("GeantIncubatorSdJwt2"));
+                "{\"client_id\":\"test\",\"preAuthorizedCredentials\":{\"GeantIncubatorSdJwt2\":[{\"path\":[\"mail\"],\"value\":\"incubatorUser at example.org\"}]}}");
+        try {
+            CredentialOfferRequest.parse(httpRequest);
+            Assert.fail("Request without client authentication accepted");
+        } catch (final ParseException e) {
+            Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_CLIENT.getCode());
+        }
     }
 
-    @Test(expectedExceptions = ParseException.class)
-    public void testNonIdentifiedClientFailure() throws ParseException {
+    @Test
+    public void testAuthenticationCheckedBeforeBody() {
         httpRequest.setAuthorization(null);
-        request = CredentialOfferRequest.parse(httpRequest);
+        httpRequest.setBody("not json");
+        try {
+            CredentialOfferRequest.parse(httpRequest);
+            Assert.fail("Request without client authentication accepted");
+        } catch (final ParseException e) {
+            Assert.assertEquals(e.getErrorObject().getCode(), OAuth2Error.INVALID_CLIENT.getCode());
+        }
     }
 
     @Test(expectedExceptions = ParseException.class)
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java
new file mode 100644
index 0000000..9bca1fb
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/DefaultOpenIDVCICredentialOfferConfigurationTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an “AS IS” BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.profile.config.impl;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/** Tests for {@link DefaultOpenIDVCICredentialOfferConfiguration}. */
+public class DefaultOpenIDVCICredentialOfferConfigurationTest {
+
+    @Test
+    public void testId() {
+        Assert.assertEquals(new DefaultOpenIDVCICredentialOfferConfiguration().getId(),
+                "http://geant.org/ns/profiles/openid/vci/credential-offer");
+    }
+
+    @Test
+    public void testCounter() {
+        Assert.assertEquals(DefaultOpenIDVCICredentialOfferConfiguration.PROFILE_COUNTER,
+                "net.shibboleth.idp.profiles.openid.vci.credential-offer");
+    }
+
+    @Test
+    public void testNoInterceptorFlowsByDefault() {
+        final DefaultOpenIDVCICredentialOfferConfiguration configuration =
+                new DefaultOpenIDVCICredentialOfferConfiguration();
+
+        Assert.assertEquals(configuration.getInboundInterceptorFlows(null), List.of());
+        Assert.assertEquals(configuration.getOutboundInterceptorFlows(null), List.of());
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java
new file mode 100644
index 0000000..f1e83a1
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an “AS IS” BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.profile.impl;
+
+import java.net.URI;
+import java.util.List;
+
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialOfferContext;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferSuccessResponse;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.webflow.execution.Event;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.oauth2.sdk.http.HTTPRequest;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import net.shibboleth.idp.profile.IdPEventIds;
+import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
+import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.shared.primitive.NonnullSupplier;
+
+/**
+ * Unit tests for {@link FormOutboundCredentialOfferResponseMessage}.
+ */
+public class FormOutboundCredentialOfferResponseMessageTest {
+
+    private RequestContext requestCtx;
+
+    private ProfileRequestContext profileRequestCtx;
+
+    private MockHttpServletResponse httpResponse;
+
+    private FormOutboundCredentialOfferResponseMessage action;
+
+    @BeforeMethod
+    protected void setUp() throws Exception {
+        final HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URI("http://example.com"));
+        httpRequest.setAuthorization("Basic dGVzdDp0ZXN0");
+        httpRequest.setContentType("application/json");
+        httpRequest.setBody("{\"preAuthorizedCredentials\":{\"GeantIncubatorSdJwt2\":"
+                + "[{\"path\":[\"mail\"],\"value\":\"incubatorUser at example.org\"}]}}");
+        final CredentialOfferRequest request = CredentialOfferRequest.parse(httpRequest);
+
+        requestCtx = new RequestContextBuilder().buildRequestContext();
+        profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+        profileRequestCtx.setInboundMessageContext(new MessageContext());
+        profileRequestCtx.getInboundMessageContext().setMessage(request);
+        final CredentialOfferContext ctx =
+                profileRequestCtx.getInboundMessageContext().ensureSubcontext(CredentialOfferContext.class);
+        ctx.setValidatedPreAuthorizedCredentials(request.getPreAuthorizedCredentials());
+        ctx.setCredentialOfferToken("code");
+
+        action = new FormOutboundCredentialOfferResponseMessage();
+        action.setIssuerLookupStrategy(prc -> "https://issuer.example.org");
+        action.setHttpServletRequestSupplier(new NonnullSupplier<>() {
+            public HttpServletRequest get() {
+                return new MockHttpServletRequest();
+            }
+        });
+        httpResponse = new MockHttpServletResponse();
+        action.setHttpServletResponseSupplier(new NonnullSupplier<>() {
+            public HttpServletResponse get() {
+                return httpResponse;
+            }
+        });
+    }
+
+    private CredentialOfferSuccessResponse execute() {
+        final Event event = action.execute(requestCtx);
+        ActionTestingSupport.assertProceedEvent(event);
+        return (CredentialOfferSuccessResponse) profileRequestCtx.getOutboundMessageContext().getMessage();
+    }
+
+    @Test
+    public void testOffer() throws Exception {
+        action.initialize();
+        final CredentialOfferSuccessResponse offer = execute();
+
+        Assert.assertEquals(offer.getCredentialIssuer(), "https://issuer.example.org");
+        Assert.assertEquals(offer.getCredentialConfigurationIds(), List.of("GeantIncubatorSdJwt2"));
+    }
+
+    @Test
+    public void testCacheControlOnce() throws Exception {
+        httpResponse.addHeader("Cache-Control", "no-store");
+        action.initialize();
+        execute();
+
+        Assert.assertEquals(httpResponse.getHeaders("Cache-Control").size(), 1);
+        Assert.assertTrue(httpResponse.getHeader("Cache-Control").contains("no-store"));
+        Assert.assertEquals(httpResponse.getHeader("Pragma"), "no-cache");
+    }
+
+    @Test
+    public void testNoCacheControlOnNimbusResponse() throws Exception {
+        action.initialize();
+        final CredentialOfferSuccessResponse offer = execute();
+
+        Assert.assertNull(offer.toHTTPResponse().getCacheControl());
+        Assert.assertNull(offer.toHTTPResponse().getHeaderValue("Pragma"));
+    }
+
+    @Test
+    public void testNoServletResponse() throws Exception {
+        final FormOutboundCredentialOfferResponseMessage noResponse = new FormOutboundCredentialOfferResponseMessage();
+        noResponse.setIssuerLookupStrategy(prc -> "https://issuer.example.org");
+        noResponse.setHttpServletRequestSupplier(new NonnullSupplier<>() {
+            public HttpServletRequest get() {
+                return new MockHttpServletRequest();
+            }
+        });
+        noResponse.initialize();
+
+        ActionTestingSupport.assertEvent(noResponse.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+    }
+
+}

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


More information about the commits mailing list