Skip to content

Commit

Permalink
PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Oct 25, 2023
1 parent 035c9d4 commit 6a5a3a8
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.edc.identityservice.api.v1.PresentationApiController;
import org.eclipse.edc.identityservice.api.validation.PresentationQueryValidator;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
Expand All @@ -35,12 +36,17 @@

import java.net.URISyntaxException;

import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.IATP_CONTEXT_URL;
import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.PRESENTATION_EXCHANGE_URL;
import static org.eclipse.edc.spi.CoreConstants.JSON_LD;

@Extension(value = "Presentation API Extension")
public class PresentationApiExtension implements ServiceExtension {

public static final String RESOLUTION_SCOPE = "resolution-scope";
public static final String RESOLUTION_CONTEXT = "resolution";
public static final String PRESENTATION_EXCHANGE_V_1_JSON = "presentation-exchange.v1.json";
public static final String PRESENTATION_QUERY_V_08_JSON = "presentation-query.v08.json";
@Inject
private TypeTransformerRegistry typeTransformer;

Expand Down Expand Up @@ -72,7 +78,7 @@ public void initialize(ServiceExtensionContext context) {


// Setup API
cacheContextDocuments();
cacheContextDocuments(getClass().getClassLoader());
var controller = new PresentationApiController(validatorRegistry, typeTransformer, credentialResolver, accessTokenVerifier, presentationGenerator, context.getMonitor());

var jsonLdMapper = typeManager.getMapper(JSON_LD);
Expand All @@ -85,10 +91,10 @@ public void initialize(ServiceExtensionContext context) {
typeTransformer.register(new JsonValueToGenericTypeTransformer(jsonLdMapper));
}

private void cacheContextDocuments() {
private void cacheContextDocuments(ClassLoader classLoader) {
try {
jsonLd.registerCachedDocument("https://identity.foundation/presentation-exchange/submission/v1", Thread.currentThread().getContextClassLoader().getResource("presentation-exchange.v1.json").toURI());
jsonLd.registerCachedDocument("https://w3id.org/tractusx-trust/v0.8", Thread.currentThread().getContextClassLoader().getResource("presentation-query.v08.json").toURI());
jsonLd.registerCachedDocument(PRESENTATION_EXCHANGE_URL, classLoader.getResource(PRESENTATION_EXCHANGE_V_1_JSON).toURI());
jsonLd.registerCachedDocument(IATP_CONTEXT_URL, classLoader.getResource(PRESENTATION_QUERY_V_08_JSON).toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class PresentationApiController implements PresentationApi {
private final PresentationGenerator presentationGenerator;
private final Monitor monitor;

public PresentationApiController(JsonObjectValidatorRegistry validatorRegistry, TypeTransformerRegistry transformerRegistry, CredentialQueryResolver queryResolver, AccessTokenVerifier accessTokenVerifier,
PresentationGenerator presentationGenerator, Monitor monitor) {
public PresentationApiController(JsonObjectValidatorRegistry validatorRegistry, TypeTransformerRegistry transformerRegistry, CredentialQueryResolver queryResolver,
AccessTokenVerifier accessTokenVerifier, PresentationGenerator presentationGenerator, Monitor monitor) {
this.validatorRegistry = validatorRegistry;
this.transformerRegistry = transformerRegistry;
this.queryResolver = queryResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Transforms a JsonObject into a PresentationQuery object.
*/
public class JsonObjectToPresentationQueryTransformer extends AbstractJsonLdTransformer<JsonObject, PresentationQuery> {

private final ObjectMapper mapper;
Expand All @@ -41,16 +44,16 @@ public JsonObjectToPresentationQueryTransformer(ObjectMapper mapper) {
var bldr = PresentationQuery.Builder.newinstance();
visitProperties(jsonObject, (k, v) -> {
switch (k) {
case PresentationQuery.PRESENTATION_QUERY_DEFINITION_PROPERTY -> bldr.presentationDefinition(readPresentationDefinition(v));
case PresentationQuery.PRESENTATION_QUERY_DEFINITION_PROPERTY -> bldr.presentationDefinition(readPresentationDefinition(v, context));
case PresentationQuery.PRESENTATION_QUERY_SCOPE_PROPERTY -> transformArrayOrObject(v, Object.class, o -> bldr.scope(o.toString()), context);
default -> context.reportProblem("unknown property '%s'".formatted(k));
default -> context.reportProblem("Unknown property '%s'".formatted(k));
}
});

return bldr.build();
}

private PresentationDefinition readPresentationDefinition(JsonValue v) {
private PresentationDefinition readPresentationDefinition(JsonValue v, TransformerContext context) {
JsonObject jo;
if (v.getValueType() == JsonValue.ValueType.ARRAY && !((JsonArray) v).isEmpty()) {
jo = v.asJsonArray().getJsonObject(0);
Expand All @@ -61,6 +64,7 @@ private PresentationDefinition readPresentationDefinition(JsonValue v) {
try {
return mapper.readValue(rawJson.toString(), PresentationDefinition.class);
} catch (JsonProcessingException e) {
context.reportProblem("Error reading JSON literal: %s".formatted(e.getMessage()));
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.edc.identityhub.spi.model.PresentationSubmission;
import org.eclipse.edc.identityhub.spi.resolution.CredentialQueryResolver;
import org.eclipse.edc.identityhub.spi.verification.AccessTokenVerifier;
import org.eclipse.edc.identityhub.tests.fixtures.IdentityHubParticipant;
import org.eclipse.edc.identityhub.tests.fixtures.IdentityHubRuntimeConfiguration;
import org.eclipse.edc.identityhub.tests.fixtures.TestData;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
Expand Down Expand Up @@ -61,7 +61,7 @@ public class ResolutionApiEndToEndTest {
]
}
""";
protected static final IdentityHubParticipant IDENTITY_HUB_PARTICIPANT = IdentityHubParticipant.Builder.newInstance()
protected static final IdentityHubRuntimeConfiguration IDENTITY_HUB_PARTICIPANT = IdentityHubRuntimeConfiguration.Builder.newInstance()
.name("identity-hub")
.id("identity-hub")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort;
import static org.eclipse.edc.spi.system.ServiceExtensionContext.PARTICIPANT_ID;

public class IdentityHubParticipant {
/**
* The IdentityHubRuntimeConfiguration class represents an IdentityHub Runtime configuration and provides various information, such as API endpoints
*/
public class IdentityHubRuntimeConfiguration {

private Endpoint resolutionEndpoint;
private String id;
Expand All @@ -48,10 +51,10 @@ public Map<String, String> controlPlaneConfiguration() {
}

public static final class Builder {
private final IdentityHubParticipant participant;
private final IdentityHubRuntimeConfiguration participant;

private Builder() {
participant = new IdentityHubParticipant();
participant = new IdentityHubRuntimeConfiguration();
}

public static Builder newInstance() {
Expand All @@ -68,7 +71,7 @@ public Builder name(String name) {
return this;
}

public IdentityHubParticipant build() {
public IdentityHubRuntimeConfiguration build() {
participant.resolutionEndpoint = new Endpoint(URI.create("http://localhost:" + getFreePort() + "/api/v1/resolution"), Map.of());
return participant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
package org.eclipse.edc.identityhub.spi.model;

public interface IdentityHubConstants {
String IATP_NAMESPACE = "https://w3id.org/tractusx-trust/v0.8/";
String IATP_PREFIX = "https://w3id.org/tractusx-trust/v0.8/";
String IATP_CONTEXT_URL = "https://w3id.org/tractusx-trust/v0.8";
String PRESENTATION_EXCHANGE_URL = "https://identity.foundation/presentation-exchange/submission/v1";

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
import java.util.ArrayList;
import java.util.List;

import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.IATP_NAMESPACE;
import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.IATP_PREFIX;


/**
* Represents a query that is sent to a CredentialService.
*
* @see <a href="https://github.com/eclipse-tractusx/identity-trust/blob/main/specifications/M1/verifiable.presentation.protocol.md#411-query-for-presentations">IATP Specification</a>
*/
public class PresentationQuery {
public static final String PRESENTATION_QUERY_SCOPE_PROPERTY = IATP_NAMESPACE + "scope";
public static final String PRESENTATION_QUERY_DEFINITION_PROPERTY = IATP_NAMESPACE + "presentation_definition";
public static final String PRESENTATION_QUERY_TYPE_PROPERTY = IATP_NAMESPACE + "Query";
public static final String PRESENTATION_QUERY_SCOPE_PROPERTY = IATP_PREFIX + "scope";
public static final String PRESENTATION_QUERY_DEFINITION_PROPERTY = IATP_PREFIX + "presentation_definition";
public static final String PRESENTATION_QUERY_TYPE_PROPERTY = IATP_PREFIX + "Query";
private List<String> scopes = new ArrayList<>();
private PresentationDefinition presentationDefinition;

Expand Down

0 comments on commit 6a5a3a8

Please sign in to comment.