Skip to content

Commit

Permalink
chore(charts): fixed policy configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Brunkow Moser committed May 12, 2024
1 parent a34cc1e commit d61f357
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data:
transfer: {{ .Values.backend.edc.apis.transfer }}
receiverEndpoint: "https://{{ .Values.backend.hostname }}/endpoint"
delay: {{ .Values.backend.edc.delay }} # -- Negotiation status Delay in milliseconds in between async requests [<= 500]
authorizationKey: {{ .Values.backend.edc.authorizationKey }}
# -- security configuration
security:
# -- authorization configuration about bpn and role checks
Expand Down
2 changes: 1 addition & 1 deletion charts/digital-product-pass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ backend:
- action: "USE"
logicalConstraint: "odrl:and"
constraints:
- leftOperand: "cx-policy:Membership"
- leftOperand: "Membership"
operator: "odrl:eq"
rightOperand: "active"
- leftOperand: "cx-policy:FrameworkAgreement"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,7 @@ public String cancelProcess(HttpServletRequest httpRequest, String processId) {
* if unable to update the status file.
*/
public String setAgreed(HttpServletRequest httpRequest, String processId, Long signedAt, String contractId, String policyId) {

this.setProcessState(httpRequest, processId, "STARTING");

return this.setStatus(processId, "contract-agreed", new History(
contractId+"/"+policyId,
"AGREED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,7 @@ public Policy buildOfferById(Dataset dataset, String policyId, String bpn) {
*
*/
public Policy buildOffer(Dataset dataset, Set policy, String bpn) {
LogUtil.printMessage("DEBUG: Set before "+ jsonUtil.toJson(policy, true) );

Policy policyOffer = jsonUtil.bind(policy, new TypeReference<>() {});
LogUtil.printMessage("DEBUG: Policy offer before "+ jsonUtil.toJson(policyOffer, true) );

return policyOffer.setup(dataset.getAssetId(), bpn, "odrl:Offer");
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@

package utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig;
import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig.ActionConfig;
import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig.PolicyConfig;
import org.eclipse.tractusx.digitalproductpass.models.edc.EndpointDataReference;
import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset;
import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Action;
import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Constraint;
import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -131,37 +126,26 @@ public List<Set> getValidPoliciesByConstraints(Object policies, PolicyCheckConfi
if (policies == null || policyCheckConfigs == null) {
return null;
}
// Generate configuration policies
List<PolicyConfig> policyConfigs = policyCheckConfigs.getPolicies();
List<Set> validPolicies = this.buildPolicies(policyConfigs);

LogUtil.printMessage("DEBUG: Valid Policies: " + jsonUtil.toJson(validPolicies, true));

Boolean strictMode = policyCheckConfigs.getStrictMode();
// There is no valid policy available
if (validPolicies == null || validPolicies.size() == 0) {
return null;
}
LogUtil.printMessage("DEBUG: Raw Policies: " + jsonUtil.toJson(policies, true));

if (policies instanceof LinkedHashMap) {
// Check if policy is valid or not
LogUtil.printMessage("DEBUG: Single Policy!");
Set policy = Set.build(policies);
LogUtil.printMessage("DEBUG: Policy: " + jsonUtil.toJson(policy, true));

// In case the policy is valid return the policy
if(this.isPolicyValid(policy, validPolicies, strictMode)){
LogUtil.printMessage("DEBUG: Policy not valid!");

return new ArrayList<>(){{add(policy);}}; // Add policy to a list of valid policies
}
// If the policy is not valid return an empty list
return new ArrayList<>();
}
LogUtil.printMessage("DEBUG: Multiple Policies!");
List<Set> policyList = this.parsePolicies(policies);
LogUtil.printMessage("DEBUG: Policies: " + jsonUtil.toJson(policyList, true));

//Search for policies that are valid and get one of the valid ones
return policyList.stream().parallel().filter(p -> this.isPolicyValid(p, validPolicies, strictMode)).toList();
}catch (Exception e) {
Expand Down Expand Up @@ -277,7 +261,6 @@ public Boolean defaultPolicyCheck(Set policy, List<Set> validPolicies){
try {
// Filter the list of policies based on the policy configuration
List<Set> policies = validPolicies.stream().filter(p -> this.isPolicyConstraintsValid(policy, p)).toList();
System.out.println("[DEBUG] [VALID POLICIES] " + policies);
return policies.size() > 0; //If any policy is valid then return true
}catch (Exception e) {
throw new UtilException(PolicyUtil.class, e, "[DEFAULT MODE] It was not possible to check if policy is valid!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ configuration:
- action: "USE"
logicalConstraint: "odrl:and"
constraints:
- leftOperand: "cx-policy:Membership"
- leftOperand: "Membership"
operator: "odrl:eq"
rightOperand: "active"
- leftOperand: "cx-policy:UsagePurpose"
Expand Down Expand Up @@ -153,12 +153,13 @@ configuration:
- "urn:samm:io.catenax.generic.digital_product_passport:2.0.0#DigitalProductPassport"
policyCheck:
enabled: true
strictMode: false
policies:
- permission:
- action: "USE"
logicalConstraint: "odrl:and"
constraints:
- leftOperand: "cx-policy:Membership"
- leftOperand: "Membership"
operator: "odrl:eq"
rightOperand: "active"
- leftOperand: "cx-policy:FrameworkAgreement"
Expand Down

0 comments on commit d61f357

Please sign in to comment.