From 4ef08143c313f12cd1b7ebcfcfcfcdc245c21fe8 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Fri, 12 Jul 2024 12:51:26 +0200 Subject: [PATCH] fix(policy-check):[#649] fix isSameAs method for AND constraints (must have same amount of constraints to ensure that there isn't any subset match in any direction) --- .../edc/client/policy/ConstraintCheckerService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java index bd9f4a2fc..3a13d6816 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java @@ -58,22 +58,33 @@ private boolean isValidOnList(final Constraint constraint, final List isSameAs(atomicConstraint, p)) || acceptedConstraints.getAnd().stream().anyMatch(p -> isSameAs(atomicConstraint, p)); } + if (constraint instanceof AndConstraint andConstraint) { + + // AND means the number of constraints must be the same + if (acceptedConstraints.getAnd() != null + && acceptedConstraints.getAnd().size() != andConstraint.getConstraints().size()) { + return false; + } + return andConstraint.getConstraints() .stream() .allMatch(constr -> isInList(constr, Optional.ofNullable(acceptedConstraints.getAnd()) .orElse(Collections.emptyList()))); } + if (constraint instanceof OrConstraint orConstraint) { return orConstraint.getConstraints() .stream() .anyMatch(constr -> isInList(constr, Optional.ofNullable(acceptedConstraints.getOr()) .orElse(Collections.emptyList()))); } + return false; }