Skip to content

Commit 059c633

Browse files
committed
Fixed issue. Use namespace in left operand in policies.
1 parent 21b74c5 commit 059c633

14 files changed

Lines changed: 134 additions & 58 deletions

File tree

.idea/sqldialects.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

federated-catalog/src/main/java/org/eclipse/edc/heleade/federated/catalog/extension/api/verification/VerificationApiController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import static org.eclipse.edc.heleade.commons.verification.claims.Claims.verifyClaims;
4040
import static org.eclipse.edc.heleade.commons.verification.claims.Claims.verifySignature;
41+
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
4142

4243

4344
/**
@@ -89,15 +90,15 @@ public JsonObject verify(String body) {
8990
jsonReader.close();
9091

9192
// get the inputs from the body
92-
String id = jsonBody.getString("participantId");
93-
String participantSignedClaims = jsonBody.getString("signedClaims");
94-
Map<String, Object> participantClaims = getMapFromJsonObject(jsonBody.getJsonObject("claims"));
95-
JsonObject participantClaimsJson = jsonBody.getJsonObject("claims");
93+
String id = jsonBody.getString(EDC_NAMESPACE + "participantId");
94+
String participantSignedClaims = jsonBody.getString(EDC_NAMESPACE + "signedClaims");
95+
Map<String, Object> participantClaims = getMapFromJsonObject(jsonBody.getJsonObject(EDC_NAMESPACE + "claims"));
96+
JsonObject participantClaimsJson = jsonBody.getJsonObject(EDC_NAMESPACE + "claims");
9697
String claimsString = participantClaimsJson.toString();
9798

9899
// check the signature
99100
ParticipantNode participantNode = targetNodeDirectory.getParticipantNode(id);
100-
String pem = participantNode.security().get("https://w3id.org/edc/v0.0.1/ns/pem");
101+
String pem = participantNode.security().get(EDC_NAMESPACE + "pem");
101102
boolean verifySignatureSuccess = verifySignature(typeManager.getMapper(), pem, participantSignedClaims, claimsString);
102103
JsonObjectBuilder builder = Json.createObjectBuilder();
103104
builder.add("verifySignatureSuccess", verifySignatureSuccess);

providers/policy/policy-evaluation/src/main/java/org/eclipse/edc/heleade/policy/extension/evaluation/common/AbstractConstraintFunction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Objects;
2626

2727
import static org.eclipse.edc.heleade.policy.extension.evaluation.common.Utils.getParticipantClaim;
28+
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
2829

2930
/**
3031
* Base class for implementing policy constraint functions that evaluate
@@ -79,7 +80,7 @@ public boolean evaluate(Operator operator, Object rightValue, R rule, C context
7980

8081
String participantValueToVerify;
8182

82-
if (!Objects.equals(leftOperand, "participant_id")) {
83+
if (!Objects.equals(leftOperand, EDC_NAMESPACE + "participant_id")) {
8384
participantValueToVerify = getParticipantClaim(participantClaims, leftOperand);
8485
} else {
8586
participantValueToVerify = participantId;

providers/policy/policy-evaluation/src/main/java/org/eclipse/edc/heleade/policy/extension/evaluation/country/CountryPolicyExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ public void initialize(ServiceExtensionContext context) {
8282
private <C extends ParticipantAgentPolicyContext> void registerFunctionAndBindTo(Class<C> contextClass, String scope, Monitor monitor) {
8383
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, scope);
8484
ruleBindingRegistry.bind(COUNTRY_CONSTRAINT_KEY, scope);
85-
policyEngine.registerFunction(contextClass, Duty.class, COUNTRY_CONSTRAINT_KEY, new CountryPolicyFunction<>(monitor, COUNTRY_KEY, fcParticipantClaimChecker));
86-
policyEngine.registerFunction(contextClass, Permission.class, COUNTRY_CONSTRAINT_KEY, new CountryPolicyFunction<>(monitor, COUNTRY_KEY, fcParticipantClaimChecker));
87-
policyEngine.registerFunction(contextClass, Prohibition.class, COUNTRY_CONSTRAINT_KEY, new CountryPolicyFunction<>(monitor, COUNTRY_KEY, fcParticipantClaimChecker));
85+
policyEngine.registerFunction(contextClass, Duty.class, COUNTRY_CONSTRAINT_KEY, new CountryPolicyFunction<>(monitor, COUNTRY_CONSTRAINT_KEY, fcParticipantClaimChecker));
86+
policyEngine.registerFunction(contextClass, Permission.class, COUNTRY_CONSTRAINT_KEY, new CountryPolicyFunction<>(monitor, COUNTRY_CONSTRAINT_KEY, fcParticipantClaimChecker));
87+
policyEngine.registerFunction(contextClass, Prohibition.class, COUNTRY_CONSTRAINT_KEY, new CountryPolicyFunction<>(monitor, COUNTRY_CONSTRAINT_KEY, fcParticipantClaimChecker));
8888
}
8989

9090

providers/policy/policy-evaluation/src/main/java/org/eclipse/edc/heleade/policy/extension/evaluation/dynamicpolicy/DynamicPolicyFunction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Map;
2525
import java.util.Objects;
2626

27-
import static org.eclipse.edc.heleade.policy.extension.evaluation.common.Utils.getLeftOperand;
2827
import static org.eclipse.edc.heleade.policy.extension.evaluation.common.Utils.getParticipantClaim;
2928
import static org.eclipse.edc.heleade.policy.extension.evaluation.common.Utils.isNumericComparison;
3029
import static org.eclipse.edc.heleade.policy.extension.evaluation.common.Utils.parseNumericValues;
@@ -82,10 +81,9 @@ public boolean evaluate(Object leftValue, Operator operator, Object rightValue,
8281
return false;
8382
}
8483

85-
String leftValueString = getLeftOperand(leftValue);
8684

8785
Map<String, Object> participantClaims = (Map<String, Object>) participantData.get("claims");
88-
String participantValueToVerify = getParticipantClaim(participantClaims, leftValueString);
86+
String participantValueToVerify = getParticipantClaim(participantClaims, leftValue.toString());
8987

9088
if (participantValueToVerify == null) {
9189
monitor.severe("Participant claim is null or is empty" + leftValue);

providers/policy/policy-evaluation/src/main/java/org/eclipse/edc/heleade/policy/extension/evaluation/entity/EntityPolicyExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public void initialize(ServiceExtensionContext context) {
8181
private <C extends ParticipantAgentPolicyContext> void registerFunctionAndBindTo(Class<C> contextClass, String scope, Monitor monitor) {
8282
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, scope);
8383
ruleBindingRegistry.bind(ENTITY_CONSTRAINT_KEY, scope);
84-
policyEngine.registerFunction(contextClass, Duty.class, ENTITY_CONSTRAINT_KEY, new EntityPolicyFunction<>(monitor, ENTITY_KEY, fcParticipantClaimChecker));
85-
policyEngine.registerFunction(contextClass, Permission.class, ENTITY_CONSTRAINT_KEY, new EntityPolicyFunction<>(monitor, ENTITY_KEY, fcParticipantClaimChecker));
86-
policyEngine.registerFunction(contextClass, Prohibition.class, ENTITY_CONSTRAINT_KEY, new EntityPolicyFunction<>(monitor, ENTITY_KEY, fcParticipantClaimChecker));
84+
policyEngine.registerFunction(contextClass, Duty.class, ENTITY_CONSTRAINT_KEY, new EntityPolicyFunction<>(monitor, ENTITY_CONSTRAINT_KEY, fcParticipantClaimChecker));
85+
policyEngine.registerFunction(contextClass, Permission.class, ENTITY_CONSTRAINT_KEY, new EntityPolicyFunction<>(monitor, ENTITY_CONSTRAINT_KEY, fcParticipantClaimChecker));
86+
policyEngine.registerFunction(contextClass, Prohibition.class, ENTITY_CONSTRAINT_KEY, new EntityPolicyFunction<>(monitor, ENTITY_CONSTRAINT_KEY, fcParticipantClaimChecker));
8787
}
8888

8989
}

providers/policy/policy-evaluation/src/main/java/org/eclipse/edc/heleade/policy/extension/evaluation/location/LocationPolicyExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public void initialize(ServiceExtensionContext context) {
8080
private <C extends ParticipantAgentPolicyContext> void registerFunctionAndBindTo(Class<C> contextClass, String scope, Monitor monitor) {
8181
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, scope);
8282
ruleBindingRegistry.bind(LOCATION_CONSTRAINT_KEY, scope);
83-
policyEngine.registerFunction(contextClass, Duty.class, LOCATION_CONSTRAINT_KEY, new LocationPolicyFunction<>(monitor, LOCATION_KEY, fcParticipantClaimChecker));
84-
policyEngine.registerFunction(contextClass, Permission.class, LOCATION_CONSTRAINT_KEY, new LocationPolicyFunction<>(monitor, LOCATION_KEY, fcParticipantClaimChecker));
85-
policyEngine.registerFunction(contextClass, Prohibition.class, LOCATION_CONSTRAINT_KEY, new LocationPolicyFunction<>(monitor, LOCATION_KEY, fcParticipantClaimChecker));
83+
policyEngine.registerFunction(contextClass, Duty.class, LOCATION_CONSTRAINT_KEY, new LocationPolicyFunction<>(monitor, LOCATION_CONSTRAINT_KEY, fcParticipantClaimChecker));
84+
policyEngine.registerFunction(contextClass, Permission.class, LOCATION_CONSTRAINT_KEY, new LocationPolicyFunction<>(monitor, LOCATION_CONSTRAINT_KEY, fcParticipantClaimChecker));
85+
policyEngine.registerFunction(contextClass, Prohibition.class, LOCATION_CONSTRAINT_KEY, new LocationPolicyFunction<>(monitor, LOCATION_CONSTRAINT_KEY, fcParticipantClaimChecker));
8686
}
8787

8888
}

providers/policy/policy-evaluation/src/main/java/org/eclipse/edc/heleade/policy/extension/evaluation/participantid/ParticipantIdPolicyExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public void initialize(ServiceExtensionContext context) {
8383
private <C extends ParticipantAgentPolicyContext> void registerFunctionAndBindTo(Class<C> contextClass, String scope, Monitor monitor) {
8484
ruleBindingRegistry.bind(ODRL_USE_ACTION_ATTRIBUTE, scope);
8585
ruleBindingRegistry.bind(PARTICIPANT_ID_CONSTRAINT_KEY, scope);
86-
policyEngine.registerFunction(contextClass, Duty.class, PARTICIPANT_ID_CONSTRAINT_KEY, new ParticipantIdPolicyFunction<>(monitor, PARTICIPANT_ID_KEY, fcParticipantClaimChecker));
87-
policyEngine.registerFunction(contextClass, Permission.class, PARTICIPANT_ID_CONSTRAINT_KEY, new ParticipantIdPolicyFunction<>(monitor, PARTICIPANT_ID_KEY, fcParticipantClaimChecker));
88-
policyEngine.registerFunction(contextClass, Prohibition.class, PARTICIPANT_ID_CONSTRAINT_KEY, new ParticipantIdPolicyFunction<>(monitor, PARTICIPANT_ID_KEY, fcParticipantClaimChecker));
86+
policyEngine.registerFunction(contextClass, Duty.class, PARTICIPANT_ID_CONSTRAINT_KEY, new ParticipantIdPolicyFunction<>(monitor, PARTICIPANT_ID_CONSTRAINT_KEY, fcParticipantClaimChecker));
87+
policyEngine.registerFunction(contextClass, Permission.class, PARTICIPANT_ID_CONSTRAINT_KEY, new ParticipantIdPolicyFunction<>(monitor, PARTICIPANT_ID_CONSTRAINT_KEY, fcParticipantClaimChecker));
88+
policyEngine.registerFunction(contextClass, Prohibition.class, PARTICIPANT_ID_CONSTRAINT_KEY, new ParticipantIdPolicyFunction<>(monitor, PARTICIPANT_ID_CONSTRAINT_KEY, fcParticipantClaimChecker));
8989
}
9090
}

system-tests/src/test/java/org/eclipse/edc/heleade/common/PolicyCommon.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public class PolicyCommon {
3434
private static final String CREATE_ASSET_FILE_PATH = RESOURCES_FOLDER + "/create-asset.json";
3535
private static final String CREATE_POLICY_FILE_PATH = RESOURCES_FOLDER + "/create-policy.json";
3636
private static final String CREATE_POLICY_COMPLEX_FILE_PATH = RESOURCES_FOLDER + "/create-complex-policy.json";
37+
private static final String CREATE_POLICY_SIMPLE_DYNAMIC = RESOURCES_FOLDER + "/create-simple-dynamic-policy.json";
3738
private static final String CREATE_CONTRACT_DEFINITION_FILE_PATH = RESOURCES_FOLDER + "/create-contract-definition.json";
3839
private static final String FETCH_DATASET_FROM_CATALOG_FILE_PATH = RESOURCES_FOLDER + "/get-dataset.json";
3940
private static final String CONTRACT_OFFER_FILE_PATH = RESOURCES_FOLDER + "/create-contract-request.json";
41+
private static final String CONTRACT_OFFER_FILE_PATH_DIFF_NAMESPACE = RESOURCES_FOLDER + "/create-contract-request-diff-namespace.json";
4042
private static final String CONTRACT_OFFER_COMPLEX_FILE_PATH = RESOURCES_FOLDER + "/create-complex-contract-request.json";
4143
private static final String CATALOG_DATASET_ID = "\"odrl:hasPolicy\".'@id'";
4244
private static final String CONTRACT_OFFER_ID_KEY = "{{contract-offer-id}}";
@@ -73,7 +75,6 @@ public static void generateKeys(String keyPath, String nodeDirectoryPath) throws
7375
}
7476

7577

76-
7778
public static boolean checkPolicyById(String policyId) {
7879
String response = get(PrerequisitesCommon.PROVIDER_MANAGEMENT_URL + V2_POLICY_DEFINITIONS_PATH + "/" + policyId, ID);
7980
return response != null && response.equals(policyId);
@@ -106,6 +107,11 @@ public static void createPolicyComplex(String policyId, String operand, String r
106107
post(PrerequisitesCommon.PROVIDER_MANAGEMENT_URL + V2_POLICY_DEFINITIONS_PATH, content);
107108
}
108109

110+
public static void createSimpleDynamicPolicy(String policyId) {
111+
String content = getFileContentFromRelativePath(CREATE_POLICY_SIMPLE_DYNAMIC)
112+
.replace(POLICY_ID_KEY, policyId);
113+
post(PrerequisitesCommon.PROVIDER_MANAGEMENT_URL + V2_POLICY_DEFINITIONS_PATH, content);
114+
}
109115

110116
public static void createContractDefinitionWithParams(String contractId, String accessPolicyId, String contractPolicyId, String assetId) {
111117
String content = getFileContentFromRelativePath(CREATE_CONTRACT_DEFINITION_FILE_PATH)
@@ -126,13 +132,16 @@ public static String fetchDatasetFromCatalogWithId(String assetId) {
126132
);
127133
}
128134

129-
public static String negotiateContractWithParams(String assetId, String contractOfferId, String leftOperand, String rightOperand, String operator) {
130-
String content = getFileContentFromRelativePath(CONTRACT_OFFER_FILE_PATH)
131-
.replace(CONTRACT_OFFER_ID_KEY, contractOfferId)
132-
.replace(LEFT_OPERAND_KEY, leftOperand)
133-
.replace(RIGHT_OPERAND_KEY, rightOperand)
134-
.replace(ASSET_ID_KEY, assetId)
135-
.replace(OPERATOR_KEY, operator);
135+
public static String negotiateContractWithParams(String assetId, String contractOfferId, String leftOperand, String rightOperand, String operator, Boolean defaultNamespace) {
136+
137+
String filepath = defaultNamespace ? CONTRACT_OFFER_FILE_PATH : CONTRACT_OFFER_FILE_PATH_DIFF_NAMESPACE;
138+
String content = getFileContentFromRelativePath(filepath)
139+
.replace(CONTRACT_OFFER_ID_KEY, contractOfferId)
140+
.replace(LEFT_OPERAND_KEY, leftOperand)
141+
.replace(RIGHT_OPERAND_KEY, rightOperand)
142+
.replace(ASSET_ID_KEY, assetId)
143+
.replace(OPERATOR_KEY, operator);
144+
136145

137146
var contractNegotiationId = post(
138147
PrerequisitesCommon.CONSUMER_MANAGEMENT_URL + V2_CONTRACT_NEGOTIATIONS_PATH,

0 commit comments

Comments
 (0)