[java-idp-plugin-vci] branch dev/REVIEWOFFERCALLERFLOW updated: credential offer code building, code length 10 to 128, sealed code cleanup of dummy entries, tests
Codeberg
noreply at shibboleth.net
Mon Nov 16 10:22:12 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/4c7ea479100b2608dd49af442fd3bab5b6ebb2d1
The following commit(s) were added to refs/heads/dev/REVIEWOFFERCALLERFLOW by this push:
new 4c7ea47 credential offer code building, code length 10 to 128, sealed code cleanup of dummy entries, tests
4c7ea47 is described below
commit 4c7ea479100b2608dd49af442fd3bab5b6ebb2d1
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Mon Nov 16 12:21:44 2026 +0200
credential offer code building, code length 10 to 128, sealed code cleanup of dummy entries, tests
---
README.md | 4 +-
.../impl/AbstractOpenIDVCIConfiguration.java | 16 +-
.../profile/impl/BuildCredentialOfferToken.java | 61 +++---
.../plugin/openidvci/conf/openid-vci.properties | 2 +-
...tOpenIDVCICredentialOfferConfigurationTest.java | 27 +++
.../impl/BuildCredentialOfferTokenTest.java | 237 +++++++++++++++++++++
6 files changed, 307 insertions(+), 40 deletions(-)
diff --git a/README.md b/README.md
index cc48206..39a3bbd 100644
--- a/README.md
+++ b/README.md
@@ -4715,7 +4715,7 @@ Endpoint `/idp/profile/openid/vci/credential-offer`, profile ID `http://geant.or
| Name | Type | Default | Description |
|---|---|---|---|
| `preAuthorizedCodeLifetime` | Duration | `PT10M` | Lifetime of the pre-authorized code. Property `openidvci.preAuthorizedCode.defaultLifetime`. |
-| `preAuthorizedCodeLength` | Integer | `0` | `0` seals the whole offer in the code, no storage needed. `10` or more is a short code of an offer in storage. Property `openidvci.preAuthorizedCode.defaultLength`. |
+| `preAuthorizedCodeLength` | Integer | `0` | `0` seals the whole offer in the code, no storage needed. `10` to `128` is a code of that length for an offer in storage. Property `openidvci.preAuthorizedCode.defaultLength`. |
| `tokenEndpointAuthMethods` | Collection<String> | | Client authentication of the caller. |
| `inboundInterceptorFlows` | List<String> | | Interceptor flows run after the request is decoded, before authentication. |
| `outboundInterceptorFlows` | List<String> | | Interceptor flows run before the response is sent, also for an error response. |
@@ -5043,7 +5043,7 @@ The file comes with the plugin and is loaded automatically.
| `openidvci.batchSize` | Integer | `2` | Default of `batchSize`. |
| `openidvci.StorageService` | Bean ID | **shibboleth.StorageService** | Storage of Credential Offers. Server side storage. |
| `openidvci.preAuthorizedCode.defaultLifetime` | Duration | `PT10M` | Lifetime of pre-authorized codes. |
-| `openidvci.preAuthorizedCode.defaultLength` | Integer | `0` | `0` self-contained, `10` or more stored. |
+| `openidvci.preAuthorizedCode.defaultLength` | Integer | `0` | `0` self-contained, `10` to `128` stored. |
| `openidvci.nonce.lifetime` | Duration | `PT5M` | Lifetime of the `c_nonce` of the Nonce endpoint. |
| `openidvci.requestParser.TokenRequest` | Bean ID | | Custom parser of the Token endpoint request, a `CustomNimbusRequestParser` of the OP plugin returning an `OpenIDVCITokenRequest`. |
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java
index 0444e4f..f23ccc3 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/impl/AbstractOpenIDVCIConfiguration.java
@@ -40,6 +40,12 @@ import net.shibboleth.shared.logic.PredicateSupport;
public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConfiguration
implements OpenIDVCIConfiguration {
+ /** Minimum length of a stored pre-authorized code. */
+ public static final int MIN_PRE_AUTHORIZED_CODE_LENGTH = 10;
+
+ /** Maximum length of a stored pre-authorized code. */
+ public static final int MAX_PRE_AUTHORIZED_CODE_LENGTH = 128;
+
/** Lookup function to supply pre-authorized code lifetime. */
@Nonnull
private Function<ProfileRequestContext, Duration> preAuthorizedCodeLifetimeLookupStrategy;
@@ -132,8 +138,9 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
public Integer getPreAuthorizedCodeLength(@Nullable final ProfileRequestContext profileRequestContext) {
final Integer codeLength = preAuthorizedCodeLengthLookupStrategy.apply(profileRequestContext);
- Constraint.isTrue(codeLength != null && (codeLength > 9 || codeLength == 0),
- "Pre-authorized code length must be at least 10 or 0");
+ Constraint.isTrue(codeLength != null && (codeLength == 0
+ || codeLength >= MIN_PRE_AUTHORIZED_CODE_LENGTH && codeLength <= MAX_PRE_AUTHORIZED_CODE_LENGTH),
+ "Pre-authorized code length must be 0 or from 10 to 128");
return codeLength;
}
@@ -144,8 +151,9 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
* @param codeLength length of the pre-authorized code.
*/
public void setPreAuthorizedCodeLength(@Positive @Nonnull final Integer codeLength) {
- Constraint.isTrue(codeLength != null && (codeLength > 9 || codeLength == 0),
- "Pre-authorized code length must be at least 10 or 0");
+ Constraint.isTrue(codeLength != null && (codeLength == 0
+ || codeLength >= MIN_PRE_AUTHORIZED_CODE_LENGTH && codeLength <= MAX_PRE_AUTHORIZED_CODE_LENGTH),
+ "Pre-authorized code length must be 0 or from 10 to 128");
preAuthorizedCodeLengthLookupStrategy = FunctionSupport.constant(codeLength);
}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java
index 098acab..5af4805 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java
@@ -20,7 +20,9 @@ import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.function.Function;
+
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.geant.shibboleth.plugin.openidvci.profile.config.OpenIDVCIConfiguration;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
@@ -36,7 +38,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.nimbusds.oauth2.sdk.Scope;
import com.nimbusds.oauth2.sdk.id.ClientID;
import net.shibboleth.idp.profile.AbstractProfileAction;
@@ -54,16 +55,13 @@ import net.shibboleth.shared.security.IdentifierGenerationStrategy;
import net.shibboleth.shared.security.impl.SecureRandomIdentifierGenerationStrategy;
/**
- * Action that builds credential offer token. Token value is either a key to
- * storage or a serialized {@link CredentialOfferClaimsSet}. Token is stored to
- * {@link CredentialOfferContext} to be returned in the response as the
- * pre-authorized_code.
+ * Action that builds the pre-authorized code of a credential offer and stores it in {@link CredentialOfferContext}.
*/
public class BuildCredentialOfferToken extends AbstractProfileAction {
/** Class logger. */
@Nonnull
- private Logger log = LoggerFactory.getLogger(BuildCredentialOfferToken.class);
+ private final Logger log = LoggerFactory.getLogger(BuildCredentialOfferToken.class);
/**
* Cache for storing credential offers.
@@ -85,20 +83,16 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
/** Length of the pre-authorized code. */
private long preAuthorizedCodeLength;
- /** lifetime of pre-authorized code. */
+ /** Lifetime of the pre-authorized code. */
+ @Nullable
private Duration expiration;
/** Relying party context. */
+ @Nullable
private RelyingPartyContext rpCtx;
- /** Inbound Credential Offer request. */
- @NonnullAfterInit
- private CredentialOfferRequest request;
-
- /**
- * Credential offer context.
- */
- @NonnullAfterInit
+ /** Credential offer context. */
+ @Nullable
private CredentialOfferContext ctx;
/** Data sealer for handling access token. */
@@ -190,6 +184,9 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
/** {@inheritDoc} */
@Override
protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
if (idGeneratorLookupStrategy.apply(profileRequestContext) == null) {
log.error("{} No identifier generation strategy", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
@@ -217,34 +214,34 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
return false;
}
ctx = profileRequestContext.getInboundMessageContext().getSubcontext(CredentialOfferContext.class);
- if (ctx == null) {
+ if (ctx == null || ctx.getValidatedPreAuthorizedCredentials() == null) {
log.error("{} No credential offer context", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
return false;
}
- return super.doPreExecute(profileRequestContext);
+ return true;
}
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ assert rpCtx != null && ctx != null && expiration != null;
final String rpId = rpCtx.getRelyingPartyId();
final CredentialOfferObject credentialRequest = new CredentialOfferObject(new ClientID(rpId),
ctx.getValidatedPreAuthorizedCredentials(), null, ctx.getCredentialOfferTxCode());
- String credentialOfferToken;
+ final String credentialOfferToken;
if (preAuthorizedCodeLength != 0) {
- credentialOfferToken = idGeneratorLookupStrategy.apply(profileRequestContext).generateIdentifier();
- if (credentialOfferToken.length() <= preAuthorizedCodeLength) {
- log.error("{} Generated pre-authorization code length is {}, expected length by profile config is {}+1",
- getLogPrefix(), credentialOfferToken.length(), preAuthorizedCodeLength);
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
- return;
+ final IdentifierGenerationStrategy idGenerator = idGeneratorLookupStrategy.apply(profileRequestContext);
+ assert idGenerator != null;
+ final StringBuilder code = new StringBuilder();
+ while (code.length() < preAuthorizedCodeLength) {
+ code.append(idGenerator.generateIdentifier(false));
}
- credentialOfferToken = credentialOfferToken.substring(1, (int) preAuthorizedCodeLength + 1);
+ credentialOfferToken = code.substring(0, (int) preAuthorizedCodeLength);
try {
- log.info("Storing credential request {} per pre-authorized code {}", credentialRequest.serialize(),
- credentialOfferToken);
+ log.debug("{} Storing credential offer of {} for client {}", getLogPrefix(),
+ ctx.getValidatedPreAuthorizedCredentials().keySet(), rpId);
if (!credentialOfferCache.storeCredentialOffer(credentialRequest, credentialOfferToken,
expiration.toMillis())) {
log.error("{} Failed to set credential offer object to cache.", getLogPrefix());
@@ -252,7 +249,7 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
return;
}
} catch (final IOException e) {
- log.error("{} Failed to set credential offer object to cache {}", getLogPrefix(), e);
+ log.error("{} Failed to set credential offer object to cache", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
return;
}
@@ -262,23 +259,21 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
claimsSet = new CredentialOfferClaimsSet.Builder()
.setIssuer(issuerLookupStrategy.apply(profileRequestContext)).setClientID(new ClientID(rpId))
.setJWTID(idGeneratorLookupStrategy.apply(profileRequestContext)).setIssuedAt(Instant.now())
- .setAuthenticationTime(Instant.now()).setPrincipal("dummy")
- .setSubject(credentialRequest.serialize()).setScope(new Scope("openid"))
+ .setAuthenticationTime(Instant.now()).setSubject(credentialRequest.serialize())
.setExpiresAt(Instant.now().plus(expiration)).build();
} catch (final JsonProcessingException e) {
- log.error("{} Failed to serialize credential offer object to claim set {}", getLogPrefix(), e);
+ log.error("{} Failed to serialize credential offer object to claim set", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
return;
}
try {
credentialOfferToken = claimsSet.serialize(dataSealer);
} catch (final DataSealerException e) {
- log.error("{} Failed to serialize credentil offer claim set {}", getLogPrefix(), e);
+ log.error("{} Failed to serialize credential offer claim set", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
return;
}
}
ctx.setCredentialOfferToken(credentialOfferToken);
-
}
}
\ No newline at end of file
diff --git a/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties b/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties
index 1bd657c..1d8a9e7 100644
--- a/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties
+++ b/openid-vci-impl/src/main/resources/org/geant/shibboleth/plugin/openidvci/conf/openid-vci.properties
@@ -19,7 +19,7 @@ openidvci.issuer =
# Default lifetime of the pre-authorized code
#openidvci.preAuthorizedCode.defaultLifetime = PT10M
-# Size of pre-authorized codes (0 = untruncated)
+# Length of pre-authorized codes (0 = sealed offer, 10 to 128 = offer in storage)
#openidvci.preAuthorizedCode.defaultLength = 0
# Lifetime of the c_nonce of the Nonce endpoint
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
index 9bca1fb..db903e4 100644
--- 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
@@ -19,8 +19,11 @@ package org.geant.shibboleth.plugin.openidvci.profile.config.impl;
import java.util.List;
import org.testng.Assert;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import net.shibboleth.shared.logic.ConstraintViolationException;
+
/** Tests for {@link DefaultOpenIDVCICredentialOfferConfiguration}. */
public class DefaultOpenIDVCICredentialOfferConfigurationTest {
@@ -45,4 +48,28 @@ public class DefaultOpenIDVCICredentialOfferConfigurationTest {
Assert.assertEquals(configuration.getOutboundInterceptorFlows(null), List.of());
}
+ @DataProvider(name = "validCodeLengths")
+ public Object[][] validCodeLengths() {
+ return new Object[][] { { 0 }, { 10 }, { 128 } };
+ }
+
+ @Test(dataProvider = "validCodeLengths")
+ public void testPreAuthorizedCodeLength(final int length) {
+ final DefaultOpenIDVCICredentialOfferConfiguration configuration =
+ new DefaultOpenIDVCICredentialOfferConfiguration();
+ configuration.setPreAuthorizedCodeLength(length);
+
+ Assert.assertEquals(configuration.getPreAuthorizedCodeLength(null), length);
+ }
+
+ @DataProvider(name = "invalidCodeLengths")
+ public Object[][] invalidCodeLengths() {
+ return new Object[][] { { -1 }, { 9 }, { 129 } };
+ }
+
+ @Test(dataProvider = "invalidCodeLengths", expectedExceptions = ConstraintViolationException.class)
+ public void testInvalidPreAuthorizedCodeLength(final int length) {
+ new DefaultOpenIDVCICredentialOfferConfiguration().setPreAuthorizedCodeLength(length);
+ }
+
}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
new file mode 100644
index 0000000..53519c4
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
@@ -0,0 +1,237 @@
+/*
+ * 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.io.IOException;
+import java.net.URI;
+import java.time.Duration;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialOfferContext;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
+import org.geant.shibboleth.plugin.openidvci.profile.config.impl.DefaultOpenIDVCICredentialOfferConfiguration;
+import org.geant.shibboleth.plugin.openidvci.storage.CredentialOfferCache;
+import org.geant.shibboleth.plugin.openidvci.storage.CredentialOfferObject;
+import org.geant.shibboleth.plugin.openidvci.token.support.CredentialOfferClaimsSet;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.storage.impl.MemoryStorageService;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.oauth2.sdk.http.HTTPRequest;
+
+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.profile.context.RelyingPartyContext;
+import net.shibboleth.shared.collection.Pair;
+import net.shibboleth.shared.security.DataSealer;
+import net.shibboleth.shared.security.DataSealerKeyStrategy;
+
+/**
+ * Unit tests for {@link BuildCredentialOfferToken}.
+ */
+public class BuildCredentialOfferTokenTest {
+
+ private RequestContext requestCtx;
+
+ private ProfileRequestContext profileRequestCtx;
+
+ private DefaultOpenIDVCICredentialOfferConfiguration configuration;
+
+ private MemoryStorageService storageService;
+
+ private CredentialOfferCache cache;
+
+ private DataSealer sealer;
+
+ private BuildCredentialOfferToken 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);
+ profileRequestCtx.getInboundMessageContext().ensureSubcontext(CredentialOfferContext.class)
+ .setValidatedPreAuthorizedCredentials(request.getPreAuthorizedCredentials());
+ configuration = new DefaultOpenIDVCICredentialOfferConfiguration();
+ configuration.setPreAuthorizedCodeLifetime(Duration.ofMinutes(10));
+ final RelyingPartyContext rpCtx = profileRequestCtx.ensureSubcontext(RelyingPartyContext.class);
+ rpCtx.setRelyingPartyId("offer-caller");
+ rpCtx.setProfileConfig(configuration);
+
+ storageService = new MemoryStorageService();
+ storageService.setId("test");
+ storageService.initialize();
+ cache = new CredentialOfferCache();
+ cache.setStorage(storageService);
+ cache.initialize();
+
+ final KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
+ keyGenerator.init(128);
+ sealer = new DataSealer();
+ sealer.setKeyStrategy(new FixedKeyStrategy(keyGenerator.generateKey()));
+ sealer.initialize();
+
+ action = new BuildCredentialOfferToken(sealer);
+ action.setCredentialOfferCache(cache);
+ action.setIssuerLookupStrategy(prc -> "https://issuer.example.org");
+ }
+
+ @AfterMethod
+ protected void tearDown() {
+ cache.destroy();
+ storageService.destroy();
+ sealer.destroy();
+ }
+
+ private String getCode() {
+ return profileRequestCtx.getInboundMessageContext().getSubcontext(CredentialOfferContext.class)
+ .getCredentialOfferToken();
+ }
+
+ @Test
+ public void testStoredCode() throws Exception {
+ configuration.setPreAuthorizedCodeLength(10);
+ action.initialize();
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+ final String code = getCode();
+ Assert.assertEquals(code.length(), 10);
+ final CredentialOfferObject offer = cache.getCredentialOffer(code);
+ Assert.assertNotNull(offer);
+ Assert.assertEquals(offer.getClientID().getValue(), "offer-caller");
+ Assert.assertTrue(offer.getPreAuthorizedCredentials().containsKey("GeantIncubatorSdJwt2"));
+ }
+
+ @Test
+ public void testStoredCodeMaxLength() throws Exception {
+ configuration.setPreAuthorizedCodeLength(128);
+ action.initialize();
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+ final String code = getCode();
+ Assert.assertEquals(code.length(), 128);
+ Assert.assertFalse(code.contains("_"));
+ Assert.assertNotNull(cache.getCredentialOffer(code));
+ }
+
+ @Test
+ public void testSealedCode() throws Exception {
+ configuration.setPreAuthorizedCodeLength(0);
+ action.initialize();
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+ final CredentialOfferClaimsSet claimsSet = CredentialOfferClaimsSet.parse(getCode(), sealer);
+ Assert.assertEquals(claimsSet.getClientID().getValue(), "offer-caller");
+ Assert.assertEquals(claimsSet.getClaimsSet().getIssuer(), "https://issuer.example.org");
+ Assert.assertNull(claimsSet.getPrincipal());
+ Assert.assertNull(claimsSet.getScope());
+ final CredentialOfferObject offer = CredentialOfferObject.parse(claimsSet.getSubject());
+ Assert.assertTrue(offer.getPreAuthorizedCredentials().containsKey("GeantIncubatorSdJwt2"));
+ }
+
+ @Test
+ public void testStorageFailure() throws Exception {
+ configuration.setPreAuthorizedCodeLength(10);
+ action.setCredentialOfferCache(new FailingCache());
+ action.initialize();
+
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.IO_ERROR);
+ }
+
+ @Test
+ public void testNoCredentialOfferContext() throws Exception {
+ profileRequestCtx.getInboundMessageContext().removeSubcontext(CredentialOfferContext.class);
+ action.initialize();
+
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+ }
+
+ @Test
+ public void testNoValidatedCredentials() throws Exception {
+ profileRequestCtx.getInboundMessageContext().addSubcontext(new CredentialOfferContext(), true);
+ action.initialize();
+
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+ }
+
+ @Test
+ public void testNoRelyingPartyContext() throws Exception {
+ profileRequestCtx.removeSubcontext(RelyingPartyContext.class);
+ action.initialize();
+
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_RELYING_PARTY_CTX);
+ }
+
+ /** Cache that fails to store. */
+ private static class FailingCache extends CredentialOfferCache {
+
+ /** {@inheritDoc} */
+ @Override
+ public synchronized boolean storeCredentialOffer(final CredentialOfferObject object, final String code,
+ final long expiration) throws IOException {
+ throw new IOException("Storage failure");
+ }
+ }
+
+ /** Key strategy of one fixed key. */
+ private static class FixedKeyStrategy implements DataSealerKeyStrategy {
+
+ private final SecretKey key;
+
+ FixedKeyStrategy(final SecretKey secretKey) {
+ key = secretKey;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @SuppressWarnings("removal")
+ public Pair<String, SecretKey> getDefaultKey() {
+ return new Pair<>("default", key);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public NamedKey getDefaultKeyRecord() {
+ return new NamedKey("default", key);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public SecretKey getKey(final String name) {
+ return key;
+ }
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list