forked from eclipse-tractusx/managed-identity-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(identity-trust)!: update IATP protocol
BREAKING CHANGE: `/api/presentations/iatp` endpoint now accepts PresentationQueryMessage and returns PresentationResponseMessage objects. Signed-off-by: Dominik Pinsel <[email protected]>
- Loading branch information
1 parent
9b3381d
commit e3c5450
Showing
14 changed files
with
798 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ain/java/org/eclipse/tractusx/managedidentitywallets/dto/PresentationResponseMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* ******************************************************************************* | ||
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* ****************************************************************************** | ||
*/ | ||
|
||
package org.eclipse.tractusx.managedidentitywallets.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Getter; | ||
import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentation; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Class to represent the response message of a presentation request. | ||
* Defined in JsonLD Tractus-X <a href="https://github.com/eclipse-tractusx/identity-trust/blob/main/specifications/context.json">context.json</a>. | ||
* <p> | ||
* As `presentationSubmission` a not well-defined, we will just skip the property for HTTP responses. Defining all types as 'Json' make the whole idea of using Json-Linked-Data a waste of time, but ok. | ||
* <p> | ||
* The `presentation` property is only specified as 'Json'. For this implementation we will assume these are Presentations from ether the <a href="https://www.w3.org/2018/credentials/v1">Verifiable Credential Data Model v1.1</a> or <a href="https://www.w3.org/ns/credentials/v2">Verifiable Credential Data Model v2.0</a>. | ||
*/ | ||
@Getter | ||
public class PresentationResponseMessage { | ||
|
||
|
||
public PresentationResponseMessage(VerifiablePresentation verifiablePresentation) { | ||
this(List.of(verifiablePresentation)); | ||
} | ||
|
||
public PresentationResponseMessage(List<VerifiablePresentation> verifiablePresentations) { | ||
this.verifiablePresentations = verifiablePresentations; | ||
} | ||
|
||
@JsonProperty("@context") | ||
private List<String> contexts = List.of("https://w3id.org/tractusx-trust/v0.8"); | ||
|
||
@JsonProperty("@type") | ||
private List<String> types = List.of("PresentationResponseMessage"); | ||
|
||
@JsonProperty("presentation") | ||
private List<VerifiablePresentation> verifiablePresentations; | ||
} |
79 changes: 79 additions & 0 deletions
79
...rc/main/java/org/eclipse/tractusx/managedidentitywallets/reader/TractusXJsonLdReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* ******************************************************************************* | ||
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* ****************************************************************************** | ||
*/ | ||
|
||
package org.eclipse.tractusx.managedidentitywallets.reader; | ||
|
||
import com.apicatalog.jsonld.JsonLdError; | ||
import com.apicatalog.jsonld.JsonLdOptions; | ||
import com.apicatalog.jsonld.document.JsonDocument; | ||
import com.apicatalog.jsonld.processor.ExpansionProcessor; | ||
import jakarta.json.JsonArray; | ||
import lombok.NonNull; | ||
import org.eclipse.tractusx.managedidentitywallets.utils.ResourceUtil; | ||
import org.eclipse.tractusx.ssi.lib.model.RemoteDocumentLoader; | ||
|
||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
public class TractusXJsonLdReader { | ||
|
||
private static final String TRACTUS_X_CONTEXT_RESOURCE = "jsonld/IdentityMinusTrust.json"; | ||
private static final URI TRACTUS_X_CONTEXT = URI.create("https://w3id.org/tractusx-trust/v0.8"); | ||
private static final URI IDENTITY_FOUNDATION_CREDENTIAL_SUBMISSION_CONTEXT = URI.create("https://identity.foundation/presentation-exchange/submission/v1"); | ||
private static final String IDENTITY_FOUNDATION_CREDENTIAL_SUBMISSION_RESOURCE = "jsonld/identity.foundation.presentation-exchange.submission.v1.json"; | ||
|
||
|
||
private final RemoteDocumentLoader documentLoader = RemoteDocumentLoader.DOCUMENT_LOADER; | ||
|
||
public TractusXJsonLdReader() { | ||
|
||
documentLoader.setEnableLocalCache(true); | ||
|
||
if (!documentLoader.getLocalCache().containsKey(TRACTUS_X_CONTEXT)) { | ||
cacheOfflineResource(TRACTUS_X_CONTEXT_RESOURCE, TRACTUS_X_CONTEXT); | ||
} | ||
if (!documentLoader.getLocalCache().containsKey(IDENTITY_FOUNDATION_CREDENTIAL_SUBMISSION_CONTEXT)) { | ||
cacheOfflineResource(IDENTITY_FOUNDATION_CREDENTIAL_SUBMISSION_RESOURCE, IDENTITY_FOUNDATION_CREDENTIAL_SUBMISSION_CONTEXT); | ||
} | ||
} | ||
|
||
public JsonArray expand(@NonNull final InputStream documentStream) throws JsonLdError { | ||
|
||
final JsonLdOptions jsonLdOptions = new JsonLdOptions(); | ||
jsonLdOptions.setDocumentLoader(documentLoader); | ||
|
||
final JsonDocument document = JsonDocument.of(com.apicatalog.jsonld.http.media.MediaType.JSON_LD, documentStream); | ||
return ExpansionProcessor.expand(document, jsonLdOptions, false); | ||
} | ||
|
||
private void cacheOfflineResource(final String resource, final URI context) { | ||
try { | ||
final InputStream resourceStream = ResourceUtil.getResourceStream(resource); | ||
final JsonDocument identityMinusTrustDocument; | ||
identityMinusTrustDocument = JsonDocument.of(com.apicatalog.jsonld.http.media.MediaType.JSON_LD, resourceStream); | ||
documentLoader.getLocalCache().put(context, identityMinusTrustDocument); | ||
} catch (JsonLdError e) { | ||
// If this ever fails, it is a programming error. Loading of the embedded context resource is checked by Unit Tests. | ||
throw new RuntimeException("Could not parse Tractus-X JsonL-d context from resource. This should never happen. Resource: '%s'".formatted(resource), e); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...org/eclipse/tractusx/managedidentitywallets/reader/TractusXPresentationRequestReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* ******************************************************************************* | ||
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* ****************************************************************************** | ||
*/ | ||
|
||
package org.eclipse.tractusx.managedidentitywallets.reader; | ||
|
||
import com.apicatalog.jsonld.JsonLdError; | ||
import jakarta.json.JsonArray; | ||
import jakarta.json.JsonObject; | ||
import jakarta.json.JsonString; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@Component | ||
public class TractusXPresentationRequestReader extends TractusXJsonLdReader { | ||
|
||
private static final String JSON_LD_TYPE = "@type"; | ||
private static final String JSON_LD_VALUE = "@value"; | ||
private static final String TRACTUS_X_PRESENTATION_QUERY_MESSAGE_TYPE = "https://w3id.org/tractusx-trust/v0.8/PresentationQueryMessage"; | ||
private static final String TRACTUS_X_SCOPE_TYPE = "https://w3id.org/tractusx-trust/v0.8/scope"; | ||
|
||
public List<String> readVerifiableCredentialScopes(InputStream is) throws InvalidPresentationQueryMessageResource { | ||
try { | ||
|
||
final JsonArray jsonArray = expand(is); | ||
|
||
if (jsonArray.size() != 1) { | ||
log.atDebug().addArgument(jsonArray::toString).log("Expanded JSON-LD: {}"); | ||
throw new InvalidPresentationQueryMessageResource("Expected a single JSON object. Found %d".formatted(jsonArray.size())); | ||
} | ||
|
||
var jsonObject = jsonArray.getJsonObject(0); | ||
|
||
final JsonArray typeArray = jsonObject.getJsonArray(JSON_LD_TYPE); | ||
final List<String> types = typeArray.getValuesAs(JsonString.class).stream().map(JsonString::getString).toList(); | ||
if (!types.contains(TRACTUS_X_PRESENTATION_QUERY_MESSAGE_TYPE)) { | ||
log.atDebug().addArgument(jsonArray::toString).log("Expanded JSON-LD: {}"); | ||
throw new InvalidPresentationQueryMessageResource("Unexpected type. Expected %s".formatted(TRACTUS_X_PRESENTATION_QUERY_MESSAGE_TYPE)); | ||
} | ||
|
||
final JsonArray scopes = jsonObject.getJsonArray(TRACTUS_X_SCOPE_TYPE); | ||
return scopes.getValuesAs(JsonObject.class) | ||
.stream() | ||
.map(o -> o.getJsonString(JSON_LD_VALUE)) | ||
.map(JsonString::getString) | ||
.toList(); | ||
|
||
} catch (JsonLdError e) { | ||
throw new InvalidPresentationQueryMessageResource(e); | ||
} | ||
} | ||
|
||
public static class InvalidPresentationQueryMessageResource extends Exception { | ||
public InvalidPresentationQueryMessageResource(String message) { | ||
super(message); | ||
} | ||
|
||
public InvalidPresentationQueryMessageResource(Throwable cause) { | ||
super(cause); | ||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.