[java-idp-plugin-vci] 01/01: Credential validity window can now be set in pre-auth offer call and by replaceable lifetime strategies
Codeberg
noreply at shibboleth.net
Mon Nov 23 08:24:29 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch dev/PREAUTHCONF
in repository java-idp-plugin-vci.
View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-vci/commit/7298a01c16307f7d73d3e15270ee3e0a41ed119e
commit 7298a01c16307f7d73d3e15270ee3e0a41ed119e
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Mon Nov 23 10:23:32 2026 +0200
Credential validity window can now be set in pre-auth offer call and by replaceable lifetime strategies
---
README.md | 82 ++++++--
.../CredentialIssuanceConfiguration.java | 44 +---
.../openidvci/profile/OpenIDVCIEventIds.java | 14 ++
.../profile/config/OpenIDVCIConfiguration.java | 47 +++--
.../CredentialIssuanceConfigurationTest.java | 25 +--
.../impl/CredentialOfferRequestDecoder.java | 2 +
.../messaging/context/CredentialOfferContext.java | 48 +++++
.../messaging/context/CredentialsContext.java | 52 ++++-
.../messaging/impl/CredentialOfferRequest.java | 90 +++++++-
.../impl/AbstractOpenIDVCIConfiguration.java | 96 ++++++---
.../profile/impl/BuildCredentialOfferToken.java | 3 +-
.../profile/impl/ResolveCredentialLifetime.java | 94 ++++-----
.../impl/ValidateCredentialOfferValidity.java | 234 +++++++++++++++++++++
.../profile/impl/ValidateCredentialOffering.java | 2 +
.../profile/impl/ValidateRequestedCredential.java | 34 +++
.../logic/CredentialLifetimeLookupFunction.java | 76 +++++++
.../CredentialValidityStartLookupFunction.java | 57 +++++
.../logic/OpenIDVCITokenManipulationStrategy.java | 34 +++
.../openidvci/storage/CredentialOfferObject.java | 108 +++++++++-
.../META-INF/net.shibboleth.idp/postconfig.xml | 10 +-
.../credential-offer/credential-offer-beans.xml | 5 +
.../vci/credential-offer/credential-offer-flow.xml | 1 +
.../openid/vci/credentials/credentials-beans.xml | 6 +-
.../idp/service/relying-party/postconfig.xml | 4 +-
.../plugin/openidvci/conf/openid-vci.properties | 31 ++-
.../messaging/impl/CredentialOfferRequestTest.java | 41 ++++
.../impl/ResolveCredentialLifetimeTest.java | 72 +++++--
.../impl/ValidateCredentialOfferValidityTest.java | 183 ++++++++++++++++
.../impl/ValidateRequestedCredentialTest.java | 32 +++
.../CredentialLifetimeLookupFunctionTest.java | 81 +++++++
.../CredentialValidityStartLookupFunctionTest.java | 73 +++++++
.../OpenIDVCITokenManipulationStrategyTest.java | 26 +++
.../storage/CredentialOfferObjectTest.java | 14 ++
33 files changed, 1506 insertions(+), 215 deletions(-)
diff --git a/README.md b/README.md
index 711cb0c..58e8437 100644
--- a/README.md
+++ b/README.md
@@ -536,11 +536,11 @@ It goes inside the credential's own configuration, next to `format` and `vct`:
| Member | Type | Default | Description |
|---|---|---|---|
-| `lifetime` | Duration | `credentialLifetime` of the profile configuration, `P180D` | Length of the validity window. |
+| `lifetime` | Duration | `openidvci.credentialLifetime`, `P180D` | Length of the validity window. |
| `not_before` | Duration, moment or date | The instant of issuance | Where the validity window opens. |
| `status_list` | Boolean | `openidvci.status-list.includeByDefault`, `true` | Whether the credential takes a Status List slot. |
| `issuer` | String | `openidvci.issuer` | What the credential says issued it. `did:jwk`, `did:web` or `url`. See [Step 2](#step-2-add-a-did-web-credential) and [Step 3](#step-3-add-a-plain-url-credential). |
-| `oidfed` | Boolean | `true` | Whether the credential states the Entity Identifier of this deployment, once the deployment is in OpenID Federation. See [Step 4](#step-4-make-the-url-credential-an-openid-federation-credential). |
+| `oidfed` | Boolean | `true` | Whether the credential carries the Entity Identifier of this deployment, once the deployment is in OpenID Federation. See [Step 4](#step-4-make-the-url-credential-an-openid-federation-credential). |
| `claim_types` | Array | | Type of a claim value in an mdoc where JSON has none, a date for example, `{"path": [...], "type": ...}`. See [The mdoc credential](#the-mdoc-credential) and [Complex claims](#complex-claims). |
| `sd` | Array | | Arrays disclosed element by element as in [Disclosures for Array Elements](https://datatracker.ietf.org/doc/draft-ietf-oauth-selective-disclosure-jwt/) of SD-JWT, `{"path": [..., null], "sd": "always"}`. See [Complex claims](#complex-claims). |
@@ -576,9 +576,6 @@ issuance timestamp is rounded down to the start of the hour. To use a different
openidvci.credentialTimestampPrecision = PT15M
```
-Use a precision shorter than the shortest `lifetime` you issue. Otherwise, the
-validity window may end before the credential is issued, and issuance will fail.
-
##### Whether a credential goes on a Status List
`"status_list": false` keeps the credential off the list. It carries no `status` claim and it
@@ -588,11 +585,40 @@ A credential with no explicit setting is added to the list. Set
`openidvci.status-list.includeByDefault` to `false` in *conf/openid-vci.properties*. Then only a
credential with `"status_list": true` goes on the list.
-##### Which setting wins
+##### Setting the validity window at run time
+
+A credential without `lifetime` is valid for `openidvci.credentialLifetime`, `P180D` by default.
+
+To decide the window at run time, define a `Function<ProfileRequestContext,Duration>` bean for
+the lifetime or a `Function<ProfileRequestContext,ValidityStart>` bean for the start, and set its
+bean ID as `openidvci.credentialLifetime.strategy` or `openidvci.credentialValidityStart.strategy`
+in *conf/openid-vci.properties*.
+
+##### Validity window from a Credential Offer
+
+In the pre-authorized code flow the offer caller can set `lifetime` and `not_before` in the offer
+request, next to `txCode`, written as above. They apply to every credential of the offer and
+override `lifetime` and `not_before` of the credential configuration.
+
+```json
+{
+ "preAuthorizedCredentials": {
+ "EventTicket": [ { "path": ["event"], "value": "Conference 2026" } ]
+ },
+ "lifetime": "P3D",
+ "not_before": "2026-09-14T08:00Z"
+}
+```
+
+To enable this you have to set `allowValidityWindow` to `true` in its **OpenID.VCI.CredentialOffer**.
+`maxCredentialLifetime` caps the `lifetime` it sets:
-`lifetime` here overrides `credentialLifetime` of the profile configuration, including a
-`credentialLifetime` you set on one wallet in *conf/relying-party.xml*. Leave `lifetime` out of
-a credential whose validity you want to keep steering for each wallet.
+```xml
+<bean parent="OpenID.VCI.CredentialOffer"
+ p:tokenEndpointAuthMethods="#{{'client_secret_basic'}}"
+ p:allowValidityWindow="true"
+ p:maxCredentialLifetime="P365D" />
+```
#### Metadata endpoints
@@ -1196,7 +1222,7 @@ This is the same structure used by the Credential Offer API. Define the attribut
</details>
-One attribute serves both credentials. Each `AttributeEncoder` in the definition creates a claim named after the encoder. This means the
+One attribute serves both credentials. Each `AttributeEncoder` in the definition creates a claim with the name of the encoder. This means the
wallet can retrieve the same claim list using either configuration ID, and you only need to write
the script once. The encoder names are credential configuration IDs.
`idp.oidc.encodedAttributes` and the filter policy use the attribute id.
@@ -1280,7 +1306,7 @@ The `uri` and the `sub` of the Status List Token are formed from the scheme and
To revoke this credential, set bit 41337 in the `2027-03` list. The list a credential belongs to
is determined by the month it **expires**, not the month it was issued. With the
-default `credentialLifetime` of `P180D` a credential that is issued in mid-September 2026 belongs to
+default lifetime of `P180D` a credential that is issued in mid-September 2026 belongs to
the list of March 2027.
The part after `~` tells under which issuer ID the credential was issued. The plugin
@@ -1491,7 +1517,7 @@ Next, add a credential whose issuer is the `did:web` identifier of this deployme
What’s new:
-- the credential states `"issuer": "did:web"` in its `_issuance_configuration`
+- the credential has `"issuer": "did:web"` in its `_issuance_configuration`
- the did:web document is published at `/.well-known/did.json`
- the credential header `kid` is a DID URL, `did:web:issuer.example.org#<kid of the key>`
- the Status List url of the credential ends with `~did-web`
@@ -1640,8 +1666,8 @@ Full file: [metadata/verifiable-credentials.json](docs/example/step-2/metadata/v
</details>
Setting `openidvci.issuer = did:web` in *conf/openid-vci.properties* would do the same for every
-credential that states no `issuer` of its own. Here we keep the deployment default as did:jwk
-and state it per credential.
+credential that has no `issuer` of its own. Here we keep the deployment default as did:jwk
+and set it per credential.
<details>
<summary>conf/relying-party.xml</summary>
@@ -2009,7 +2035,7 @@ the OP’s keyset.
What’s new:
-- the credential states `"issuer": "url"`
+- the credential has `"issuer": "url"`
- JWT VC issuer metadata is published at `/.well-known/jwt-vc-issuer`
- the credential header `kid` is the plain name of the key, as in the keyset of the OP
- the Status List URL of the credential ends with `~url`
@@ -4371,7 +4397,7 @@ always disclosed.
}
```
-For a `vc+sd-jwt` credential the path starts with `credentialSubject`. An array not named in `sd`
+For a `vc+sd-jwt` credential the path starts with `credentialSubject`. An array not listed in `sd`
is one value, as in [Disclosures for Object Properties](https://datatracker.ietf.org/doc/draft-ietf-oauth-selective-disclosure-jwt/).
You give an array always as one value, the path has no `null` and no index.
@@ -4567,7 +4593,7 @@ The lifetimes and rotation are the OP settings of **OpenID.VCI.Token**:
For the authorization code and refresh token grants the token endpoint resolves the user's
attributes again and filters them with the wallet as the requester, as the OP token endpoint does.
-A released attribute whose OIDC encoder is named by a credential configuration ID becomes a
+A released attribute whose OIDC encoder has a credential configuration ID as its name becomes a
credential of the grant, next to the ones carried in the authorization code or refresh token. The
scope and `authorization_details` of the grant then limit them as in
[Authorization code flow](#authorization-code-flow).
@@ -4695,6 +4721,8 @@ Endpoint `/idp/profile/openid/vci/credential-offer`, profile ID `http://geant.or
| `preAuthorizedCodeLength` | Integer | `0` | `0` seals the whole offer by data sealer, no storage needed. Use `32` to `128` if you want storage based
shorter code. Property `openidvci.preAuthorizedCode.defaultLength`. |
| `tokenEndpointAuthMethods` | Collection<String> | | Client authentication of the caller. Use `client_secret_basic`. |
+| `allowValidityWindow` | Boolean | `false` | Whether the caller may set `lifetime` and `not_before` in the offer request. See [Validity window from a Credential Offer](#validity-window-from-a-credential-offer). Property `openidvci.credentialOffer.allowValidityWindow`. |
+| `maxCredentialLifetime` | Duration | | Longest `lifetime` the caller may set. No limit if unset. Property `openidvci.credentialOffer.maxCredentialLifetime`. |
| `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. |
| `messageHandler` | Function<MessageContext,Exception> | | Of the OP plugin. Runs on the inbound message before authentication and on the outbound one before encoding. |
@@ -4705,6 +4733,10 @@ 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. |
+| `lifetime` | Duration | Length of the validity window of the credentials offered. See [Validity window from a Credential Offer](#validity-window-from-a-credential-offer). |
+| `not_before` | Duration, moment or date | Start of the validity window of the credentials offered. |
+
+A request with any other member is refused with `400 invalid_request`.
Response is the Credential Offer as an `openid-credential-offer://` deep link, a `text/plain` body.
Its `credential_issuer` is the one of the Credential Issuer metadata. An offer of a
@@ -4738,7 +4770,6 @@ Endpoint `/idp/profile/openid/vci/credentials`, profile ID `http://geant.org/ns/
| Name | Type | Default | Description |
|---|---|---|---|
-| `credentialLifetime` | Duration | `P180D` | Validity of a credential. Decides also the Status List. Not read for a credential stating `lifetime`. |
| `credentialSignatureSigningConfiguration` | SignatureSigningConfiguration | **openidvci.SigningConfiguration** | Signing of credentials. |
| `proofSignatureValidationConfiguration` | SignatureValidationConfiguration | **openidvci.ProofSignatureValidationConfiguration** | Validation of key proof signatures. |
| `proofClaimsValidator` | ClaimsValidator | **openidvci.DefaultProofBodyClaimsValidator** | Validation of key proof claims. |
@@ -4910,11 +4941,11 @@ The `_issuance_configuration` member of a credential configuration. It is not pu
| Name | Type | Default | Description |
|---|---|---|---|
-| `lifetime` | Duration | `credentialLifetime` | Length of the validity window. Overrides `credentialLifetime`. |
+| `lifetime` | Duration | `openidvci.credentialLifetime` | Length of the validity window. |
| `not_before` | Duration, moment or date | instant of issuance | Where the validity window opens. `P30D`, `2026-08-01T06:00Z`, `2026-08-01T00:00+03:00` or `2026-08-01`. |
| `status_list` | Boolean | `openidvci.status-list.includeByDefault` | Whether the credential takes a Status List slot. |
| `issuer` | String | `openidvci.issuer` | `did:jwk`, `did:web`, `url` or the identifier itself. |
-| `oidfed` | Boolean | `true` | Whether the credential states the Entity Identifier, when *conf/openid-vci-oidfed.xml* is imported. |
+| `oidfed` | Boolean | `true` | Whether the credential carries the Entity Identifier, when *conf/openid-vci-oidfed.xml* is imported. |
| `claim_types` | Array | | `{"path": [...], "type": ...}` per claim of an mdoc. `full-date`, `tdate`, `bstr`, `int` or `bool`. The path is a Claims Path Pointer, `null` for every element of an array, see [Complex claims](#complex-claims). |
| `sd` | Array | | `{"path": [..., null], "sd": "always"}` per array of a `dc+sd-jwt` or `vc+sd-jwt` credential that is disclosed as in [Disclosures for Array Elements](https://datatracker.ietf.org/doc/draft-ietf-oauth-selective-disclosure-jwt/) of SD-JWT. For `vc+sd-jwt` the path starts with `credentialSubject`. See [Complex claims](#complex-claims). |
@@ -4929,7 +4960,7 @@ The following members of a `vc+sd-jwt` credential are defined by [W3C VCDM 2.0](
| [`name`](https://www.w3.org/TR/vc-data-model-2.0/#names-and-descriptions) | You | Optional | Name of the credential. |
| [`description`](https://www.w3.org/TR/vc-data-model-2.0/#names-and-descriptions) | You | Optional | Description of the credential. |
| [`credentialSchema`](https://www.w3.org/TR/vc-data-model-2.0/#data-schemas) | You | Optional | Schema of the credential. |
-| [`termsOfUse`](https://www.w3.org/TR/vc-data-model-2.0/#terms-of-use) | You and the plugin | Optional | Terms of use. The plugin adds an `OpenIDFederation` entry when the credential states the Entity Identifier. When both are there, the credential has one array, the plugin's entry first. |
+| [`termsOfUse`](https://www.w3.org/TR/vc-data-model-2.0/#terms-of-use) | You and the plugin | Optional | Terms of use. The plugin adds an `OpenIDFederation` entry when the credential carries the Entity Identifier. When both are there, the credential has one array, the plugin's entry first. |
| [`relatedResource`](https://www.w3.org/TR/vc-data-model-2.0/#integrity-of-related-resources) | You | Optional | Integrity information of resources the credential refers to. |
| [`evidence`](https://www.w3.org/TR/vc-data-model-2.0/#evidence) | You | Optional | Evidence supporting the claims. It is the same for every credential issued with this configuration. |
| [`id`](https://www.w3.org/TR/vc-data-model-2.0/#identifiers) | The plugin | Not read | `urn:uuid:` and a random UUID, per credential. |
@@ -5025,10 +5056,15 @@ The file comes with the plugin and is loaded automatically.
| `idp.authn.OpenIDVCIClient.subjectDecorator` | Bean ID | | Decorator of the Subject of the `OpenIDVCIClient` login flow. |
| `idp.authn.OpenIDVCIClient.supportedPrincipals` | Comma-separated | | Principals the `OpenIDVCIClient` login flow supports. |
| `openidvci.credentialTimestampPrecision` | Duration | `PT1H` | Instant of issuance is rounded down to this. Keep it shorter than the shortest lifetime. |
+| `openidvci.credentialLifetime` | Duration | `P180D` | Default validity of a credential if not set in credential offer request or in credential configuration. |
+| `openidvci.credentialLifetime.strategy` | Bean ID | **openidvci.DefaultCredentialLifetimeLookupStrategy** | Function supplying the lifetime of a credential. |
+| `openidvci.credentialValidityStart.strategy` | Bean ID | **openidvci.DefaultCredentialValidityStartLookupStrategy** | Function supplying the start of the validity window of a credential. |
| `openidvci.batchSize` | Integer | `2` | Default of `batchSize`. |
| `openidvci.StorageService` | Bean ID | **shibboleth.StorageService** | Storage of Credential Offers, used only when `openidvci.preAuthorizedCode.defaultLength` is not `0`. Server side storage. |
| `openidvci.preAuthorizedCode.defaultLifetime` | Duration | `PT10M` | Lifetime of pre-authorized codes. |
| `openidvci.preAuthorizedCode.defaultLength` | Integer | `0` | `0` self-contained, `32` to `128` stored. |
+| `openidvci.credentialOffer.allowValidityWindow` | Boolean | `false` | Default of `allowValidityWindow`. |
+| `openidvci.credentialOffer.maxCredentialLifetime` | Duration | | Default of `maxCredentialLifetime`. Empty for no limit. |
| `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`. |
@@ -5081,7 +5117,7 @@ The other settings of the `OpenIDVCIClient` login flow are the `idp.authn.OAuth2
| Name | Type | Default | Function |
|---|---|---|---|
| `openidvci.status-list.index.permutationKey` | String | `change_this_to_secret` | Key of the slot permutation. **Must be changed** before issuing, and not changed after. Move it to *credentials/secrets.properties*. |
-| `openidvci.status-list.includeByDefault` | Boolean | `true` | Whether a credential stating no `status_list` takes a slot. |
+| `openidvci.status-list.includeByDefault` | Boolean | `true` | Whether a credential takes a slot if its configuration has no `status_list`. |
| `openidvci.status-list.token.defaultLifetime` | Duration | `PT1H` | How long a verifier may cache a Status List Token. The `ttl` claim and the `max-age` of `Cache-Control`. |
| `openidvci.status-list.assignment.retention` | Duration | `P7D` | How long an assignment record is kept after it was written. |
| `openidvci.status-list.StorageService` | Bean ID | **shibboleth.StorageService** | Storage of the lists. Server side storage. |
@@ -5142,7 +5178,7 @@ example, if the issuer is `https://issuer.example.org/tenant`, the metadata is a
`/.well-known/jwt-vc-issuer/tenant`. The rewrite pattern must include the same path.
The authorization server metadata URL includes the same path. In this example, it is
`/.well-known/oauth-authorization-server/tenant`.
-The JWT VC issuer metadata names one issuer. A credential whose issuer is a URL other than `idp.oidc.issuer` must be verified using `x5c`.
+The JWT VC issuer metadata has one issuer. A credential whose issuer is a URL other than `idp.oidc.issuer` must be verified using `x5c`.
Otherwise, change the `issuer` value in the template to match that URL.
The plugin adds `credential_configurations_supported` from *metadata/verifiable-credentials.json*.
The Credential Issuer metadata endpoint returns `500 server_error` if any of the following
diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfiguration.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfiguration.java
index 1479f0e..864737f 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfiguration.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfiguration.java
@@ -54,7 +54,8 @@ public final class CredentialIssuanceConfiguration {
private final Boolean statusList;
/**
- * Whether credentials of this configuration are stated in OpenID Federation.
+ * Whether credentials of this configuration carry the Entity Identifier of
+ * this deployment in OpenID Federation.
*/
@Nullable
private final Boolean oidFederation;
@@ -81,8 +82,8 @@ public final class CredentialIssuanceConfiguration {
* or an instant
* @param inStatusList whether credentials of this configuration take a
* Status List slot
- * @param inOIDFederation whether credentials of this configuration are
- * stated in OpenID Federation
+ * @param inOIDFederation whether credentials of this configuration carry
+ * the Entity Identifier in OpenID Federation
* @param issuerIdentifier Credential Issuer identifier credentials of this
* configuration carry, one of 'did:jwk', 'did:web'
* and 'url', overriding the one of the deployment
@@ -138,10 +139,10 @@ public final class CredentialIssuanceConfiguration {
}
/**
- * Get whether credentials of this configuration are stated in OpenID
- * Federation, carrying the Entity Identifier of this deployment.
+ * Get whether credentials of this configuration carry the Entity Identifier
+ * of this deployment in OpenID Federation.
*
- * @return the flag, or null when the configuration states none
+ * @return the flag, or null when the configuration has none
*/
@Nullable
public Boolean getOIDFederation() {
@@ -161,7 +162,7 @@ public final class CredentialIssuanceConfiguration {
/**
* Get the types of claim values in an mdoc.
*
- * @return types of claim values, empty when the configuration states none
+ * @return types of claim values, empty when the configuration has none
*/
@Nonnull
public List<ClaimType> getClaimTypes() {
@@ -170,38 +171,13 @@ public final class CredentialIssuanceConfiguration {
/**
* Get the selective disclosure of claims in an SD-JWT.
- * @return selective disclosure of claims, empty when the configuration states none
+ * @return selective disclosure of claims, empty when the configuration has none
*/
@Nonnull
public List<ClaimDisclosure> getClaimDisclosures() {
return claimDisclosures;
}
- /**
- * Resolve the instant the validity window of a credential opens.
- *
- * @param issuedAt instant the credential is issued at
- * @return instant the validity window opens, the instant of issuance when no
- * start is configured
- */
- @Nonnull
- public Instant resolveNotBefore(@Nonnull final Instant issuedAt) {
- return notBefore == null ? issuedAt : notBefore.resolve(issuedAt);
- }
-
- /**
- * Resolve the instant the validity window of a credential closes.
- *
- * @param issuedAt instant the credential is issued at
- * @param defaultLifetime length of the window when this configuration states
- * none of its own
- * @return instant the validity window closes
- */
- @Nonnull
- public Instant resolveExpiration(@Nonnull final Instant issuedAt, @Nonnull final Duration defaultLifetime) {
- return resolveNotBefore(issuedAt).plus(lifetime == null ? defaultLifetime : lifetime);
- }
-
/**
* Whether the validity window of this configuration is fixed on the calendar,
* so that it does not move with the instant of issuance.
@@ -238,7 +214,7 @@ public final class CredentialIssuanceConfiguration {
* @throws IllegalArgumentException if the value is not a positive duration
*/
@Nullable
- private static Duration parseLifetime(@Nullable final String value) {
+ public static Duration parseLifetime(@Nullable final String value) {
if (value == null || value.trim().isEmpty()) {
return null;
diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/OpenIDVCIEventIds.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/OpenIDVCIEventIds.java
index 828094d..e7670b7 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/OpenIDVCIEventIds.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/OpenIDVCIEventIds.java
@@ -78,6 +78,20 @@ public final class OpenIDVCIEventIds {
@NotEmpty
public static final String INVALID_CREDENTIAL = "InvalidCredential";
+ /**
+ * ID of event returned if the validity window of the requested credential has closed.
+ */
+ @Nonnull
+ @NotEmpty
+ public static final String VALIDITY_WINDOW_CLOSED = "ValidityWindowClosed";
+
+ /**
+ * ID of event returned if the validity window in a Credential Offer is not accepted.
+ */
+ @Nonnull
+ @NotEmpty
+ public static final String INVALID_VALIDITY_WINDOW = "InvalidValidityWindow";
+
/**
* ID of event returned if there proof type is not supported.
*/
diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java
index 55a3546..fb2be01 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/config/OpenIDVCIConfiguration.java
@@ -118,22 +118,6 @@ public interface OpenIDVCIConfiguration extends ConditionalProfileConfiguration
@Nonnull
Duration getPreAuthorizedCodeLifetime(@Nullable final ProfileRequestContext profileRequestContext);
- /**
- * Get credential lifetime.
- *
- * <p>
- * Defaults to 180 days.
- * </p>
- *
- * @param profileRequestContext profile request context
- *
- * @return credential lifetime
- */
- @ConfigurationSetting(name = "credentialLifetime")
- @Positive
- @Nonnull
- Duration getCredentialLifetime(@Nullable final ProfileRequestContext profileRequestContext);
-
/**
* Get the {@link SignatureValidationConfiguration} to be used for Credential
* Proof JWT signature validation.
@@ -203,7 +187,7 @@ public interface OpenIDVCIConfiguration extends ConditionalProfileConfiguration
@Nullable final ProfileRequestContext profileRequestContext);
/**
- * Get whether a Credential Request may name a credential configuration id when credential identifiers were
+ * Get whether a Credential Request may use a credential configuration id when credential identifiers were
* issued.
*
* <p>
@@ -218,4 +202,33 @@ public interface OpenIDVCIConfiguration extends ConditionalProfileConfiguration
boolean isAllowCredentialConfigurationIdWithIdentifiers(
@Nullable final ProfileRequestContext profileRequestContext);
+ /**
+ * Get whether a Credential Offer may set the validity window of its credentials.
+ *
+ * <p>
+ * Defaults to false.
+ * </p>
+ *
+ * @param profileRequestContext profile request context
+ *
+ * @return whether a Credential Offer may set the validity window of its credentials
+ */
+ @ConfigurationSetting(name = "allowValidityWindow")
+ boolean isAllowValidityWindow(@Nullable final ProfileRequestContext profileRequestContext);
+
+ /**
+ * Get the longest lifetime a Credential Offer may set for its credentials.
+ *
+ * <p>
+ * Defaults to none.
+ * </p>
+ *
+ * @param profileRequestContext profile request context
+ *
+ * @return the longest lifetime, or null for no limit
+ */
+ @ConfigurationSetting(name = "maxCredentialLifetime")
+ @Nullable
+ Duration getMaxCredentialLifetime(@Nullable final ProfileRequestContext profileRequestContext);
+
}
diff --git a/openid-vci-api/src/test/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfigurationTest.java b/openid-vci-api/src/test/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfigurationTest.java
index 200934a..0402387 100644
--- a/openid-vci-api/src/test/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfigurationTest.java
+++ b/openid-vci-api/src/test/java/org/geant/shibboleth/plugin/openidvci/credential/CredentialIssuanceConfigurationTest.java
@@ -32,10 +32,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
*/
public class CredentialIssuanceConfigurationTest {
- private static final Instant ISSUED_AT = Instant.parse("2026-10-15T09:30:00Z");
-
- private static final Duration PROFILE_LIFETIME = Duration.ofDays(180);
-
private String withSettings(final String settings) {
return "{\"format\":\"dc+sd-jwt\",\"vct\":\"Diploma\",\"_issuance_configuration\":" + settings + "}";
}
@@ -57,10 +53,6 @@ public class CredentialIssuanceConfigurationTest {
Assert.assertEquals(settings.getLifetime(), Duration.ofDays(365));
Assert.assertFalse(settings.isFixedWindow());
Assert.assertNull(settings.getFixedExpiration());
-
- Assert.assertEquals(settings.resolveNotBefore(ISSUED_AT), Instant.parse("2026-11-14T09:30:00Z"));
- Assert.assertEquals(settings.resolveExpiration(ISSUED_AT, PROFILE_LIFETIME),
- Instant.parse("2027-11-14T09:30:00Z"));
}
@Test
@@ -72,13 +64,6 @@ public class CredentialIssuanceConfigurationTest {
Assert.assertTrue(settings.isFixedWindow());
Assert.assertEquals(settings.getFixedExpiration(), Instant.parse("2027-08-01T00:00:00Z"));
-
- Assert.assertEquals(settings.resolveNotBefore(ISSUED_AT), Instant.parse("2026-08-01T00:00:00Z"));
- Assert.assertEquals(settings.resolveExpiration(ISSUED_AT, PROFILE_LIFETIME),
- Instant.parse("2027-08-01T00:00:00Z"));
-
- Assert.assertEquals(settings.resolveExpiration(Instant.parse("2026-08-02T12:00:00Z"), PROFILE_LIFETIME),
- settings.resolveExpiration(Instant.parse("2027-01-07T08:00:00Z"), PROFILE_LIFETIME));
}
@Test
@@ -90,22 +75,18 @@ public class CredentialIssuanceConfigurationTest {
Assert.assertEquals(settings.getLifetime(), Duration.ofDays(7));
Assert.assertNull(settings.getNotBefore());
Assert.assertFalse(settings.isFixedWindow());
-
- Assert.assertEquals(settings.resolveNotBefore(ISSUED_AT), ISSUED_AT);
- Assert.assertEquals(settings.resolveExpiration(ISSUED_AT, PROFILE_LIFETIME),
- Instant.parse("2026-10-22T09:30:00Z"));
}
@Test
- public void notBeforeOnlyFallsBackToTheProfileLifetime() throws JsonProcessingException {
+ public void notBeforeOnly() throws JsonProcessingException {
final CredentialIssuanceConfiguration settings = CredentialConfiguration
.parse(withSettings("{\"not_before\":\"2026-08-01\"}")).getIssuanceConfiguration();
Assert.assertNull(settings.getLifetime());
Assert.assertFalse(settings.isFixedWindow());
- Assert.assertEquals(settings.resolveExpiration(ISSUED_AT, PROFILE_LIFETIME),
- Instant.parse("2026-08-01T00:00:00Z").plus(PROFILE_LIFETIME));
+ Assert.assertNull(settings.getFixedExpiration());
+ Assert.assertEquals(settings.getNotBefore().getFixed(), Instant.parse("2026-08-01T00:00:00Z"));
}
@Test
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/decoding/impl/CredentialOfferRequestDecoder.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/decoding/impl/CredentialOfferRequestDecoder.java
index 28b5eac..8540de8 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/decoding/impl/CredentialOfferRequestDecoder.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/decoding/impl/CredentialOfferRequestDecoder.java
@@ -81,6 +81,8 @@ public class CredentialOfferRequestDecoder extends BaseOAuth2RequestDecoder<Cred
}
}
return MoreObjects.toStringHelper(this).omitNullValues().add("credential_offer_request", requestAsString)
+ .add(CredentialOfferRequest.LIFETIME, message.getLifetime())
+ .add(CredentialOfferRequest.NOT_BEFORE, message.getNotBefore())
.add("clientAuthentication", RequestUtil.getClientAuthenticationLog(message.getClientAuthentication()))
.add("endpointURI", getEndpointURI(message))
.toString();
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialOfferContext.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialOfferContext.java
index 20cbbfe..6ac1ad6 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialOfferContext.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialOfferContext.java
@@ -16,11 +16,13 @@
package org.geant.shibboleth.plugin.openidvci.messaging.context;
+import java.time.Duration;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialDataset;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferTxCode;
import org.opensaml.messaging.context.BaseContext;
@@ -38,6 +40,14 @@ public class CredentialOfferContext extends BaseContext {
@Nullable
private CredentialOfferTxCode credentialOfferTxCode;
+ /** Length of the validity window of the credentials offered. */
+ @Nullable
+ private Duration lifetime;
+
+ /** Start of the validity window of the credentials offered. */
+ @Nullable
+ private ValidityStart notBefore;
+
/** Token returned as the pre-authorized code in responses. */
@Nullable
private String credentialOfferToken;
@@ -80,6 +90,44 @@ public class CredentialOfferContext extends BaseContext {
this.credentialOfferTxCode = credentialOfferTxCode;
}
+ /**
+ * Get length of the validity window of the credentials offered.
+ *
+ * @return length of the validity window, or null
+ */
+ @Nullable
+ public Duration getLifetime() {
+ return lifetime;
+ }
+
+ /**
+ * Set length of the validity window of the credentials offered.
+ *
+ * @param validity length of the validity window
+ */
+ public void setLifetime(@Nullable final Duration validity) {
+ lifetime = validity;
+ }
+
+ /**
+ * Get start of the validity window of the credentials offered.
+ *
+ * @return start of the validity window, or null
+ */
+ @Nullable
+ public ValidityStart getNotBefore() {
+ return notBefore;
+ }
+
+ /**
+ * Set start of the validity window of the credentials offered.
+ *
+ * @param validityStart start of the validity window
+ */
+ public void setNotBefore(@Nullable final ValidityStart validityStart) {
+ notBefore = validityStart;
+ }
+
/**
* Get token returned as the pre-authorized code in responses.
*
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialsContext.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialsContext.java
index 5bb7185..d657d0f 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialsContext.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/context/CredentialsContext.java
@@ -16,6 +16,7 @@
package org.geant.shibboleth.plugin.openidvci.messaging.context;
+import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@@ -23,6 +24,7 @@ import java.util.List;
import javax.annotation.Nullable;
import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.credential.impl.MobileSecurityObject;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequestedCredential;
import org.opensaml.messaging.context.BaseContext;
@@ -56,6 +58,14 @@ public class CredentialsContext extends BaseContext {
@Nullable
private String datasetId;
+ /** Length of the validity window in the Credential Offer of the grant. */
+ @Nullable
+ private Duration requestedLifetime;
+
+ /** Start of the validity window in the Credential Offer of the grant. */
+ @Nullable
+ private ValidityStart requestedValidityStart;
+
/** Validated proofs of wallet. */
@Nullable
private List<SignedJWT> proofs;
@@ -157,8 +167,8 @@ public class CredentialsContext extends BaseContext {
/**
* Get instant the validity window of all credentials of this request opens.
*
- * This is the instant of issuance unless the credential configuration states a
- * 'not_before' of its own.
+ * This is the instant of issuance unless the Credential Offer or the credential
+ * configuration has a 'not_before' of its own.
*
* @return Instant the validity window opens
*/
@@ -294,6 +304,44 @@ public class CredentialsContext extends BaseContext {
datasetId = id;
}
+ /**
+ * Get length of the validity window in the Credential Offer of the grant.
+ *
+ * @return length of the validity window in the Credential Offer of the grant, or null
+ */
+ @Nullable
+ public Duration getRequestedLifetime() {
+ return requestedLifetime;
+ }
+
+ /**
+ * Set length of the validity window in the Credential Offer of the grant.
+ *
+ * @param lifetime length of the validity window in the Credential Offer of the grant
+ */
+ public void setRequestedLifetime(@Nullable final Duration lifetime) {
+ requestedLifetime = lifetime;
+ }
+
+ /**
+ * Get start of the validity window in the Credential Offer of the grant.
+ *
+ * @return start of the validity window in the Credential Offer of the grant, or null
+ */
+ @Nullable
+ public ValidityStart getRequestedValidityStart() {
+ return requestedValidityStart;
+ }
+
+ /**
+ * Set start of the validity window in the Credential Offer of the grant.
+ *
+ * @param start start of the validity window in the Credential Offer of the grant
+ */
+ public void setRequestedValidityStart(@Nullable final ValidityStart start) {
+ requestedValidityStart = start;
+ }
+
/**
* Get credential shell(s) per proof.
*
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 042526e..617abb6 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
@@ -18,12 +18,18 @@ package org.geant.shibboleth.plugin.openidvci.messaging.impl;
import java.net.URI;
import java.net.URISyntaxException;
+import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -39,6 +45,18 @@ import com.nimbusds.oauth2.sdk.http.HTTPRequest;
*/
public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest {
+ /** Member name of the length of the validity window. */
+ @Nonnull
+ public static final String LIFETIME = "lifetime";
+
+ /** Member name of the start of the validity window. */
+ @Nonnull
+ public static final String NOT_BEFORE = "not_before";
+
+ /** Members of a request. */
+ @Nonnull
+ private static final Set<String> MEMBERS = Set.of("preAuthorizedCredentials", "txCode", LIFETIME, NOT_BEFORE);
+
/** Credential offer request content in pre-auth flow. */
@Nullable
private final Map<String, List<CredentialDataset>> preAuthorizedCredentials;
@@ -47,6 +65,14 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
@Nullable
private final CredentialOfferTxCode credentialOfferTxCode;
+ /** Length of the validity window of the credentials offered. */
+ @Nullable
+ private final Duration lifetime;
+
+ /** Start of the validity window of the credentials offered. */
+ @Nullable
+ private final ValidityStart notBefore;
+
/**
* Constructor.
*
@@ -54,13 +80,18 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
* @param clientAuth client authentication
* @param preAuthorizedCredentials credentials offered in the pre-authorized code flow
* @param credentialOfferTxCode Transaction Code the wallet must present
+ * @param validity length of the validity window of the credentials offered, or null
+ * @param validityStart start of the validity window of the credentials offered, or null
*/
public CredentialOfferRequest(@Nullable final URI uri, @Nullable final ClientAuthentication clientAuth,
@Nullable final Map<String, List<CredentialDataset>> preAuthorizedCredentials,
- @Nullable final CredentialOfferTxCode credentialOfferTxCode) {
+ @Nullable final CredentialOfferTxCode credentialOfferTxCode, @Nullable final Duration validity,
+ @Nullable final ValidityStart validityStart) {
super(uri, clientAuth);
this.preAuthorizedCredentials = preAuthorizedCredentials;
this.credentialOfferTxCode = credentialOfferTxCode;
+ lifetime = validity;
+ notBefore = validityStart;
}
/**
@@ -82,6 +113,26 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
return credentialOfferTxCode;
}
+ /**
+ * Get length of the validity window of the credentials offered.
+ *
+ * @return length of the validity window, or null
+ */
+ @Nullable
+ public Duration getLifetime() {
+ return lifetime;
+ }
+
+ /**
+ * Get start of the validity window of the credentials offered.
+ *
+ * @return start of the validity window, or null
+ */
+ @Nullable
+ public ValidityStart getNotBefore() {
+ return notBefore;
+ }
+
// Checkstyle: CyclomaticComplexity OFF
/**
* Parses request from http request.
@@ -121,6 +172,11 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
+ "supported. This endpoint offers the pre-authorized code flow only; an authorization code "
+ "flow offer carries no per request state and is published as a static link");
}
+ for (final String member : content.keySet()) {
+ if (!MEMBERS.contains(member)) {
+ throw new ParseException("Invalid credential offer request: unknown parameter '" + member + "'");
+ }
+ }
if (!content.containsKey("preAuthorizedCredentials")) {
throw new ParseException(
"Invalid credential offer request: The parameter 'preAuthorizedCredentials' must exist");
@@ -144,16 +200,46 @@ public class CredentialOfferRequest extends AbstractOptionallyIdentifiedRequest
credentialOfferTxCode = CredentialOfferTxCode.parse(content.get("txCode"));
}
+ final Duration lifetime;
+ final ValidityStart notBefore;
+ try {
+ lifetime = CredentialIssuanceConfiguration.parseLifetime(stringMember(content, LIFETIME));
+ final String start = stringMember(content, NOT_BEFORE);
+ notBefore = start == null ? null : ValidityStart.parse(start);
+ } catch (final IllegalArgumentException e) {
+ throw new ParseException("Invalid credential offer request: " + e.getMessage());
+ }
+
final URI uri;
try {
uri = httpRequest.getURL().toURI();
} catch (final URISyntaxException e) {
throw new ParseException(e.getMessage(), e);
}
- return new CredentialOfferRequest(uri, clientAuth, preAuthorizedCredentials, credentialOfferTxCode);
+ return new CredentialOfferRequest(uri, clientAuth, preAuthorizedCredentials, credentialOfferTxCode, lifetime,
+ notBefore);
}
// Checkstyle: CyclomaticComplexity ON
+ /**
+ * Get a member of the request that is a string.
+ *
+ * @param content request to read
+ * @param name name of the member
+ * @return value of the member, or null if there is none
+ * @throws ParseException if the member is not a string
+ */
+ @Nullable
+ private static String stringMember(@Nonnull final Map<String, Object> content, @Nonnull final String name)
+ throws ParseException {
+ final Object value = content.get(name);
+ if (value != null && !(value instanceof String)) {
+ throw new ParseException("Invalid credential offer request: The parameter '" + name
+ + "' must be a string");
+ }
+ return (String) value;
+ }
+
/** {@inheritDoc} */
@Override
public HTTPRequest toHTTPRequest() {
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 8a1c539..3544799 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
@@ -59,10 +59,6 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
@Nonnull
private Function<ProfileRequestContext, Integer> batchSizeLookupStrategy;
- /** Lookup function to supply credential lifetime. */
- @Nonnull
- private Function<ProfileRequestContext, Duration> credentialLifetimeLookupStrategy;
-
/** Validation of JWT signature of proofs. */
@Nonnull
private Function<ProfileRequestContext, SignatureValidationConfiguration>
@@ -89,6 +85,14 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
@Nonnull
private Predicate<ProfileRequestContext> allowCredentialConfigurationIdWithIdentifiersPredicate;
+ /** Whether a Credential Offer may set the validity window of its credentials. */
+ @Nonnull
+ private Predicate<ProfileRequestContext> allowValidityWindowPredicate;
+
+ /** Lookup function to supply the longest lifetime a Credential Offer may set. */
+ @Nonnull
+ private Function<ProfileRequestContext, Duration> maxCredentialLifetimeLookupStrategy;
+
/**
* Constructor.
*
@@ -99,13 +103,14 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
preAuthorizedCodeLifetimeLookupStrategy = FunctionSupport.constant(Duration.ofMinutes(10));
preAuthorizedCodeLengthLookupStrategy = FunctionSupport.constant(Integer.valueOf(0));
batchSizeLookupStrategy = FunctionSupport.constant(Integer.valueOf(2));
- credentialLifetimeLookupStrategy = FunctionSupport.constant(Duration.ofDays(180));
proofSignatureValidationConfigurationLookupStrategy = FunctionSupport.constant(null);
credentialSignatureSigningConfigurationLookupStrategy = FunctionSupport.constant(null);
proofClaimsValidatorLookupStrategy = FunctionSupport.constant(null);
keyAttestationClaimsValidatorLookupStrategy = FunctionSupport.constant(null);
proofNonceGeneratorLookupStrategy = FunctionSupport.constant(null);
allowCredentialConfigurationIdWithIdentifiersPredicate = PredicateSupport.alwaysFalse();
+ allowValidityWindowPredicate = PredicateSupport.alwaysFalse();
+ maxCredentialLifetimeLookupStrategy = FunctionSupport.constant(null);
}
/** {@inheritDoc} */
@@ -209,30 +214,6 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
batchSizeLookupStrategy = Constraint.isNotNull(strategy, "Lookup strategy cannot be null");
}
- /** {@inheritDoc} */
- @Override
- @Positive
- @Nonnull
- public Duration getCredentialLifetime(@Nullable final ProfileRequestContext profileRequestContext) {
- final Duration lifetime = credentialLifetimeLookupStrategy.apply(profileRequestContext);
-
- Constraint.isTrue(lifetime != null && !lifetime.isZero() && !lifetime.isNegative(),
- "Credential lifetime must be greater than 0");
- return lifetime;
- }
-
- /**
- * Set the lifetime of an credential.
- *
- * @param lifetime lifetime of an credential
- */
- public void setCredentialLifetime(@Positive @Nonnull final Duration lifetime) {
- Constraint.isTrue(lifetime != null && !lifetime.isZero() && !lifetime.isNegative(),
- "Credential lifetime must be greater than 0");
-
- credentialLifetimeLookupStrategy = FunctionSupport.constant(lifetime);
- }
-
/** {@inheritDoc} */
@Override
@Nullable
@@ -412,4 +393,61 @@ public abstract class AbstractOpenIDVCIConfiguration extends AbstractOIDCSSOConf
allowCredentialConfigurationIdWithIdentifiersPredicate =
Constraint.isNotNull(condition, "Condition cannot be null");
}
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isAllowValidityWindow(@Nullable final ProfileRequestContext profileRequestContext) {
+ return allowValidityWindowPredicate.test(profileRequestContext);
+ }
+
+ /**
+ * Set whether a Credential Offer may set the validity window of its credentials.
+ *
+ * @param flag flag to set
+ */
+ public void setAllowValidityWindow(final boolean flag) {
+ allowValidityWindowPredicate = flag ? PredicateSupport.alwaysTrue() : PredicateSupport.alwaysFalse();
+ }
+
+ /**
+ * Set condition for whether a Credential Offer may set the validity window of its credentials.
+ *
+ * @param condition condition to set
+ */
+ public void setAllowValidityWindowPredicate(@Nonnull final Predicate<ProfileRequestContext> condition) {
+ allowValidityWindowPredicate = Constraint.isNotNull(condition, "Condition cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable
+ public Duration getMaxCredentialLifetime(@Nullable final ProfileRequestContext profileRequestContext) {
+ final Duration lifetime = maxCredentialLifetimeLookupStrategy.apply(profileRequestContext);
+
+ Constraint.isTrue(lifetime == null || (!lifetime.isZero() && !lifetime.isNegative()),
+ "Maximum credential lifetime must be greater than 0");
+ return lifetime;
+ }
+
+ /**
+ * Set the longest lifetime a Credential Offer may set for its credentials.
+ *
+ * @param lifetime longest lifetime, or null for no limit
+ */
+ public void setMaxCredentialLifetime(@Nullable final Duration lifetime) {
+ Constraint.isTrue(lifetime == null || (!lifetime.isZero() && !lifetime.isNegative()),
+ "Maximum credential lifetime must be greater than 0");
+
+ maxCredentialLifetimeLookupStrategy = FunctionSupport.constant(lifetime);
+ }
+
+ /**
+ * Set the lookup strategy for the longest lifetime a Credential Offer may set for its credentials.
+ *
+ * @param strategy lookup strategy
+ */
+ public void setMaxCredentialLifetimeLookupStrategy(
+ @Nonnull final Function<ProfileRequestContext, Duration> strategy) {
+ maxCredentialLifetimeLookupStrategy = Constraint.isNotNull(strategy, "Lookup strategy cannot be null");
+ }
}
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 90e6362..9a91219 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
@@ -228,7 +228,8 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
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());
+ ctx.getValidatedPreAuthorizedCredentials(), null, ctx.getCredentialOfferTxCode(), ctx.getLifetime(),
+ ctx.getNotBefore());
final String credentialOfferToken;
if (preAuthorizedCodeLength != 0) {
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetime.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetime.java
index 883d8a3..f9102ef 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetime.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetime.java
@@ -25,16 +25,14 @@ import javax.annotation.Nullable;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.idp.profile.IdPEventIds;
-import net.shibboleth.profile.config.ProfileConfiguration;
-import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
-import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
-import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
-import org.geant.shibboleth.plugin.openidvci.profile.config.OpenIDVCIConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
-import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds;
+import org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialLifetimeLookupFunction;
+import org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialValidityStartLookupFunction;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -55,22 +53,23 @@ public class ResolveCredentialLifetime extends AbstractProfileAction {
/** Class logger. */
@Nonnull
- private Logger log = LoggerFactory.getLogger(ResolveCredentialLifetime.class);
+ private final Logger log = LoggerFactory.getLogger(ResolveCredentialLifetime.class);
- /**
- * Strategy used to locate the {@link RelyingPartyContext} associated with a
- * given {@link ProfileRequestContext}.
- */
+ /** Strategy used to obtain the lifetime of the credentials. */
@Nonnull
- private Function<ProfileRequestContext, RelyingPartyContext> relyingPartyContextLookupStrategy;
+ private Function<ProfileRequestContext, Duration> lifetimeLookupStrategy;
+
+ /** Strategy used to obtain the start of the validity window of the credentials. */
+ @Nonnull
+ private Function<ProfileRequestContext, ValidityStart> validityStartLookupStrategy;
/** Lifetime of credential. */
@Nullable
private Duration lifetime;
- /** Settings the Credential Configuration in issue states, if any. */
+ /** Start of the validity window, or null for the instant of issuance. */
@Nullable
- private CredentialIssuanceConfiguration settings;
+ private ValidityStart validityStart;
/** Granularity the instant of issuance is rounded down to. */
@Nonnull
@@ -82,22 +81,30 @@ public class ResolveCredentialLifetime extends AbstractProfileAction {
/** Constructor. */
public ResolveCredentialLifetime() {
- relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class);
+ lifetimeLookupStrategy = new CredentialLifetimeLookupFunction();
+ validityStartLookupStrategy = new CredentialValidityStartLookupFunction();
}
/**
- * Set the strategy used to locate the {@link RelyingPartyContext} associated
- * with a given {@link ProfileRequestContext}.
+ * Set the strategy used to obtain the lifetime of the credentials.
*
- * @param strategy strategy used to locate the {@link RelyingPartyContext}
- * associated with a given {@link ProfileRequestContext}
+ * @param strategy lookup strategy
*/
- public void setRelyingPartyContextLookupStrategy(
- @Nonnull final Function<ProfileRequestContext, RelyingPartyContext> strategy) {
- ifInitializedThrowUnmodifiabledComponentException();
+ public void setLifetimeLookupStrategy(@Nonnull final Function<ProfileRequestContext, Duration> strategy) {
+ checkSetterPreconditions();
+ lifetimeLookupStrategy = Constraint.isNotNull(strategy, "Lifetime lookup strategy cannot be null");
+ }
- relyingPartyContextLookupStrategy = Constraint.isNotNull(strategy,
- "RelyingPartyContext lookup strategy cannot be null");
+ /**
+ * Set the strategy used to obtain the start of the validity window of the
+ * credentials.
+ *
+ * @param strategy lookup strategy
+ */
+ public void setValidityStartLookupStrategy(
+ @Nonnull final Function<ProfileRequestContext, ValidityStart> strategy) {
+ checkSetterPreconditions();
+ validityStartLookupStrategy = Constraint.isNotNull(strategy, "Validity start lookup strategy cannot be null");
}
/**
@@ -108,7 +115,7 @@ public class ResolveCredentialLifetime extends AbstractProfileAction {
* credential configuration
*/
public void setTimestampPrecision(@Nonnull final Duration precision) {
- ifInitializedThrowUnmodifiabledComponentException();
+ checkSetterPreconditions();
Constraint.isNotNull(precision, "Timestamp precision cannot be null");
Constraint.isFalse(precision.getSeconds() < 1, "Timestamp precision cannot be shorter than a second");
@@ -124,26 +131,6 @@ public class ResolveCredentialLifetime extends AbstractProfileAction {
return false;
}
- final RelyingPartyContext rpCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
- if (rpCtx == null) {
- log.debug("{} No relying party context associated with this profile request", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
- return false;
- }
-
- final ProfileConfiguration pc = rpCtx.getProfileConfig();
- if (!(pc instanceof OpenIDVCIConfiguration)) {
- log.error("{} No OpenID VCI profile configuration associated with this profile request", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
- return false;
- }
- lifetime = ((OpenIDVCIConfiguration) pc).getCredentialLifetime(profileRequestContext);
- if (lifetime == null) {
- log.error("{} No credential lifetime available", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
- return false;
- }
-
if (profileRequestContext.getInboundMessageContext() == null) {
log.error("{} No inbound message context", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
@@ -151,13 +138,13 @@ public class ResolveCredentialLifetime extends AbstractProfileAction {
}
ctx = profileRequestContext.getInboundMessageContext().ensureSubcontext(CredentialsContext.class);
- final CredentialConfiguration configuration = ctx.getCredentialConfiguration();
- settings = configuration == null ? null : configuration.getIssuanceConfiguration();
- if (settings != null && settings.getLifetime() != null) {
- log.debug("{} Credential configuration states a lifetime of {}, in place of the profile"
- + " configuration's {}", getLogPrefix(), settings.getLifetime(), lifetime);
- lifetime = settings.getLifetime();
+ lifetime = lifetimeLookupStrategy.apply(profileRequestContext);
+ if (lifetime == null || lifetime.isZero() || lifetime.isNegative()) {
+ log.error("{} No positive credential lifetime available", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+ return false;
}
+ validityStart = validityStartLookupStrategy.apply(profileRequestContext);
return true;
}
@@ -170,18 +157,17 @@ public class ResolveCredentialLifetime extends AbstractProfileAction {
final Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
final Instant issuedAt = roundDown(now);
- final Instant notBefore = (settings == null ? issuedAt : settings.resolveNotBefore(issuedAt))
+ final Instant notBefore = (validityStart == null ? issuedAt : validityStart.resolve(issuedAt))
.truncatedTo(ChronoUnit.SECONDS);
final Instant expiresAt = notBefore.plus(lifetime);
if (!expiresAt.isAfter(now)) {
- // TODO: A closed window deserves an error the wallet is able to act on.
log.error(
"{} Validity window of the requested credential closed at {}, there is nothing to issue."
+ " Move the 'not_before' or the 'lifetime' of its credential configuration, or"
+ " shorten the timestamp precision {}.",
getLogPrefix(), expiresAt, timestampPrecision);
- ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+ ActionSupport.buildEvent(profileRequestContext, OpenIDVCIEventIds.VALIDITY_WINDOW_CLOSED);
return;
}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOfferValidity.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOfferValidity.java
new file mode 100644
index 0000000..0b5dc51
--- /dev/null
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOfferValidity.java
@@ -0,0 +1,234 @@
+/*
+ * 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.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.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialOfferContext;
+import org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds;
+import org.geant.shibboleth.plugin.openidvci.profile.config.OpenIDVCIConfiguration;
+import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.profile.action.ActionSupport;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+
+import net.shibboleth.idp.profile.IdPEventIds;
+import net.shibboleth.profile.config.ProfileConfiguration;
+import net.shibboleth.profile.context.RelyingPartyContext;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
+
+/**
+ * Action that validates the validity window in a Credential Offer against the
+ * profile configuration of the caller.
+ */
+public class ValidateCredentialOfferValidity extends AbstractCredentialValidationAction {
+
+ /** Class logger. */
+ @Nonnull
+ private final Logger log = LoggerFactory.getLogger(ValidateCredentialOfferValidity.class);
+
+ /**
+ * Strategy used to locate the {@link RelyingPartyContext} associated with a
+ * given {@link ProfileRequestContext}.
+ */
+ @Nonnull
+ private Function<ProfileRequestContext, RelyingPartyContext> relyingPartyContextLookupStrategy;
+
+ /** Lifetime of a credential if the offer and the Credential Configuration have none. */
+ @Nonnull
+ private Duration defaultCredentialLifetime = Duration.ofDays(180);
+
+ /** Context of the Credential Offer. */
+ @Nullable
+ private CredentialOfferContext ctx;
+
+ /** Whether the caller may set the validity window. */
+ private boolean allowValidityWindow;
+
+ /** Longest lifetime the caller may set, or null for no limit. */
+ @Nullable
+ private Duration maxLifetime;
+
+ /** Lifetime of the pre-authorized code. */
+ @Nullable
+ private Duration codeLifetime;
+
+ /** Constructor. */
+ public ValidateCredentialOfferValidity() {
+ relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class);
+ }
+
+ /**
+ * Set the strategy used to locate the {@link RelyingPartyContext} associated
+ * with a given {@link ProfileRequestContext}.
+ *
+ * @param strategy lookup strategy
+ */
+ public void setRelyingPartyContextLookupStrategy(
+ @Nonnull final Function<ProfileRequestContext, RelyingPartyContext> strategy) {
+ checkSetterPreconditions();
+ relyingPartyContextLookupStrategy = Constraint.isNotNull(strategy,
+ "RelyingPartyContext lookup strategy cannot be null");
+ }
+
+ /**
+ * Set the lifetime of a credential if the offer and the Credential
+ * Configuration have none.
+ *
+ * @param lifetime positive lifetime
+ */
+ public void setDefaultCredentialLifetime(@Nonnull final Duration lifetime) {
+ checkSetterPreconditions();
+ Constraint.isNotNull(lifetime, "Default credential lifetime cannot be null");
+ Constraint.isFalse(lifetime.isZero() || lifetime.isNegative(), "Default credential lifetime must be positive");
+ defaultCredentialLifetime = lifetime;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
+ final RelyingPartyContext rpCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
+ if (rpCtx == null) {
+ log.error("{} No relying party context associated with this profile request", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
+ return false;
+ }
+ final ProfileConfiguration pc = rpCtx.getProfileConfig();
+ if (!(pc instanceof OpenIDVCIConfiguration configuration)) {
+ log.error("{} No OpenID VCI profile configuration associated with this profile request", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
+ return false;
+ }
+ allowValidityWindow = configuration.isAllowValidityWindow(profileRequestContext);
+ maxLifetime = configuration.getMaxCredentialLifetime(profileRequestContext);
+ codeLifetime = configuration.getPreAuthorizedCodeLifetime(profileRequestContext);
+
+ ctx = profileRequestContext.getInboundMessageContext() == null ? null
+ : profileRequestContext.getInboundMessageContext().getSubcontext(CredentialOfferContext.class);
+ if (ctx == null || ctx.getValidatedPreAuthorizedCredentials() == null) {
+ log.error("{} No credential offer context", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+ return false;
+ }
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ assert ctx != null;
+
+ if (ctx.getLifetime() == null && ctx.getNotBefore() == null) {
+ return;
+ }
+ if (!allowValidityWindow) {
+ refuse(profileRequestContext, "the caller may not set a validity window");
+ return;
+ }
+ if (ctx.getLifetime() != null && maxLifetime != null && ctx.getLifetime().compareTo(maxLifetime) > 0) {
+ refuse(profileRequestContext, "lifetime " + ctx.getLifetime() + " is longer than " + maxLifetime);
+ return;
+ }
+ final Instant now = Instant.now();
+ for (final String configurationId : ctx.getValidatedPreAuthorizedCredentials().keySet()) {
+ final CredentialConfiguration configuration = getCredentialConfigurations().get(configurationId);
+ final Instant closes = closes(configuration == null ? null : configuration.getIssuanceConfiguration(),
+ now);
+ if (closes != null) {
+ refuse(profileRequestContext, "validity window of " + configurationId + " closes at " + closes
+ + ", before the credential can be issued");
+ return;
+ }
+ }
+ }
+
+ /**
+ * Refuse the Credential Offer.
+ *
+ * @param profileRequestContext profile request context
+ * @param problem what is wrong with the validity window
+ */
+ private void refuse(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final String problem) {
+ log.warn("{} Credential offer refused: {}", getLogPrefix(), problem);
+ ActionSupport.buildEvent(profileRequestContext, OpenIDVCIEventIds.INVALID_VALIDITY_WINDOW);
+ }
+
+ /**
+ * Get the instant the validity window of a Credential Configuration closes, if
+ * it closes before its credential can be issued.
+ *
+ * @param settings settings of the Credential Configuration, or null
+ * @param now instant of the offer
+ * @return the instant the window closes, or null if it stays open
+ */
+ @Nullable
+ private Instant closes(@Nullable final CredentialIssuanceConfiguration settings, @Nonnull final Instant now) {
+ assert ctx != null && codeLifetime != null;
+
+ final Duration lifetime = lifetimeOf(settings);
+ final ValidityStart start = ctx.getNotBefore() != null ? ctx.getNotBefore() : startOf(settings);
+ final Instant closes = (start == null ? now : start.resolve(now)).plus(lifetime);
+ final Instant deadline = start != null && start.isFixed() ? now.plus(codeLifetime) : now;
+
+ return closes.isAfter(deadline) ? null : closes;
+ }
+
+ /**
+ * Get the lifetime credentials of a Credential Configuration are issued with.
+ *
+ * @param settings settings of the Credential Configuration, or null
+ * @return lifetime of the offer, of the Credential Configuration or the default
+ */
+ @Nonnull
+ private Duration lifetimeOf(@Nullable final CredentialIssuanceConfiguration settings) {
+ assert ctx != null;
+ if (ctx.getLifetime() != null) {
+ return ctx.getLifetime();
+ }
+ if (settings != null && settings.getLifetime() != null) {
+ return settings.getLifetime();
+ }
+ return defaultCredentialLifetime;
+ }
+
+ /**
+ * Get the start of the validity window in a Credential Configuration.
+ *
+ * @param settings settings of the Credential Configuration, or null
+ * @return start of the validity window, or null for the instant of issuance
+ */
+ @Nullable
+ private static ValidityStart startOf(@Nullable final CredentialIssuanceConfiguration settings) {
+ return settings == null ? null : settings.getNotBefore();
+ }
+
+}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOffering.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOffering.java
index 2dd9d0f..2fcd692 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOffering.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOffering.java
@@ -105,6 +105,8 @@ public class ValidateCredentialOffering extends AbstractCredentialValidationActi
final CredentialOfferContext ctx = new CredentialOfferContext();
ctx.setValidatedPreAuthorizedCredentials(request.getPreAuthorizedCredentials());
ctx.setCredentialOfferTxCode(request.getCredentialOfferTxCode());
+ ctx.setLifetime(request.getLifetime());
+ ctx.setNotBefore(request.getNotBefore());
profileRequestContext.getInboundMessageContext().addSubcontext(ctx, true);
}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredential.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredential.java
index b44abb7..b10719f 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredential.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredential.java
@@ -26,10 +26,13 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
import org.geant.shibboleth.plugin.openidvci.messaging.context.navigate.RequestCredentialConfigurationIdLookupFunction;
import org.geant.shibboleth.plugin.openidvci.messaging.context.navigate.RequestCredentialIdentifierLookupFunction;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialDataset;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
import org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds;
import org.geant.shibboleth.plugin.openidvci.profile.config.OpenIDVCIConfiguration;
import org.geant.shibboleth.plugin.openidvci.profile.logic.OpenIDVCITokenManipulationStrategy;
@@ -255,9 +258,40 @@ public class ValidateRequestedCredential extends AbstractCredentialValidationAct
ctx.setCredentialIdentifier(identifier != null ? identifier : configurationId);
ctx.setCredentialConfigurationId(selectedConfigurationId);
ctx.setDatasetId(dataset.getDatasetId());
+ if (!setValidityWindow(ctx)) {
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+ }
}
// Checkstyle: CyclomaticComplexity|ReturnCount ON
+ /**
+ * Set the validity window in the Credential Offer of the grant to the credentials context.
+ *
+ * @param ctx credentials context
+ * @return whether the validity window of the grant could be read
+ */
+ private boolean setValidityWindow(@Nonnull final CredentialsContext ctx) {
+ assert oidcResponseContext != null;
+ final Map<String, Object> window;
+ try {
+ window = oidcResponseContext.getAuthorizationGrantClaimsSet().getClaimsSet()
+ .getJSONObjectClaim(OpenIDVCITokenManipulationStrategy.VALIDITY_WINDOW);
+ if (window == null) {
+ return true;
+ }
+ final Object lifetime = window.get(CredentialOfferRequest.LIFETIME);
+ final Object start = window.get(CredentialOfferRequest.NOT_BEFORE);
+ ctx.setRequestedLifetime(
+ CredentialIssuanceConfiguration.parseLifetime(lifetime == null ? null : lifetime.toString()));
+ ctx.setRequestedValidityStart(start == null ? null : ValidityStart.parse(start.toString()));
+ } catch (final ParseException | IllegalArgumentException e) {
+ log.error("{} Parsing the validity window of the grant failed", getLogPrefix(), e);
+ return false;
+ }
+ log.debug("{} Validity window of the Credential Offer: {}", getLogPrefix(), window);
+ return true;
+ }
+
/**
* Select the dataset of the request.
*
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialLifetimeLookupFunction.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialLifetimeLookupFunction.java
new file mode 100644
index 0000000..665e9e7
--- /dev/null
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialLifetimeLookupFunction.java
@@ -0,0 +1,76 @@
+/*
+ * 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.logic;
+
+import java.time.Duration;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+
+import net.shibboleth.shared.logic.Constraint;
+
+/**
+ * Supplies the lifetime of the credentials of this request, from the Credential
+ * Offer of the grant or from the 'lifetime' member of the Credential Configuration
+ * in issue.
+ */
+public class CredentialLifetimeLookupFunction implements Function<ProfileRequestContext, Duration> {
+
+ /** Lifetime of a credential if the Credential Configuration has none. */
+ @Nonnull
+ private Duration defaultLifetime = Duration.ofDays(180);
+
+ /**
+ * Set the lifetime of a credential if the Credential Configuration has none.
+ *
+ * @param lifetime positive lifetime
+ */
+ public void setDefaultLifetime(@Nonnull final Duration lifetime) {
+ Constraint.isNotNull(lifetime, "Default lifetime cannot be null");
+ Constraint.isFalse(lifetime.isZero() || lifetime.isNegative(), "Default lifetime must be positive");
+ defaultLifetime = lifetime;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nonnull
+ public Duration apply(@Nullable final ProfileRequestContext profileRequestContext) {
+
+ if (profileRequestContext == null || profileRequestContext.getInboundMessageContext() == null) {
+ return defaultLifetime;
+ }
+
+ final CredentialsContext ctx = profileRequestContext.getInboundMessageContext()
+ .getSubcontext(CredentialsContext.class);
+ if (ctx != null && ctx.getRequestedLifetime() != null) {
+ return ctx.getRequestedLifetime();
+ }
+ final CredentialConfiguration configuration = ctx == null ? null : ctx.getCredentialConfiguration();
+ final CredentialIssuanceConfiguration settings = configuration == null ? null
+ : configuration.getIssuanceConfiguration();
+ final Duration lifetime = settings == null ? null : settings.getLifetime();
+
+ return lifetime == null ? defaultLifetime : lifetime;
+ }
+
+}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialValidityStartLookupFunction.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialValidityStartLookupFunction.java
new file mode 100644
index 0000000..4de2217
--- /dev/null
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialValidityStartLookupFunction.java
@@ -0,0 +1,57 @@
+/*
+ * 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.logic;
+
+import java.util.function.Function;
+
+import javax.annotation.Nullable;
+
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+
+/**
+ * Supplies the start of the validity window of the credentials of this request,
+ * from the Credential Offer of the grant or from the 'not_before' member of the
+ * Credential Configuration in issue.
+ */
+public class CredentialValidityStartLookupFunction implements Function<ProfileRequestContext, ValidityStart> {
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable
+ public ValidityStart apply(@Nullable final ProfileRequestContext profileRequestContext) {
+
+ if (profileRequestContext == null || profileRequestContext.getInboundMessageContext() == null) {
+ return null;
+ }
+
+ final CredentialsContext ctx = profileRequestContext.getInboundMessageContext()
+ .getSubcontext(CredentialsContext.class);
+ if (ctx != null && ctx.getRequestedValidityStart() != null) {
+ return ctx.getRequestedValidityStart();
+ }
+ final CredentialConfiguration configuration = ctx == null ? null : ctx.getCredentialConfiguration();
+ final CredentialIssuanceConfiguration settings = configuration == null ? null
+ : configuration.getIssuanceConfiguration();
+
+ return settings == null ? null : settings.getNotBefore();
+ }
+
+}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategy.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategy.java
index eb63d84..68b95d4 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategy.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategy.java
@@ -16,6 +16,7 @@
package org.geant.shibboleth.plugin.openidvci.profile.logic;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
@@ -26,8 +27,10 @@ import javax.annotation.Nullable;
import org.geant.shibboleth.plugin.openidvci.messaging.context.TokenContext;
import org.geant.shibboleth.plugin.openidvci.messaging.context.navigate.AuthorizationDetailsLookupFunction;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.OpenIDVCIAuthorizationDetail;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.OpenIDVCITokenRequest;
+import org.geant.shibboleth.plugin.openidvci.storage.CredentialOfferObject;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
@@ -62,6 +65,10 @@ public class OpenIDVCITokenManipulationStrategy
/** Claim name carrying the client instance key thumbprint of the client attestation. */
public static final String CLIENT_INSTANCE_KEY = "vci.int.clientInstanceKey";
+ /** Claim name of the validity window in a Credential Offer. */
+ @Nonnull
+ public static final String VALIDITY_WINDOW = "vci.int.validityWindow";
+
/** Member name of the credential configuration id of an issued credential identifier. */
public static final String CREDENTIAL_CONFIGURATION_ID = "credential_configuration_id";
@@ -125,6 +132,10 @@ public class OpenIDVCITokenManipulationStrategy
profileRequestContext.getInboundMessageContext().getSubcontext(TokenContext.class);
if (tokenContext != null) {
claims.put(POTENTIAL_CLAIMS, tokenContext.getPotentialCredentials().toJSONObject());
+ final Map<String, Object> window = validityWindow(tokenContext);
+ if (window != null) {
+ claims.put(VALIDITY_WINDOW, window);
+ }
if (tokenContext.getIssuedCredentialIdentifiers() != null
&& !tokenContext.getIssuedCredentialIdentifiers().isEmpty()) {
claims.put(CREDENTIAL_IDENTIFIERS, tokenContext.getIssuedCredentialIdentifiers());
@@ -139,4 +150,27 @@ public class OpenIDVCITokenManipulationStrategy
return claims;
}
+
+ /**
+ * Get the validity window in the Credential Offer of the grant.
+ *
+ * @param tokenContext token context of the grant
+ * @return 'lifetime' and 'not_before' of the offer, or null if it has neither
+ */
+ @Nullable
+ private static Map<String, Object> validityWindow(@Nonnull final TokenContext tokenContext) {
+ final CredentialOfferObject offer = tokenContext.getCredentialOfferObject();
+ if (offer == null || (offer.getLifetime() == null && offer.getNotBefore() == null)) {
+ return null;
+ }
+ final Map<String, Object> window = new HashMap<>();
+ if (offer.getLifetime() != null) {
+ window.put(CredentialOfferRequest.LIFETIME, offer.getLifetimeValue());
+ }
+ if (offer.getNotBefore() != null) {
+ window.put(CredentialOfferRequest.NOT_BEFORE, offer.getNotBeforeValue());
+ }
+ return window;
+ }
+
}
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObject.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObject.java
index 147af54..76a00a4 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObject.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObject.java
@@ -16,16 +16,21 @@
package org.geant.shibboleth.plugin.openidvci.storage;
+import java.time.Duration;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialIssuanceConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialDataset;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferTxCode;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -52,6 +57,50 @@ public class CredentialOfferObject {
@Nullable
private final CredentialOfferTxCode credentialOfferTxCode;
+ /** Length of the validity window of the credentials offered. */
+ @Nullable
+ private final Duration lifetime;
+
+ /** Start of the validity window of the credentials offered. */
+ @Nullable
+ private final ValidityStart notBefore;
+
+ /**
+ * Constructor.
+ *
+ * @param clientID Client ID of the relying party
+ * @param preAuthorizedCredentials Credentials offered in the pre-authorized code flow
+ * @param codeCredentials Credentials offered in the authorization code flow
+ * @param credentialOfferTxCode Transaction Code the wallet must present
+ */
+ public CredentialOfferObject(@Nullable final ClientID clientID,
+ @Nullable final Map<String, List<CredentialDataset>> preAuthorizedCredentials,
+ @Nullable final List<String> codeCredentials, @Nullable final CredentialOfferTxCode credentialOfferTxCode) {
+ this(clientID, preAuthorizedCredentials, codeCredentials, credentialOfferTxCode, (Duration) null, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param clientID Client ID of the relying party
+ * @param preAuthorizedCredentials Credentials offered in the pre-authorized code flow
+ * @param codeCredentials Credentials offered in the authorization code flow
+ * @param credentialOfferTxCode Transaction Code the wallet must present
+ * @param validity length of the validity window of the credentials offered, or null
+ * @param validityStart start of the validity window of the credentials offered, or null
+ */
+ public CredentialOfferObject(@Nullable final ClientID clientID,
+ @Nullable final Map<String, List<CredentialDataset>> preAuthorizedCredentials,
+ @Nullable final List<String> codeCredentials, @Nullable final CredentialOfferTxCode credentialOfferTxCode,
+ @Nullable final Duration validity, @Nullable final ValidityStart validityStart) {
+ this.clientID = clientID;
+ this.preAuthorizedCredentials = preAuthorizedCredentials;
+ this.codeCredentials = codeCredentials;
+ this.credentialOfferTxCode = credentialOfferTxCode;
+ lifetime = validity;
+ notBefore = validityStart;
+ }
+
/**
* Constructor.
*
@@ -59,18 +108,21 @@ public class CredentialOfferObject {
* @param preAuthorizedCredentials Credentials offered in the pre-authorized code flow
* @param codeCredentials Credentials offered in the authorization code flow
* @param credentialOfferTxCode Transaction Code the wallet must present
+ * @param validity length of the validity window as written in json, or null
+ * @param validityStart start of the validity window as written in json, or null
*/
@JsonCreator
- public CredentialOfferObject(
+ private CredentialOfferObject(
@JsonProperty("clientID") @Nullable final ClientID clientID,
@JsonProperty("preAuthorizedCredentials") @Nullable
final Map<String, List<CredentialDataset>> preAuthorizedCredentials,
@JsonProperty("codeCredentials") @Nullable final List<String> codeCredentials,
- @JsonProperty("credentialOfferTxCode") @Nullable final CredentialOfferTxCode credentialOfferTxCode) {
- this.clientID = clientID;
- this.preAuthorizedCredentials = preAuthorizedCredentials;
- this.codeCredentials = codeCredentials;
- this.credentialOfferTxCode = credentialOfferTxCode;
+ @JsonProperty("credentialOfferTxCode") @Nullable final CredentialOfferTxCode credentialOfferTxCode,
+ @JsonProperty(CredentialOfferRequest.LIFETIME) @Nullable final String validity,
+ @JsonProperty(CredentialOfferRequest.NOT_BEFORE) @Nullable final String validityStart) {
+ this(clientID, preAuthorizedCredentials, codeCredentials, credentialOfferTxCode,
+ CredentialIssuanceConfiguration.parseLifetime(validity),
+ validityStart == null ? null : ValidityStart.parse(validityStart));
}
@@ -112,6 +164,50 @@ public class CredentialOfferObject {
return credentialOfferTxCode;
}
+ /**
+ * Get length of the validity window of the credentials offered.
+ *
+ * @return length of the validity window, or null
+ */
+ @JsonIgnore
+ @Nullable
+ public Duration getLifetime() {
+ return lifetime;
+ }
+
+ /**
+ * Get length of the validity window of the credentials offered as written in json.
+ *
+ * @return length of the validity window, or null
+ */
+ @JsonProperty(CredentialOfferRequest.LIFETIME)
+ @Nullable
+ public String getLifetimeValue() {
+ return lifetime == null ? null : lifetime.toString();
+ }
+
+ /**
+ * Get start of the validity window of the credentials offered.
+ *
+ * @return start of the validity window, or null
+ */
+ @JsonIgnore
+ @Nullable
+ public ValidityStart getNotBefore() {
+ return notBefore;
+ }
+
+ /**
+ * Get start of the validity window of the credentials offered as written in json.
+ *
+ * @return start of the validity window, or null
+ */
+ @JsonProperty(CredentialOfferRequest.NOT_BEFORE)
+ @Nullable
+ public String getNotBeforeValue() {
+ return notBefore == null ? null : notBefore.toString();
+ }
+
/**
* Serialize object to json.
*
diff --git a/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index 24a25b3..5add70f 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -194,7 +194,15 @@
<bean id="openidvci.AllowedCredentialConfigurationsLookup" lazy-init="true"
class="org.geant.shibboleth.plugin.openidvci.profile.logic.AllowedCredentialConfigurationsLookupFunction"
c:resolver-ref="openidvci.CredentialConfigurationsResolver" />
-
+
+ <!-- Validity window of issued credentials, from the Credential Offer or the Credential Configuration in issue. -->
+ <bean id="openidvci.DefaultCredentialLifetimeLookupStrategy" lazy-init="true"
+ class="org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialLifetimeLookupFunction"
+ p:defaultLifetime="%{openidvci.credentialLifetime:P180D}" />
+
+ <bean id="openidvci.DefaultCredentialValidityStartLookupStrategy" lazy-init="true"
+ class="org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialValidityStartLookupFunction" />
+
<!-- Credential Issuer metadata, published at /.well-known/openid-credential-issuer. -->
<bean id="openidvci.DefaultCredentialIssuerMetadataResolver" lazy-init="true"
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 c3b4082..93c126f 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
@@ -32,6 +32,10 @@
<bean id="ValidateCredentialOffering" class="org.geant.shibboleth.plugin.openidvci.profile.impl.ValidateCredentialOffering"
scope="prototype" p:credentialConfigurationsResolver-ref="openidvci.CredentialConfigurationsResolver"/>
+ <bean id="ValidateCredentialOfferValidity" class="org.geant.shibboleth.plugin.openidvci.profile.impl.ValidateCredentialOfferValidity"
+ scope="prototype" p:credentialConfigurationsResolver-ref="openidvci.CredentialConfigurationsResolver"
+ p:defaultCredentialLifetime="%{openidvci.credentialLifetime:P180D}"/>
+
<bean id="ValidateCredentialOfferScope" class="org.geant.shibboleth.plugin.openidvci.profile.impl.ValidateCredentialOfferScope"
scope="prototype" p:allowedCredentialConfigurationsLookupStrategy-ref="openidvci.AllowedCredentialConfigurationsLookup"/>
@@ -72,6 +76,7 @@
<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(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}" />
+ <entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).INVALID_VALIDITY_WINDOW}" value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).INVALID_REQUEST}" />
</map>
</property>
</bean>
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-flow.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-flow.xml
index 1677b17..9b05a51 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-flow.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-flow.xml
@@ -18,6 +18,7 @@
<action-state id="ResumeAfterAuthentication">
<evaluate expression="ValidateCredentialOffering"/>
<evaluate expression="ValidateCredentialOfferScope"/>
+ <evaluate expression="ValidateCredentialOfferValidity"/>
<evaluate expression="BuildCredentialOfferToken"/>
<evaluate expression="'proceed'"/>
<transition on="proceed" to="BuildResponseMessage"/>
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-beans.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-beans.xml
index 3ecf4ea..c166763 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-beans.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-beans.xml
@@ -142,7 +142,9 @@
<bean id="ResolveCredentialLifetime" class="org.geant.shibboleth.plugin.openidvci.profile.impl.ResolveCredentialLifetime"
scope="prototype"
- p:timestampPrecision="%{openidvci.credentialTimestampPrecision:PT1H}" />
+ p:timestampPrecision="%{openidvci.credentialTimestampPrecision:PT1H}"
+ p:lifetimeLookupStrategy-ref="#{'%{openidvci.credentialLifetime.strategy:openidvci.DefaultCredentialLifetimeLookupStrategy}'.trim()}"
+ p:validityStartLookupStrategy-ref="#{'%{openidvci.credentialValidityStart.strategy:openidvci.DefaultCredentialValidityStartLookupStrategy}'.trim()}" />
<bean id="openidvci.MdocCondition" class="org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialFormatPredicate"
c:credentialFormat="mso_mdoc" />
@@ -212,6 +214,8 @@
value="#{T(org.geant.shibboleth.plugin.openidvci.messaging.error.OpenIDVCIError).INVALID_NONCE}" />
<entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).INVALID_CREDENTIAL}"
value="#{T(org.geant.shibboleth.plugin.openidvci.messaging.error.OpenIDVCIError).CREDENTIAL_REQUEST_DENIED}" />
+ <entry key="#{T(org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds).VALIDITY_WINDOW_CLOSED}"
+ value="#{T(org.geant.shibboleth.plugin.openidvci.messaging.error.OpenIDVCIError).CREDENTIAL_REQUEST_DENIED}" />
<entry key="#{T(org.opensaml.profile.action.EventIds).INVALID_PROFILE_CTX}"
value="#{T(com.nimbusds.oauth2.sdk.OAuth2Error).SERVER_ERROR}" />
<entry key="#{T(org.opensaml.profile.action.EventIds).INVALID_MSG_CTX}"
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml
index 3a804f3..6542287 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/service/relying-party/postconfig.xml
@@ -39,7 +39,9 @@
p:keyAttestationClaimsValidator="#{getObject('openidvci.ProofNonceValidator')}" />
<bean id="OpenID.VCI.CredentialOffer" parent="AbstractVCIProfile" lazy-init="true"
- class="org.geant.shibboleth.plugin.openidvci.profile.config.impl.DefaultOpenIDVCICredentialOfferConfiguration" />
+ class="org.geant.shibboleth.plugin.openidvci.profile.config.impl.DefaultOpenIDVCICredentialOfferConfiguration"
+ p:allowValidityWindow="%{openidvci.credentialOffer.allowValidityWindow:false}"
+ p:maxCredentialLifetime="#{'%{openidvci.credentialOffer.maxCredentialLifetime:}'.trim().isEmpty() ? null : T(java.time.Duration).parse('%{openidvci.credentialOffer.maxCredentialLifetime:}'.trim())}" />
<!-- Settings of AbstractOIDCSSOProfile and OAUTH2.Token of the OP plugin, with the DPoP claims validator of this plugin. -->
<bean id="AbstractVCITokenProfile" abstract="true"
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 bb84f25..22e58c2 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
@@ -4,8 +4,8 @@
# derived from the issuer of the OP, and a verifier resolves it from the document published at
# /.well-known/did.json. Any other value is the identifier itself, an https url being the one a
# verifier resolves from /.well-known/jwt-vc-issuer.
-# A did:jwk identifier names the signing key, so it changes when that key does. Rotating the key
-# leaves every credential issued under the previous one naming an identifier this deployment no
+# A did:jwk identifier contains the signing key, so it changes when that key does. Rotating the key
+# leaves every credential issued under the previous one with an identifier this deployment no
# longer answers for, and their Status List Tokens no longer match. Deployments that rotate keys
# and revoke credentials want 'did:web' or a url here.
openidvci.issuer =
@@ -19,6 +19,11 @@ openidvci.issuer =
# Default lifetime of the pre-authorized code
#openidvci.preAuthorizedCode.defaultLifetime = PT10M
+# Whether an offer caller may set 'lifetime' and 'not_before' in the offer request, and the longest
+# 'lifetime' it may set (empty for no limit). Defaults of allowValidityWindow and
+# maxCredentialLifetime of OpenID.VCI.CredentialOffer.
+#openidvci.credentialOffer.allowValidityWindow = false
+#openidvci.credentialOffer.maxCredentialLifetime =
# Length of pre-authorized codes (0 = sealed offer, 32 to 128 = offer in storage; 32 hex characters
# give the 2^-128 guessing probability of RFC 6749 section 10.10, 40 the recommended 2^-160)
#openidvci.preAuthorizedCode.defaultLength = 0
@@ -34,7 +39,7 @@ openidvci.issuer =
# metadata and used as the instruction on how a credential is formed. Every flow reads them
# from here, through one resolver, so the file is read when it changes and not once per request.
# Settings that are this deployment's own, the validity window of a credential and whether it
-# takes a Status List slot, are stated per credential in that same file, in an
+# takes a Status List slot, are set per credential in that same file, in an
# '_issuance_configuration' member that is parsed and then dropped from what gets published.
#openidvci.credentialConfigurations.resource = %{idp.home}/metadata/verifiable-credentials.json
# Bounds on the next file refresh of the Credential Configurations resource. A change to the
@@ -42,6 +47,16 @@ openidvci.issuer =
#openidvci.credentialConfigurations.minRefreshDelay = PT5M
#openidvci.credentialConfigurations.maxRefreshDelay = PT5M
+# Validity of a credential if the Credential Configuration has no 'lifetime'
+#openidvci.credentialLifetime = P180D
+# Bean names of the functions supplying the lifetime and the start of the validity window of a
+# credential, Function<ProfileRequestContext,Duration> and Function<ProfileRequestContext,ValidityStart>.
+# The defaults read the Credential Offer and then the Credential Configuration in issue.
+#openidvci.credentialLifetime.strategy = openidvci.DefaultCredentialLifetimeLookupStrategy
+#openidvci.credentialValidityStart.strategy = openidvci.DefaultCredentialValidityStartLookupStrategy
+# The instant of issuance is rounded down to this. Keep it shorter than the shortest lifetime.
+#openidvci.credentialTimestampPrecision = PT1H
+
# Settings for the issuer-metadata flow
# Flow is available at /openid/vci/issuer-metadata, usually it should be wired from /.well-known/openid-credential-issuer
#openidvci.issuerMetadata.template = %{idp.home}/static/openid-credential-issuer.json
@@ -78,8 +93,8 @@ openidvci.signing.status-list.es.key = %{idp.home}/credentials/openid-vci-status
# Do *NOT* share the key with other people, it's like divulging your private key.
# It is suggested you move this property into credentials/secrets.properties
openidvci.status-list.index.permutationKey = change_this_to_secret
-# Whether a credential whose configuration states no 'status_list' takes a slot of the
-# Status List. Set to false to make the Status List something each Credential
+# Whether a credential takes a slot of the Status List if its configuration has no 'status_list'.
+# Set to false to make the Status List something each Credential
# Configuration opts into with '"status_list": true' instead.
#openidvci.status-list.includeByDefault = true
# Default lifetime of Status List Tokens
@@ -95,7 +110,7 @@ openidvci.status-list.index.permutationKey = change_this_to_secret
# Settings for the jwt-vc-issuer flow
# Flow is available at /oauth/jwt-vc-issuer, usually it should be wired from
# /.well-known/jwt-vc-issuer. A verifier reads that document to find the keys of the issuer, but
-# only when a credential names its issuer by url and its key has no certificates. The default Credential Issuer identifier is
+# only when a credential has a url as its issuer and its key has no certificates. The default Credential Issuer identifier is
# did:jwk, which carries the key inside the credential, so nothing reads the document until you
# set openidvci.issuer.
#openidvci.jwtVcIssuer.template = %{idp.home}/static/jwt-vc-issuer.json
@@ -129,9 +144,9 @@ openidvci.status-list.index.permutationKey = change_this_to_secret
# least this long after adding a signing key before signing with it.
#openidvci.didDocument.cacheControl = max-age=3600
-# Settings for stating this deployment as a Credential Issuer in OpenID Federation. Active
+# Settings for this deployment as a Credential Issuer in OpenID Federation. Active
# only when conf/openid-vci-oidfed.xml is imported into conf/global.xml. Set to false to
-# state federation_entity entirely in the federation module's own metadata file instead of
+# set federation_entity entirely in the federation module's own metadata file instead of
# filling display_name and logo_uri from Credential Issuer metadata.
#openidvci.oidfed.decorateFederationEntity = true
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 c4bb536..e2ca469 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
@@ -17,6 +17,8 @@
package org.geant.shibboleth.plugin.openidvci.messaging.impl;
import java.net.URI;
+import java.time.Duration;
+import java.time.Instant;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -32,6 +34,10 @@ import org.testng.Assert;
*/
public class CredentialOfferRequestTest {
+ private static final String CREDENTIALS =
+ "\"preAuthorizedCredentials\":{\"GeantIncubatorSdJwt2\":"
+ + "[{\"path\":[\"mail\"],\"value\":\"a at example.org\"}]}";
+
private CredentialOfferRequest request;
private HTTPRequest httpRequest;
@@ -57,6 +63,41 @@ public class CredentialOfferRequestTest {
Assert.assertEquals(request.getPreAuthorizedCredentials().get("GeantIncubatorSdJwt2").get(0).getContent().getRequestedCredential()
.get(1).getPath().get(1), "eppn");
Assert.assertEquals(request.getCredentialOfferTxCode().getValue(), "12345");
+ Assert.assertNull(request.getLifetime());
+ Assert.assertNull(request.getNotBefore());
+ }
+
+ @Test
+ public void testValidityWindow() throws ParseException {
+ httpRequest.setBody("{\"lifetime\":\"P3D\",\"not_before\":\"2026-09-14T08:00Z\","
+ + CREDENTIALS + "}");
+ request = CredentialOfferRequest.parse(httpRequest);
+ Assert.assertEquals(request.getLifetime(), Duration.ofDays(3));
+ Assert.assertEquals(request.getNotBefore().getFixed(), Instant.parse("2026-09-14T08:00:00Z"));
+ }
+
+ @Test(expectedExceptions = ParseException.class)
+ public void testUnknownParameterFailure() throws ParseException {
+ httpRequest.setBody("{\"lifetme\":\"P3D\"," + CREDENTIALS + "}");
+ CredentialOfferRequest.parse(httpRequest);
+ }
+
+ @Test(expectedExceptions = ParseException.class)
+ public void testLifetimeNotAStringFailure() throws ParseException {
+ httpRequest.setBody("{\"lifetime\":3," + CREDENTIALS + "}");
+ CredentialOfferRequest.parse(httpRequest);
+ }
+
+ @Test(expectedExceptions = ParseException.class)
+ public void testLifetimeNotADurationFailure() throws ParseException {
+ httpRequest.setBody("{\"lifetime\":\"P1M\"," + CREDENTIALS + "}");
+ CredentialOfferRequest.parse(httpRequest);
+ }
+
+ @Test(expectedExceptions = ParseException.class)
+ public void testNotBeforeNotAStartFailure() throws ParseException {
+ httpRequest.setBody("{\"not_before\":\"tomorrow\"," + CREDENTIALS + "}");
+ CredentialOfferRequest.parse(httpRequest);
}
@Test
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetimeTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetimeTest.java
index 4171294..15cd8cf 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetimeTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ResolveCredentialLifetimeTest.java
@@ -21,8 +21,10 @@ import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
-import org.geant.shibboleth.plugin.openidvci.profile.config.impl.DefaultOpenIDVCICredentialsConfiguration;
+import org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds;
+import org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialLifetimeLookupFunction;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -35,14 +37,13 @@ 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;
/**
* Unit tests for {@link ResolveCredentialLifetime}.
*/
public class ResolveCredentialLifetimeTest {
- private static final Duration PROFILE_LIFETIME = Duration.ofDays(180);
+ private static final Duration DEFAULT_LIFETIME = Duration.ofDays(180);
private ProfileRequestContext profileRequestCtx;
@@ -54,8 +55,6 @@ public class ResolveCredentialLifetimeTest {
protected void setUp() throws Exception {
requestCtx = new RequestContextBuilder().buildRequestContext();
profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
- profileRequestCtx.ensureSubcontext(RelyingPartyContext.class)
- .setProfileConfig(new DefaultOpenIDVCICredentialsConfiguration());
profileRequestCtx.setInboundMessageContext(new MessageContext());
action = new ResolveCredentialLifetime();
@@ -83,7 +82,7 @@ public class ResolveCredentialLifetimeTest {
Assert.assertNotNull(ctx.getIssuedAt());
// Nothing states a start, so there is no window to announce beyond 'iat'.
Assert.assertEquals(ctx.getNotBefore(), ctx.getIssuedAt());
- Assert.assertEquals(ctx.getExpiresAt(), ctx.getIssuedAt().plus(PROFILE_LIFETIME));
+ Assert.assertEquals(ctx.getExpiresAt(), ctx.getIssuedAt().plus(DEFAULT_LIFETIME));
}
@Test
@@ -106,12 +105,12 @@ public class ResolveCredentialLifetimeTest {
action.initialize();
credentialWith("{\"lifetime\":\"PT1M\"}");
- ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.VALIDITY_WINDOW_CLOSED);
Assert.assertNull(resolved().getExpiresAt());
}
@Test
- public void testCredentialLifetimeOverridesTheProfileConfiguration() throws Exception {
+ public void testCredentialLifetimeOverridesTheDefault() throws Exception {
credentialWith("{\"lifetime\":\"P7D\"}");
ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
@@ -145,16 +144,16 @@ public class ResolveCredentialLifetimeTest {
}
@Test
- public void testFixedStartWithoutALifetimeTakesTheProfileOne() throws Exception {
+ public void testFixedStartWithoutALifetimeTakesTheDefault() throws Exception {
credentialWith("{\"not_before\":\"2020-01-01\"}");
- ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.VALIDITY_WINDOW_CLOSED);
Assert.assertNull(resolved().getExpiresAt());
}
@Test
public void testClosedWindowIssuesNothing() throws Exception {
credentialWith("{\"lifetime\":\"P1D\",\"not_before\":\"2020-01-01\"}");
- ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.VALIDITY_WINDOW_CLOSED);
final CredentialsContext ctx = resolved();
Assert.assertNull(ctx.getIssuedAt());
Assert.assertNull(ctx.getNotBefore());
@@ -162,10 +161,55 @@ public class ResolveCredentialLifetimeTest {
}
@Test
- public void testNoRelyingPartyContext() throws Exception {
+ public void testDefaultLifetimeOfTheStrategy() throws Exception {
+ final CredentialLifetimeLookupFunction lifetime = new CredentialLifetimeLookupFunction();
+ lifetime.setDefaultLifetime(Duration.ofDays(30));
+ action = new ResolveCredentialLifetime();
+ action.setLifetimeLookupStrategy(lifetime);
+ action.initialize();
+ credentialWith(null);
+
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+ final CredentialsContext ctx = resolved();
+ Assert.assertEquals(ctx.getExpiresAt(), ctx.getIssuedAt().plus(Duration.ofDays(30)));
+ }
+
+ @Test
+ public void testStrategiesReplaceTheCredentialConfiguration() throws Exception {
+ action = new ResolveCredentialLifetime();
+ action.setLifetimeLookupStrategy(prc -> Duration.ofDays(2));
+ action.setValidityStartLookupStrategy(prc -> ValidityStart.parse("P1D"));
+ action.initialize();
+ credentialWith("{\"lifetime\":\"P7D\",\"not_before\":\"P30D\"}");
+
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+
+ final CredentialsContext ctx = resolved();
+ Assert.assertEquals(ctx.getNotBefore(), ctx.getIssuedAt().plus(Duration.ofDays(1)));
+ Assert.assertEquals(ctx.getExpiresAt(), ctx.getNotBefore().plus(Duration.ofDays(2)));
+ }
+
+ @Test
+ public void testNoLifetimeFromTheStrategy() throws Exception {
+ action = new ResolveCredentialLifetime();
+ action.setLifetimeLookupStrategy(prc -> null);
+ action.initialize();
+ credentialWith(null);
+
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+ Assert.assertNull(resolved().getExpiresAt());
+ }
+
+ @Test
+ public void testNegativeLifetimeFromTheStrategy() throws Exception {
+ action = new ResolveCredentialLifetime();
+ action.setLifetimeLookupStrategy(prc -> Duration.ofDays(-1));
+ action.initialize();
credentialWith(null);
- profileRequestCtx.removeSubcontext(RelyingPartyContext.class);
- ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_RELYING_PARTY_CTX);
+
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+ Assert.assertNull(resolved().getExpiresAt());
}
@Test
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOfferValidityTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOfferValidityTest.java
new file mode 100644
index 0000000..a6aa95b
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateCredentialOfferValidityTest.java
@@ -0,0 +1,183 @@
+/*
+ * 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.time.Duration;
+import java.time.Instant;
+import java.util.Map;
+
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
+import org.geant.shibboleth.plugin.openidvci.credential.impl.FilesystemCredentialConfigurationsResolver;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialOfferContext;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialDataset;
+import org.geant.shibboleth.plugin.openidvci.profile.OpenIDVCIEventIds;
+import org.geant.shibboleth.plugin.openidvci.profile.config.impl.DefaultOpenIDVCICredentialOfferConfiguration;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+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;
+
+/**
+ * Unit tests for {@link ValidateCredentialOfferValidity}.
+ */
+public class ValidateCredentialOfferValidityTest {
+
+ private static final String CLAIMS = "[{\"path\":[\"mail\"],\"value\":\"user at example.org\"}]";
+
+ private ProfileRequestContext profileRequestCtx;
+
+ private RequestContext requestCtx;
+
+ private DefaultOpenIDVCICredentialOfferConfiguration configuration;
+
+ private ValidateCredentialOfferValidity action;
+
+ @BeforeMethod
+ protected void setUp() throws Exception {
+ requestCtx = new RequestContextBuilder().buildRequestContext();
+ profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+ configuration = new DefaultOpenIDVCICredentialOfferConfiguration();
+ profileRequestCtx.ensureSubcontext(RelyingPartyContext.class).setProfileConfig(configuration);
+ profileRequestCtx.setInboundMessageContext(new MessageContext());
+ action = newAction(null);
+ }
+
+ private ValidateCredentialOfferValidity newAction(final Duration defaultLifetime) throws Exception {
+ final FilesystemCredentialConfigurationsResolver resolver = new FilesystemCredentialConfigurationsResolver(
+ new ClassPathResource("conf/verifiable-credentials.json"));
+ resolver.setId("test");
+ resolver.initialize();
+ final ValidateCredentialOfferValidity validity = new ValidateCredentialOfferValidity();
+ validity.setCredentialConfigurationsResolver(resolver);
+ if (defaultLifetime != null) {
+ validity.setDefaultCredentialLifetime(defaultLifetime);
+ }
+ validity.initialize();
+ return validity;
+ }
+
+ private void offer(final String configurationId, final String lifetime, final String notBefore)
+ throws Exception {
+ final CredentialOfferContext ctx = new CredentialOfferContext();
+ ctx.setValidatedPreAuthorizedCredentials(Map.of(configurationId, CredentialDataset.parse(CLAIMS)));
+ ctx.setLifetime(lifetime == null ? null : Duration.parse(lifetime));
+ ctx.setNotBefore(notBefore == null ? null : ValidityStart.parse(notBefore));
+ profileRequestCtx.getInboundMessageContext().addSubcontext(ctx, true);
+ }
+
+ @Test
+ public void testNoWindowStated() throws Exception {
+ offer("GeantIncubatorDiploma", null, null);
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ }
+
+ @Test
+ public void testNotAllowed() throws Exception {
+ offer("GeantIncubatorDiploma", "P3D", null);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.INVALID_VALIDITY_WINDOW);
+ }
+
+ @Test
+ public void testAllowed() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ offer("GeantIncubatorDiploma", "P3D", "2099-09-14T08:00Z");
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ }
+
+ @Test
+ public void testWithinMaximum() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ configuration.setMaxCredentialLifetime(Duration.ofDays(3));
+ offer("GeantIncubatorDiploma", "P3D", null);
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ }
+
+ @Test
+ public void testLongerThanMaximum() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ configuration.setMaxCredentialLifetime(Duration.ofDays(3));
+ offer("GeantIncubatorDiploma", "P4D", null);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.INVALID_VALIDITY_WINDOW);
+ }
+
+ @Test
+ public void testMaximumDoesNotCapTheConfiguration() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ configuration.setMaxCredentialLifetime(Duration.ofDays(3));
+ offer("GeantIncubatorDiploma", null, "P1D");
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ }
+
+ @Test
+ public void testClosedWindow() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ offer("GeantIncubatorDiploma", "P1D", "2020-01-01");
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.INVALID_VALIDITY_WINDOW);
+ }
+
+ @Test
+ public void testWindowClosingBeforeTheCodeExpires() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ final Instant start = Instant.now().minus(Duration.ofDays(1));
+ offer("GeantIncubatorDiploma", "PT24H5M", start.toString());
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.INVALID_VALIDITY_WINDOW);
+ }
+
+ @Test
+ public void testOffsetWindowNeverClosedAtIssuance() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ offer("GeantIncubatorDiploma", "PT1M", "P1D");
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ }
+
+ @Test
+ public void testNotBeforeOnlyTakesTheConfigurationLifetime() throws Exception {
+ configuration.setAllowValidityWindow(true);
+ offer("GeantIncubatorDiploma", null, "2020-01-01");
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), OpenIDVCIEventIds.INVALID_VALIDITY_WINDOW);
+ }
+
+ @Test
+ public void testNotBeforeOnlyTakesTheDefaultLifetime() throws Exception {
+ action = newAction(Duration.ofDays(36500));
+ configuration.setAllowValidityWindow(true);
+ offer("GeantIncubatorDiploma2", null, "2020-01-01");
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ }
+
+ @Test
+ public void testNoRelyingPartyContext() throws Exception {
+ offer("GeantIncubatorDiploma", null, null);
+ profileRequestCtx.removeSubcontext(RelyingPartyContext.class);
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_RELYING_PARTY_CTX);
+ }
+
+ @Test
+ public void testNoOfferContext() throws Exception {
+ ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+ }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredentialTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredentialTest.java
index 58aab10..f84f124 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredentialTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/ValidateRequestedCredentialTest.java
@@ -17,6 +17,7 @@
package org.geant.shibboleth.plugin.openidvci.profile.impl;
import java.net.URI;
+import java.time.Duration;
import java.time.Instant;
import java.util.Map;
@@ -110,6 +111,37 @@ public class ValidateRequestedCredentialTest {
CredentialDataset.DATASET_ID, datasetId);
}
+ @Test
+ public void testValidityWindowOfTheGrant() throws Exception {
+ setRequest("{\"credential_configuration_id\":\"GeantIncubatorDiploma\"}");
+ final AccessTokenClaimsSet.Builder builder = new AccessTokenClaimsSet.Builder();
+ builder.setJWTID("jti").setClientID(new ClientID("client")).setIssuer("issuer").setPrincipal("principal")
+ .setSubject("subject").setIssuedAt(Instant.now()).setExpiresAt(Instant.now().plusSeconds(60))
+ .setAuthenticationTime(Instant.now());
+ builder.addCustomClaim(OpenIDVCITokenManipulationStrategy.POTENTIAL_CLAIMS,
+ Map.of("GeantIncubatorDiploma", CONTENT));
+ builder.addCustomClaim(OpenIDVCITokenManipulationStrategy.VALIDITY_WINDOW,
+ Map.of("lifetime", "PT72H", "not_before", "2026-09-14"));
+ profileRequestCtx.getOutboundMessageContext().ensureSubcontext(OIDCAuthenticationResponseContext.class)
+ .setAuthorizationGrantClaimsSet(builder.build());
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ final CredentialsContext ctx = profileRequestCtx.getInboundMessageContext()
+ .getSubcontext(CredentialsContext.class);
+ Assert.assertEquals(ctx.getRequestedLifetime(), Duration.ofDays(3));
+ Assert.assertEquals(ctx.getRequestedValidityStart().getFixed(), Instant.parse("2026-09-14T00:00:00Z"));
+ }
+
+ @Test
+ public void testNoValidityWindowInTheGrant() throws Exception {
+ setRequest("{\"credential_configuration_id\":\"GeantIncubatorDiploma\"}");
+ setGrant(Map.of("GeantIncubatorDiploma", CONTENT), null);
+ ActionTestingSupport.assertProceedEvent(action.execute(requestCtx));
+ final CredentialsContext ctx = profileRequestCtx.getInboundMessageContext()
+ .getSubcontext(CredentialsContext.class);
+ Assert.assertNull(ctx.getRequestedLifetime());
+ Assert.assertNull(ctx.getRequestedValidityStart());
+ }
+
@Test
public void testConfigurationId() throws Exception {
setRequest("{\"credential_configuration_id\":\"GeantIncubatorDiploma\"}");
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialLifetimeLookupFunctionTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialLifetimeLookupFunctionTest.java
new file mode 100644
index 0000000..f615f3e
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialLifetimeLookupFunctionTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.logic;
+
+import java.time.Duration;
+
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for {@link CredentialLifetimeLookupFunction}.
+ */
+public class CredentialLifetimeLookupFunctionTest {
+
+ private final CredentialLifetimeLookupFunction lookup = new CredentialLifetimeLookupFunction();
+
+ private ProfileRequestContext credentialWith(final String settings) throws Exception {
+ final String configuration = "{\"format\":\"dc+sd-jwt\",\"vct\":\"Diploma\""
+ + (settings == null ? "" : ",\"_issuance_configuration\":" + settings) + "}";
+ final ProfileRequestContext prc = new ProfileRequestContext();
+ prc.setInboundMessageContext(new MessageContext());
+ prc.getInboundMessageContext().ensureSubcontext(CredentialsContext.class)
+ .setCredentialConfiguration(CredentialConfiguration.parse(configuration));
+ return prc;
+ }
+
+ @Test
+ public void testLifetimeOfTheCredentialConfiguration() throws Exception {
+ Assert.assertEquals(lookup.apply(credentialWith("{\"lifetime\":\"P7D\"}")), Duration.ofDays(7));
+ }
+
+ @Test
+ public void testDefaultWhenTheCredentialConfigurationStatesNone() throws Exception {
+ Assert.assertEquals(lookup.apply(credentialWith(null)), Duration.ofDays(180));
+ Assert.assertEquals(lookup.apply(credentialWith("{\"not_before\":\"P1D\"}")), Duration.ofDays(180));
+ }
+
+ @Test
+ public void testDefaultSet() throws Exception {
+ final CredentialLifetimeLookupFunction custom = new CredentialLifetimeLookupFunction();
+ custom.setDefaultLifetime(Duration.ofDays(30));
+ Assert.assertEquals(custom.apply(credentialWith(null)), Duration.ofDays(30));
+ }
+
+ @Test
+ public void testLifetimeOfTheOfferedDataset() throws Exception {
+ final ProfileRequestContext prc = credentialWith("{\"lifetime\":\"P7D\"}");
+ prc.getInboundMessageContext().getSubcontext(CredentialsContext.class).setRequestedLifetime(Duration.ofDays(3));
+ Assert.assertEquals(lookup.apply(prc), Duration.ofDays(3));
+ }
+
+ @Test
+ public void testNoContexts() {
+ Assert.assertEquals(lookup.apply(new ProfileRequestContext()), Duration.ofDays(180));
+ Assert.assertEquals(lookup.apply(null), Duration.ofDays(180));
+ }
+
+ @Test(expectedExceptions = Exception.class)
+ public void testNonPositiveDefault() {
+ new CredentialLifetimeLookupFunction().setDefaultLifetime(Duration.ZERO);
+ }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialValidityStartLookupFunctionTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialValidityStartLookupFunctionTest.java
new file mode 100644
index 0000000..392f105
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialValidityStartLookupFunctionTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.logic;
+
+import java.time.Instant;
+
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for {@link CredentialValidityStartLookupFunction}.
+ */
+public class CredentialValidityStartLookupFunctionTest {
+
+ private final CredentialValidityStartLookupFunction lookup = new CredentialValidityStartLookupFunction();
+
+ private ProfileRequestContext credentialWith(final String settings) throws Exception {
+ final String configuration = "{\"format\":\"dc+sd-jwt\",\"vct\":\"Diploma\""
+ + (settings == null ? "" : ",\"_issuance_configuration\":" + settings) + "}";
+ final ProfileRequestContext prc = new ProfileRequestContext();
+ prc.setInboundMessageContext(new MessageContext());
+ prc.getInboundMessageContext().ensureSubcontext(CredentialsContext.class)
+ .setCredentialConfiguration(CredentialConfiguration.parse(configuration));
+ return prc;
+ }
+
+ @Test
+ public void testStartOfTheCredentialConfiguration() throws Exception {
+ final ValidityStart start = lookup.apply(credentialWith("{\"not_before\":\"2026-08-01\"}"));
+ Assert.assertNotNull(start);
+ Assert.assertEquals(start.getFixed(), Instant.parse("2026-08-01T00:00:00Z"));
+ }
+
+ @Test
+ public void testNoStartStated() throws Exception {
+ Assert.assertNull(lookup.apply(credentialWith(null)));
+ Assert.assertNull(lookup.apply(credentialWith("{\"lifetime\":\"P7D\"}")));
+ }
+
+ @Test
+ public void testStartOfTheOfferedDataset() throws Exception {
+ final ProfileRequestContext prc = credentialWith("{\"not_before\":\"2026-08-01\"}");
+ prc.getInboundMessageContext().getSubcontext(CredentialsContext.class)
+ .setRequestedValidityStart(ValidityStart.parse("2026-09-14T08:00Z"));
+ Assert.assertEquals(lookup.apply(prc).getFixed(), Instant.parse("2026-09-14T08:00:00Z"));
+ }
+
+ @Test
+ public void testNoContexts() {
+ Assert.assertNull(lookup.apply(new ProfileRequestContext()));
+ Assert.assertNull(lookup.apply(null));
+ }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategyTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategyTest.java
index 13ed978..15ba3e4 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategyTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/OpenIDVCITokenManipulationStrategyTest.java
@@ -18,10 +18,14 @@ package org.geant.shibboleth.plugin.openidvci.profile.logic;
import java.net.URI;
import java.net.URISyntaxException;
+import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.TokenContext;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.OpenIDVCITokenRequest;
+import org.geant.shibboleth.plugin.openidvci.storage.CredentialOfferObject;
import org.opensaml.messaging.context.MessageContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.testng.Assert;
@@ -31,6 +35,8 @@ import org.testng.annotations.Test;
import com.nimbusds.common.contenttype.ContentType;
import com.nimbusds.oauth2.sdk.ParseException;
import com.nimbusds.oauth2.sdk.http.HTTPRequest;
+import com.nimbusds.oauth2.sdk.id.ClientID;
+import com.nimbusds.openid.connect.sdk.claims.ClaimsSet;
/**
* Tests for the client instance key of {@link OpenIDVCITokenManipulationStrategy}.
@@ -66,6 +72,26 @@ public class OpenIDVCITokenManipulationStrategyTest {
.containsKey(OpenIDVCITokenManipulationStrategy.CLIENT_INSTANCE_KEY));
}
+ @Test
+ public void validityWindowOfTheOffer() {
+ final TokenContext tokenContext = prc.getInboundMessageContext().ensureSubcontext(TokenContext.class);
+ tokenContext.setPotentialCredentials(new ClaimsSet());
+ tokenContext.setCredentialOfferObject(new CredentialOfferObject(new ClientID("caller"), null, null, null,
+ Duration.ofDays(3), ValidityStart.parse("2026-09-14")));
+ final Map<String, Object> claims = new OpenIDVCITokenManipulationStrategy().apply(prc, new HashMap<>());
+ Assert.assertEquals(claims.get(OpenIDVCITokenManipulationStrategy.VALIDITY_WINDOW),
+ Map.of("lifetime", "PT72H", "not_before", "2026-09-14"));
+ }
+
+ @Test
+ public void noValidityWindowInTheOffer() {
+ final TokenContext tokenContext = prc.getInboundMessageContext().ensureSubcontext(TokenContext.class);
+ tokenContext.setPotentialCredentials(new ClaimsSet());
+ tokenContext.setCredentialOfferObject(new CredentialOfferObject(new ClientID("caller"), null, null, null));
+ Assert.assertFalse(new OpenIDVCITokenManipulationStrategy().apply(prc, new HashMap<>())
+ .containsKey(OpenIDVCITokenManipulationStrategy.VALIDITY_WINDOW));
+ }
+
@Test
public void noStrategy() {
Assert.assertFalse(new OpenIDVCITokenManipulationStrategy().apply(prc, new HashMap<>())
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObjectTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObjectTest.java
index 7b8fdd5..5b2df27 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObjectTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/storage/CredentialOfferObjectTest.java
@@ -18,8 +18,11 @@ package org.geant.shibboleth.plugin.openidvci.storage;
import java.net.URI;
import java.net.URISyntaxException;
+import java.time.Duration;
+import java.time.Instant;
import java.util.Arrays;
+import org.geant.shibboleth.plugin.openidvci.credential.ValidityStart;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferTxCode;
import org.testng.Assert;
@@ -56,6 +59,17 @@ public class CredentialOfferObjectTest {
Assert.assertEquals(parsedObject.getPreAuthorizedCredentials().get("GeantIncubatorSdJwt2").get(0).getContent().getRequestedCredential()
.get(0).getValue(), "incubatorUser at example.org");
Assert.assertEquals(parsedObject.getCredentialOfferTxCode().getValue(), "12345");
+ Assert.assertNull(parsedObject.getLifetime());
+ Assert.assertNull(parsedObject.getNotBefore());
}
+
+ @Test
+ public void testValidityWindow() throws JsonProcessingException, ParseException {
+ object = new CredentialOfferObject(new ClientID("clientID_XYZ"), null, null, null, Duration.ofDays(3),
+ ValidityStart.parse("2026-09-14T08:00Z"));
+ final CredentialOfferObject parsedObject = CredentialOfferObject.parse(object.serialize());
+ Assert.assertEquals(parsedObject.getLifetime(), Duration.ofDays(3));
+ Assert.assertEquals(parsedObject.getNotBefore().getFixed(), Instant.parse("2026-09-14T08:00:00Z"));
+ }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list