Skip to content

Commit

Permalink
pr remarks, checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Jul 19, 2024
1 parent e4efc33 commit 089519d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
16 changes: 8 additions & 8 deletions deployment/postman/MVD.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"@type\": \"PolicyDefinitionRequestDto\",\n \"@id\": \"require-membership\",\n \"policy\": {\n \"@type\": \"http://www.w3.org/ns/odrl/2/Set\",\n \"odrl:permission\": [\n {\n \"odrl:action\": \"USE\",\n \"odrl:constraint\": {\n \"@type\": \"LogicalConstraint\",\n \"odrl:leftOperand\": \"MembershipCredential\",\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"active\"\n }\n }\n ]\n }\n}"
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"@type\": \"PolicyDefinitionRequestDto\",\n \"@id\": \"require-membership\",\n \"policy\": {\n \"@type\": \"http://www.w3.org/ns/odrl/2/Set\",\n \"odrl:permission\": [\n {\n \"odrl:action\": \"use\",\n \"odrl:constraint\": {\n \"@type\": \"LogicalConstraint\",\n \"odrl:leftOperand\": \"MembershipCredential\",\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"active\"\n }\n }\n ]\n }\n}"
},
"url": {
"raw": "{{HOST}}/api/management/v3/policydefinitions",
Expand Down Expand Up @@ -124,7 +124,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"@type\": \"PolicyDefinitionRequestDto\",\n \"@id\": \"require-dataprocessor\",\n \"policy\": {\n \"@type\": \"http://www.w3.org/ns/odrl/2/Set\",\n \"odrl:obligation\": [\n {\n \"odrl:action\": \"USE\",\n \"odrl:constraint\": {\n \"@type\": \"LogicalConstraint\",\n \"odrl:leftOperand\": \"DataAccess.level\",\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"processing\"\n }\n }\n ]\n }\n}"
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"@type\": \"PolicyDefinitionRequestDto\",\n \"@id\": \"require-dataprocessor\",\n \"policy\": {\n \"@type\": \"http://www.w3.org/ns/odrl/2/Set\",\n \"odrl:obligation\": [\n {\n \"odrl:action\": \"use\",\n \"odrl:constraint\": {\n \"@type\": \"LogicalConstraint\",\n \"odrl:leftOperand\": \"DataAccess.level\",\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"processing\"\n }\n }\n ]\n }\n}"
},
"url": {
"raw": "{{HOST}}/api/management/v3/policydefinitions",
Expand Down Expand Up @@ -157,7 +157,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"@type\": \"PolicyDefinitionRequestDto\",\n \"@id\": \"require-sensitive\",\n \"policy\": {\n \"@type\": \"http://www.w3.org/ns/odrl/2/Set\",\n \"odrl:obligation\": [\n {\n \"odrl:action\": \"USE\",\n \"odrl:constraint\": {\n \"@type\": \"LogicalConstraint\",\n \"odrl:leftOperand\": \"DataAccess.level\",\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"sensitive\"\n }\n }\n ]\n }\n}"
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"@type\": \"PolicyDefinitionRequestDto\",\n \"@id\": \"require-sensitive\",\n \"policy\": {\n \"@type\": \"http://www.w3.org/ns/odrl/2/Set\",\n \"odrl:obligation\": [\n {\n \"odrl:action\": \"use\",\n \"odrl:constraint\": {\n \"@type\": \"LogicalConstraint\",\n \"odrl:leftOperand\": \"DataAccess.level\",\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"sensitive\"\n }\n }\n ]\n }\n}"
},
"url": {
"raw": "{{HOST}}/api/management/v3/policydefinitions",
Expand Down Expand Up @@ -570,7 +570,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"@context\": {\n \"@vocab\": \"https://w3id.org/edc/v0.0.1/ns/\"\n },\n \"@type\": \"https://w3id.org/edc/v0.0.1/ns/ContractRequest\",\n \"counterPartyAddress\": \"{{PROVIDER_DSP_URL}}/api/dsp\",\n \"counterPartyId\": \"{{PROVIDER_ID}}\",\n \"protocol\": \"dataspace-protocol-http\",\n \"policy\": {\n \"@context\": \"http://www.w3.org/ns/odrl.jsonld\",\n \"@type\": \"http://www.w3.org/ns/odrl/2/Offer\",\n \"@id\": \"bWVtYmVyLWFuZC1kYXRhcHJvY2Vzc29yLWRlZg==:YXNzZXQtMQ==:NDFiMWQzZDUtOTA0OS00ZGRmLTk5MDEtNTYxOTVhYmQzNjNj\",\n \"assigner\": \"{{PROVIDER_ID}}\",\n \"permission\": [],\n \"prohibition\": [],\n \"odrl:obligation\": {\n \"odrl:action\": {\n \"@id\": \"USE\"\n },\n \"odrl:constraint\": {\n \"odrl:leftOperand\": {\n \"@id\": \"DataAccess.level\"\n },\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"processing\"\n }\n },\n \"target\": \"asset-1\"\n },\n \"callbackAddresses\": []\n}",
"raw": "{\n \"@context\": {\n \"@vocab\": \"https://w3id.org/edc/v0.0.1/ns/\"\n },\n \"@type\": \"https://w3id.org/edc/v0.0.1/ns/ContractRequest\",\n \"counterPartyAddress\": \"{{PROVIDER_DSP_URL}}/api/dsp\",\n \"counterPartyId\": \"{{PROVIDER_ID}}\",\n \"protocol\": \"dataspace-protocol-http\",\n \"policy\": {\n \"@context\": \"http://www.w3.org/ns/odrl.jsonld\",\n \"@type\": \"http://www.w3.org/ns/odrl/2/Offer\",\n \"@id\": \"bWVtYmVyLWFuZC1kYXRhcHJvY2Vzc29yLWRlZg==:YXNzZXQtMQ==:MmQ0ZWZjZTYtYzJjNy00NTM5LTk5ODAtZDAwOTlkZDNkOWQy\",\n \"assigner\": \"{{PROVIDER_ID}}\",\n \"permission\": [],\n \"prohibition\": [],\n \"odrl:obligation\": {\n \"odrl:action\": {\n \"@id\": \"use\"\n },\n \"odrl:constraint\": {\n \"odrl:leftOperand\": {\n \"@id\": \"DataAccess.level\"\n },\n \"odrl:operator\": {\n \"@id\": \"odrl:eq\"\n },\n \"odrl:rightOperand\": \"processing\"\n }\n },\n \"target\": \"asset-1\"\n },\n \"callbackAddresses\": []\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -633,7 +633,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"assetId\": \"asset-1\",\n \"counterPartyAddress\": \"{{PROVIDER_DSP_URL}}/api/dsp\",\n \"connectorId\": \"{{PROVIDER_ID}}\",\n \"contractId\": \"5613c232-d12e-41de-b0d6-befc290e5309\",\n \"dataDestination\": {\n \"type\": \"HttpProxy\"\n },\n \"protocol\": \"dataspace-protocol-http\",\n \"transferType\": \"HttpData-PULL\"\n}",
"raw": "{\n \"@context\": {\n \"odrl\": \"http://www.w3.org/ns/odrl/2/\"\n },\n \"assetId\": \"asset-1\",\n \"counterPartyAddress\": \"{{PROVIDER_DSP_URL}}/api/dsp\",\n \"connectorId\": \"{{PROVIDER_ID}}\",\n \"contractId\": \"47e43627-d9b0-4e35-b534-cef450d7de88\",\n \"dataDestination\": {\n \"type\": \"HttpProxy\"\n },\n \"protocol\": \"dataspace-protocol-http\",\n \"transferType\": \"HttpData-PULL\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -734,7 +734,7 @@
}
],
"url": {
"raw": "{{HOST}}/api/management/v3/edrs/cb60556e-5544-4d37-a5ca-6412b293fc98/dataaddress",
"raw": "{{HOST}}/api/management/v3/edrs/713dfab7-c70a-4c7b-9756-d372647276b5/dataaddress",
"host": [
"{{HOST}}"
],
Expand All @@ -743,7 +743,7 @@
"management",
"v3",
"edrs",
"cb60556e-5544-4d37-a5ca-6412b293fc98",
"713dfab7-c70a-4c7b-9756-d372647276b5",
"dataaddress"
]
}
Expand All @@ -764,7 +764,7 @@
},
{
"key": "Authorization",
"value": "eyJraWQiOiJkaWQ6d2ViOnByb3ZpZGVyLWlkZW50aXR5aHViJTNBNzA4Mzpwcm92aWRlciNrZXktMSIsImFsZyI6IkVTMjU2In0.eyJpc3MiOiJkaWQ6d2ViOnByb3ZpZGVyLWlkZW50aXR5aHViJTNBNzA4Mzpwcm92aWRlciIsImF1ZCI6ImRpZDp3ZWI6Y29uc3VtZXItaWRlbnRpdHlodWIlM0E3MDgzOmNvbnN1bWVyIiwic3ViIjoiZGlkOndlYjpwcm92aWRlci1pZGVudGl0eWh1YiUzQTcwODM6cHJvdmlkZXIiLCJpYXQiOjE3MjExMjUwMTY4NTUsImp0aSI6ImMzODM0YWJmLWE3YjYtNDNmNC05ZWU3LTBjYjIzNzI2NGIzZiJ9.Ok7g_ekPgOuevytQEf3gDaixyUEphTbZa496lUqKYoyS0QIsKsxtYfkbD0tCitUtCkZIgGOIBsq5-A8ia_7UHg",
"value": "eyJraWQiOiJkaWQ6d2ViOmxvY2FsaG9zdCUzQTcwOTMja2V5LTEiLCJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJkaWQ6d2ViOmxvY2FsaG9zdCUzQTcwOTMiLCJhdWQiOiJkaWQ6d2ViOmxvY2FsaG9zdCUzQTcwODMiLCJzdWIiOiJkaWQ6d2ViOmxvY2FsaG9zdCUzQTcwOTMiLCJpYXQiOjE3MjEzOTMxNjU5ODgsImp0aSI6ImFmOWI2YWIyLTMwNjYtNDNlNi1hNjg1LWIyMDVjNTFkZmJhMyJ9.ute0sLuMgc0bzG_ZUGG9G3pliFfANf9pWDxReiRrWjGudgUa4YmR9ftB5LeZTOvKCBJshRpbZX-hnQxR8fXMWA",
"type": "text"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@

package org.eclipse.edc.demo.dcp.policy;

import org.eclipse.edc.iam.verifiablecredentials.spi.model.VerifiableCredential;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction;
import org.eclipse.edc.policy.engine.spi.PolicyContext;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.spi.agent.ParticipantAgent;
import org.eclipse.edc.spi.result.Result;

import java.time.Instant;
import java.util.List;
import java.util.Map;

public class MembershipCredentialEvaluationFunction extends AbstractCredentialEvaluationFunction implements AtomicConstraintFunction<Permission> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
import org.eclipse.edc.spi.system.ServiceExtensionContext;

import static org.eclipse.edc.demo.dcp.policy.MembershipCredentialEvaluationFunction.MEMBERSHIP_CONSTRAINT_KEY;
import static org.eclipse.edc.demo.dcp.policy.PolicyScopes.CATALOG_REQUEST_SCOPE;
import static org.eclipse.edc.demo.dcp.policy.PolicyScopes.CATALOG_SCOPE;
import static org.eclipse.edc.demo.dcp.policy.PolicyScopes.NEGOTIATION_REQUEST_SCOPE;
import static org.eclipse.edc.demo.dcp.policy.PolicyScopes.NEGOTIATION_SCOPE;
import static org.eclipse.edc.demo.dcp.policy.PolicyScopes.TRANSFER_PROCESS_REQUEST_SCOPE;
import static org.eclipse.edc.demo.dcp.policy.PolicyScopes.TRANSFER_PROCESS_SCOPE;
import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA;

Expand Down Expand Up @@ -62,15 +59,15 @@ private void registerDataAccessLevelFunction() {
}

private void bindPermissionFunction(AtomicConstraintFunction<Permission> function, String scope, String constraintType) {
ruleBindingRegistry.bind("USE", scope);
ruleBindingRegistry.bind("use", scope);
ruleBindingRegistry.bind(ODRL_SCHEMA + "use", scope);
ruleBindingRegistry.bind(constraintType, scope);

policyEngine.registerFunction(scope, Permission.class, constraintType, function);
}

private void bindDutyFunction(AtomicConstraintFunction<Duty> function, String scope, String constraintType) {
ruleBindingRegistry.bind("USE", scope);
ruleBindingRegistry.bind("use", scope);
ruleBindingRegistry.bind(ODRL_SCHEMA + "use", scope);
ruleBindingRegistry.bind(constraintType, scope);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@ public class JwtSigner {
@SuppressWarnings("unchecked")
@ParameterizedTest
@ArgumentsSource(InputOutputProvider.class)
void generateJwt(String rawCredentialFilePAth, File vcResource, String did) throws JOSEException, IOException {
void generateJwt(String rawCredentialFilePath, File vcResource, String did) throws JOSEException, IOException {

var header = new JWSHeader.Builder(JWSAlgorithm.EdDSA)
.keyID("did:example:dataspace-issuer#key-1")
.type(JOSEObjectType.JWT)
.build();


//todo: change this to whatever credential JSON you want to sign
var credential = mapper.readValue(new File(rawCredentialFilePAth), Map.class);
var credential = mapper.readValue(new File(rawCredentialFilePath), Map.class);

//todo: change the claims to suit your needs
var claims = new JWTClaimsSet.Builder()
.audience(did)
.subject(did)
Expand All @@ -85,7 +83,6 @@ void generateJwt(String rawCredentialFilePAth, File vcResource, String did) thro

var content = Files.readString(vcResource.toPath());
var updatedContent = content.replaceFirst("\"rawVc\":.*,", "\"rawVc\": \"%s\",".formatted(jwt.serialize()));
// mapper.writeValue(vcResource, updatedContent);
Files.write(vcResource.toPath(), updatedContent.getBytes());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.Duration;
Expand Down Expand Up @@ -97,6 +98,7 @@ public String fromIri(String s) {
}).forEach(transformerRegistry::register);
}

@DisplayName("Tests a successful End-to-End contract negotiation and data transfer")
@Test
void transferData_hasPermission_shouldTransferData() {
System.out.println("Waiting for Provider dataplane to come online");
Expand Down Expand Up @@ -250,6 +252,7 @@ void transferData_hasPermission_shouldTransferData() {
assertThat(response).isNotEmpty();
}

@DisplayName("Tests a failing End-to-End contract negotiation because of an unfulfilled policy")
@Test
void transferData_doesNotHavePermission_shouldTerminate() {
System.out.println("Waiting for Provider dataplane to come online");
Expand Down Expand Up @@ -313,7 +316,8 @@ void transferData_doesNotHavePermission_shouldTerminate() {
var negotiationRequest = TestUtils.getResourceFileContentAsString("negotiation-request.json")
.replace("{{PROVIDER_ID}}", PROVIDER_ID)
.replace("{{PROVIDER_DSP_URL}}", PROVIDER_DSP_URL)
.replace("{{OFFER_ID}}", offerId.get());
.replace("{{OFFER_ID}}", offerId.get())
.replaceFirst("\"odrl:rightOperand\": \"processing\"", " \"odrl:rightOperand\": \"sensitive\"");
var negotiationId = baseRequest()
.body(negotiationRequest)
.post(CONSUMER_MANAGEMENT_URL + "/api/management/v3/contractnegotiations")
Expand Down
2 changes: 1 addition & 1 deletion tests/end2end/src/test/resources/negotiation-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"prohibition": [],
"odrl:obligation": {
"odrl:action": {
"@id": "USE"
"@id": "use"
},
"odrl:constraint": {
"odrl:leftOperand": {
Expand Down

0 comments on commit 089519d

Please sign in to comment.