Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidonos committed Nov 16, 2023
2 parents b1567fc + dd99058 commit d8a378a
Show file tree
Hide file tree
Showing 56 changed files with 1,104 additions and 287 deletions.
3 changes: 3 additions & 0 deletions .github/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ changelog:
labels:
- no-changelog
categories:
- title: Breaking changes
labels:
- breaking-change
- title: Bugfixes
labels:
- bug
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Contains implementations for communication protocols a connector might use, such
## Releases

GitHub releases are listed [here](https://github.com/eclipse-edc/Connector/releases).
Please find more information about releases in our [release approach](https://github.com/eclipse-edc/.github/blob/main/docs/developer/releases.md).
Please find more information about releases in our [release approach](https://github.com/eclipse-edc/docs/blob/main/developer/releases.md).

### Roadmap

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private TransferRequest createTransferRequest() {
.assetId("assetId")
.dataDestination(DataAddress.Builder.newInstance().type("any").build())
.protocol("test")
.connectorAddress("http://an/address")
.counterPartyAddress("http://an/address")
.contractId("contractId")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public StatusResult<TransferProcess> initiateConsumerRequest(TransferRequest tra
.assetId(transferRequest.getAssetId())
.connectorId(transferRequest.getConnectorId())
.dataDestination(transferRequest.getDataDestination())
.connectorAddress(transferRequest.getConnectorAddress())
.connectorAddress(transferRequest.getCounterPartyAddress())
.contractId(transferRequest.getContractId())
.destinationType(transferRequest.getDataDestination().getType())
.protocol(transferRequest.getProtocol())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.runtime.metamodel.annotation.Setting;
import org.eclipse.edc.spi.http.EdcHttpClient;
import org.eclipse.edc.spi.iam.IdentityService;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.verifiablecredentials.jwt.JwtPresentationVerifier;
import org.eclipse.edc.verifiablecredentials.linkeddata.LdpVerifier;
import org.eclipse.edc.verification.jwt.SelfIssuedIdTokenVerifier;
Expand All @@ -51,8 +53,6 @@ public class IdentityAndTrustExtension implements ServiceExtension {
@Inject
private SecureTokenService secureTokenService;

@Inject
private PresentationVerifier presentationVerifier;

@Inject
private CredentialServiceClient credentialServiceClient;
Expand All @@ -72,14 +72,22 @@ public class IdentityAndTrustExtension implements ServiceExtension {
@Inject
private JsonLd jsonLd;

private JwtValidator jwtValidator;
private JwtVerifier jwtVerifier;
@Inject
private Clock clock;

@Inject
private TypeTransformerRegistry typeTransformerRegistry;

@Inject
private EdcHttpClient httpClient;

private JwtValidator jwtValidator;
private JwtVerifier jwtVerifier;
private PresentationVerifier presentationVerifier;

@Provider
public IdentityService createIdentityService(ServiceExtensionContext context) {
return new IdentityAndTrustService(secureTokenService, getIssuerDid(context), context.getParticipantId(), presentationVerifier,
return new IdentityAndTrustService(secureTokenService, getIssuerDid(context), context.getParticipantId(), getPresentationVerifier(context),
credentialServiceClient, getJwtValidator(), getJwtVerifier(), registry, clock);
}

Expand All @@ -92,17 +100,20 @@ public JwtValidator getJwtValidator() {
}

@Provider
public PresentationVerifier createPresentationVerifier(ServiceExtensionContext context) {
var mapper = typeManager.getMapper(JSON_LD);

var jwtVerifier = new JwtPresentationVerifier(getJwtVerifier(), mapper);
var ldpVerifier = LdpVerifier.Builder.newInstance()
.signatureSuites(signatureSuiteRegistry)
.jsonLd(jsonLd)
.objectMapper(mapper)
.build();

return new MultiFormatPresentationVerifier(getOwnDid(context), jwtVerifier, ldpVerifier);
public PresentationVerifier getPresentationVerifier(ServiceExtensionContext context) {
if (presentationVerifier == null) {
var mapper = typeManager.getMapper(JSON_LD);

var jwtVerifier = new JwtPresentationVerifier(getJwtVerifier(), mapper);
var ldpVerifier = LdpVerifier.Builder.newInstance()
.signatureSuites(signatureSuiteRegistry)
.jsonLd(jsonLd)
.objectMapper(mapper)
.build();

presentationVerifier = new MultiFormatPresentationVerifier(getOwnDid(context), jwtVerifier, ldpVerifier);
}
return presentationVerifier;
}

@Provider
Expand All @@ -113,6 +124,12 @@ public JwtVerifier getJwtVerifier() {
return jwtVerifier;
}

@Provider
public CredentialServiceClient createClient(ServiceExtensionContext context) {
context.getMonitor().warning("Using a dummy CredentialServiceClient, that'll return null always. Don't use this in production use cases!");
return (csUrl, siTokenJwt, scopes) -> null;
}

private String getOwnDid(ServiceExtensionContext context) {
// todo: this must be config value
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.types.TypeManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.spi.CoreConstants.JSON_LD;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand All @@ -33,17 +35,19 @@
@ExtendWith(DependencyInjectionExtension.class)
class IdentityAndTrustExtensionTest {

private IdentityAndTrustExtension extension;
private ServiceExtensionContext spiedContext;

@BeforeEach
void setUp(ServiceExtensionContext context) {
spiedContext = spy(context);
spiedContext.registerService(SecureTokenService.class, mock());
TypeManager mockedTm = mock();
when(mockedTm.getMapper(eq(JSON_LD))).thenReturn(mock());
spiedContext.registerService(TypeManager.class, mockedTm);
}

@Test
void verifyCorrectService(IdentityAndTrustExtension extension, ServiceExtensionContext context) {
void verifyCorrectService(IdentityAndTrustExtension extension) {
var configMock = mock(Config.class);
when(configMock.getString(eq(IdentityAndTrustExtension.ISSUER_DID_PROPERTY))).thenReturn("did:web:test");
when(spiedContext.getConfig()).thenReturn(configMock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ public Result<ClaimToken> verifyJwtToken(TokenRepresentation tokenRepresentation
return issuerResult.mapTo();
}

//todo: implement actual VP request, currently it's a stub
// https://github.com/eclipse-edc/Connector/issues/3495
var vpResponse = credentialServiceClient.requestPresentation(null, null, null);

if (vpResponse.failed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {

testImplementation(project(":extensions:common:json-ld"))
testImplementation(project(":core:common:transform-core")) //for the TransformerContextImpl
testImplementation(project(":core:common:junit")) //for the TestUtils
testImplementation(testFixtures(project(":spi:common:identity-trust-spi")))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* 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
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.iam.identitytrust.transform.to;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import org.eclipse.edc.identitytrust.model.credentialservice.PresentationQuery;
import org.eclipse.edc.identitytrust.model.presentationdefinition.PresentationDefinition;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
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;

public JsonObjectToPresentationQueryTransformer(ObjectMapper mapper) {
super(JsonObject.class, PresentationQuery.class);
this.mapper = mapper;
}

@Override
public @Nullable PresentationQuery transform(@NotNull JsonObject jsonObject, @NotNull TransformerContext context) {
var bldr = PresentationQuery.Builder.newinstance();
visitProperties(jsonObject, (k, v) -> {
switch (k) {
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));
}
});

return bldr.build();
}

private PresentationDefinition readPresentationDefinition(JsonValue v, TransformerContext context) {
JsonObject jo;
if (v.getValueType() == JsonValue.ValueType.ARRAY && !((JsonArray) v).isEmpty()) {
jo = v.asJsonArray().getJsonObject(0);
} else {
jo = v.asJsonObject();
}
var rawJson = jo.get(JsonLdKeywords.VALUE);
try {
return mapper.readValue(rawJson.toString(), PresentationDefinition.class);
} catch (JsonProcessingException e) {
context.reportProblem("Error reading JSON literal: %s".formatted(e.getMessage()));
return null;
}
}
}
Loading

0 comments on commit d8a378a

Please sign in to comment.