Skip to content

Commit

Permalink
Merge pull request #83 from catenax-ng/tx_remove_time_duration
Browse files Browse the repository at this point in the history
[fix|SDE backend] : Removed time duration from apply policy
  • Loading branch information
almadigabor authored Jan 4, 2024
2 parents 79334b1 + c2eab84 commit 4f44651
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 166 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [2.3.4] - 2023-12-21

### Fixed
- Removed time duration from policy.

## [2.3.3] - 2023-12-06
### Fixed
- fixed veracode security in app CVE-2023-46589 and CVE-2023-34053 .
Expand Down Expand Up @@ -257,7 +262,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Compliance with Catena-X Guidelines
- Integration with Digital Twin registry service.

[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.3...main
[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.4...main
[2.3.4]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.3...v2.3.4
[2.3.3]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.2...v2.3.3
[2.3.2]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.1...v2.3.2
[2.3.1]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.0...v2.3.1
Expand Down
10 changes: 10 additions & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
maven/mavencentral/ch.qos.logback/logback-classic/1.4.13, EPL-1.0 OR LGPL-2.1-only, approved, #3435
maven/mavencentral/ch.qos.logback/logback-classic/1.4.7, EPL-1.0 OR LGPL-2.1-only, approved, #3435
maven/mavencentral/ch.qos.logback/logback-core/1.4.13, EPL-1.0 OR LGPL-2.1-only, approved, #3373
maven/mavencentral/ch.qos.logback/logback-core/1.4.7, EPL-1.0 OR LGPL-2.1-only, approved, #3373
maven/mavencentral/com.ethlo.time/itu/1.7.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.15.0, Apache-2.0, approved, #7947
maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.15.0, MIT AND Apache-2.0, approved, #7932
Expand Down Expand Up @@ -52,13 +54,17 @@ maven/mavencentral/org.apache.commons/commons-text/1.10.0, Apache-2.0, approved,
maven/mavencentral/org.apache.logging.log4j/log4j-api/2.17.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apache.logging.log4j/log4j-to-slf4j/2.17.1, Apache-2.0, approved, #2163
maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.16, Apache-2.0 AND (EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND (CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND W3C AND CC0-1.0, approved, #5949
maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.8, Apache-2.0 AND (EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND (CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND W3C AND CC0-1.0, approved, #5949
maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-el/10.1.8, Apache-2.0, approved, #6997
maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.8, Apache-2.0, approved, #7920
maven/mavencentral/org.apache.tomcat/tomcat-annotations-api/10.1.8, Apache-2.0, approved, #8196
maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.aspectj/aspectjweaver/1.9.19, Apache-2.0 AND BSD-3-Clause AND EPL-1.0 AND BSD-3-Clause AND Apache-1.1, approved, #7695
maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161
maven/mavencentral/org.bouncycastle/bcpkix-jdk15on/1.69, MIT, approved, clearlydefined
maven/mavencentral/org.bouncycastle/bcprov-jdk15on/1.69, MIT, approved, clearlydefined
maven/mavencentral/org.bouncycastle/bcprov-jdk18on/1.77, MIT AND CC0-1.0, approved, #11595
maven/mavencentral/org.bouncycastle/bcutil-jdk15on/1.69, MIT, approved, clearlydefined
maven/mavencentral/org.checkerframework/checker-qual/3.33.0, MIT, approved, clearlydefined
maven/mavencentral/org.eclipse.angus/angus-activation/2.0.0, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus
maven/mavencentral/org.eclipse.persistence/eclipselink/3.0.3, EPL-2.0 OR BSD-3-Clause, approved, ee4j.eclipselink
Expand Down Expand Up @@ -129,7 +135,9 @@ maven/mavencentral/org.springframework.cloud/spring-cloud-starter-openfeign/4.0.
maven/mavencentral/org.springframework.cloud/spring-cloud-starter/4.0.3, Apache-2.0, approved, #7299
maven/mavencentral/org.springframework.data/spring-data-commons/3.1.0, Apache-2.0, approved, #8805
maven/mavencentral/org.springframework.data/spring-data-jpa/3.1.0, Apache-2.0, approved, #9120
maven/mavencentral/org.springframework.security/spring-security-config/6.1.0, Apache-2.0, approved, #9736
maven/mavencentral/org.springframework.security/spring-security-config/6.1.2, Apache-2.0, approved, #9736
maven/mavencentral/org.springframework.security/spring-security-core/6.1.0, Apache-2.0, approved, #9801
maven/mavencentral/org.springframework.security/spring-security-core/6.1.2, Apache-2.0, approved, #9801
maven/mavencentral/org.springframework.security/spring-security-crypto/6.1.0, Apache-2.0 AND ISC, approved, #9735
maven/mavencentral/org.springframework.security/spring-security-oauth2-core/6.1.0, Apache-2.0, approved, #9741
Expand All @@ -150,7 +158,9 @@ maven/mavencentral/org.springframework/spring-orm/6.0.9, Apache-2.0, approved, #
maven/mavencentral/org.springframework/spring-test/6.0.9, Apache-2.0, approved, #7003
maven/mavencentral/org.springframework/spring-tx/6.0.9, Apache-2.0, approved, #5926
maven/mavencentral/org.springframework/spring-web/6.0.14, Apache-2.0, approved, #5942
maven/mavencentral/org.springframework/spring-web/6.0.9, Apache-2.0, approved, #5942
maven/mavencentral/org.springframework/spring-webmvc/6.0.14, Apache-2.0, approved, #5944
maven/mavencentral/org.springframework/spring-webmvc/6.0.9, Apache-2.0, approved, #5944
maven/mavencentral/org.webjars/swagger-ui/4.15.5, Apache-2.0 AND MIT, approved, #5921
maven/mavencentral/org.webjars/webjars-locator-core/0.52, MIT, approved, clearlydefined
maven/mavencentral/org.xmlunit/xmlunit-core/2.9.1, Apache-2.0, approved, #6272
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package org.eclipse.tractusx.sde.common.entities;

import org.eclipse.tractusx.sde.common.enums.DurationEnum;
import org.eclipse.tractusx.sde.common.enums.PolicyAccessEnum;
import org.eclipse.tractusx.sde.common.enums.UsagePolicyEnum;

Expand Down Expand Up @@ -49,9 +48,4 @@ public class UsagePolicies {
PolicyAccessEnum typeOfAccess;

String value;

@JsonProperty("durationUnit")
@SerializedName(value = "duration_unit")
DurationEnum durationUnit;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package org.eclipse.tractusx.sde.common.enums;

public enum UsagePolicyEnum {
DURATION,
PURPOSE,
ROLE,
CUSTOM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.commons.lang3.StringUtils;
import org.eclipse.tractusx.sde.common.entities.UsagePolicies;
import org.eclipse.tractusx.sde.common.enums.PolicyAccessEnum;
import org.eclipse.tractusx.sde.common.enums.UsagePolicyEnum;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

Expand All @@ -36,11 +35,7 @@ public boolean isValid(List<UsagePolicies> usagePolicies) {
if (usagePolicies != null && !CollectionUtils.isEmpty(usagePolicies)) {
boolean validateFlag = false;
for (UsagePolicies usagePolicy : usagePolicies) {
if (usagePolicy.getType().equals(UsagePolicyEnum.DURATION)) {
validateFlag = validateDuration(usagePolicy);
} else {
validateFlag = validatePolicy(usagePolicy);
}
validateFlag = validatePolicy(usagePolicy);
if (!validateFlag) {
break;
}
Expand All @@ -62,15 +57,4 @@ private boolean validatePolicy(UsagePolicies usagePolicy) {

return isValid;
}

private boolean validateDuration(UsagePolicies usagePolicy) {

boolean isValid = false;
if (usagePolicy.getTypeOfAccess().equals(PolicyAccessEnum.UNRESTRICTED)
|| usagePolicy.getTypeOfAccess().equals(PolicyAccessEnum.RESTRICTED)
&& StringUtils.isNotBlank(usagePolicy.getValue()) && usagePolicy.getDurationUnit() != null) {
isValid = true;
}
return isValid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.eclipse.tractusx.sde.common.entities.UsagePolicies;
import org.eclipse.tractusx.sde.edc.entities.request.policies.accesspolicy.AccessPolicyDTO;
import org.eclipse.tractusx.sde.edc.entities.request.policies.usagepolicy.DurationPolicyDTO;
import org.eclipse.tractusx.sde.edc.entities.request.policies.usagepolicy.PurposePolicyDTO;
import org.eclipse.tractusx.sde.edc.entities.request.policies.usagepolicy.RolePolicyDTO;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -68,9 +67,6 @@ private void usagePolicy(List<ConstraintRequest> usageConstraintList, UsagePolic
ConstraintRequest request = null;

switch (policy.getType()) {
case DURATION:
request = DurationPolicyDTO.fromUsagePolicy(policy).toConstraint();
break;
case PURPOSE:
request = PurposePolicyDTO.fromUsagePolicy(policy).toConstraint();
break;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.apache.commons.lang3.StringUtils;
import org.eclipse.tractusx.sde.common.entities.UsagePolicies;
import org.eclipse.tractusx.sde.common.enums.DurationEnum;
import org.eclipse.tractusx.sde.common.enums.PolicyAccessEnum;
import org.eclipse.tractusx.sde.common.enums.UsagePolicyEnum;
import org.eclipse.tractusx.sde.edc.entities.request.policies.ConstraintRequest;
Expand All @@ -53,49 +52,6 @@ public static String removeLastSlashOfUrl(String url) {
}
}

public static UsagePolicies getDurationPolicy(String durationValue) {
DurationEnum durationUnit;
// Sample value - P0Y0M3DT0H0M0S - Output - 3 Day(s)
String value = StringUtils.substringBetween(durationValue, "P", "Y");
if (!value.equals("0")) {
durationUnit = DurationEnum.YEAR;
return getResponse(value, durationUnit);
}
value = StringUtils.substringBetween(durationValue, "Y", "M");
if (!value.equals("0")) {
durationUnit = DurationEnum.MONTH;
return getResponse(value, durationUnit);
}
value = StringUtils.substringBetween(durationValue, "M", "D");
if (!value.equals("0")) {
durationUnit = DurationEnum.DAY;
return getResponse(value, durationUnit);
}
value = StringUtils.substringBetween(durationValue, "T", "H");
if (!value.equals("0")) {
durationUnit = DurationEnum.HOUR;
return getResponse(value, durationUnit);
}
value = StringUtils.substringBetween(durationValue, "H", "M");
if (!value.equals("0")) {
durationUnit = DurationEnum.MINUTE;
return getResponse(value, durationUnit);
}
value = durationValue.substring(durationValue.lastIndexOf("M") + 1, durationValue.indexOf("S"));
if (!value.equals("0")) {
durationUnit = DurationEnum.SECOND;
return getResponse(value, durationUnit);
}
return null;
}

private static UsagePolicies getResponse(String value, DurationEnum durationUnit) {
UsagePolicies policyResponse;
policyResponse = UsagePolicies.builder().type(UsagePolicyEnum.DURATION)
.typeOfAccess(PolicyAccessEnum.RESTRICTED).value(value).durationUnit(durationUnit).build();
return policyResponse;
}

public static List<UsagePolicies> getUsagePolicies(List<UsagePolicies> usagePolicies, List<ConstraintRequest> constraints) {
constraints.forEach(constraint -> {
String leftExpVal = constraint.getLeftOperand();
Expand All @@ -117,9 +73,6 @@ public static UsagePolicies identyAndGetUsagePolicy(String leftExpVal, String ri
policyResponse = UsagePolicies.builder().type(UsagePolicyEnum.ROLE)
.typeOfAccess(PolicyAccessEnum.RESTRICTED).value(rightExpVal).build();
break;
case "idsc:ELAPSED_TIME":
policyResponse = UtilityFunctions.getDurationPolicy(rightExpVal);
break;
case "idsc:PURPOSE":
policyResponse = UsagePolicies.builder().type(UsagePolicyEnum.PURPOSE)
.typeOfAccess(PolicyAccessEnum.RESTRICTED).value(rightExpVal).build();
Expand Down

0 comments on commit 4f44651

Please sign in to comment.