Skip to content

Commit

Permalink
feat(impl):[#370] merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Jan 31, 2024
2 parents 7b2b9b4 + 7326f50 commit e9b9c36
Show file tree
Hide file tree
Showing 25 changed files with 599 additions and 147 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed lookupGlobalAssetIds to lookupShellsByBPN, which provides full object.
- Suppressed CVE-2024-20932 from graal-sdk-21.2.0.jar because this is not applicable for IRS.
- Redesigned Shell object - wrapped payload and added "contractAgreementId" field
- Changed structure of Policy creation to match EDC format

### Fixed
- Update to Spring Boot 3.1.8. This fixes the following CVEs:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,13 @@ from the base distribution, along with any direct or indirect dependencies of th

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies
with any relevant licenses for all software contained within.

## Contact

Contact the Eclipse Tractus-X developers via the developer mailing list.

* https://accounts.eclipse.org/mailing-list/tractusx-dev

Contact the project developers via eclipse matrix chat.

* Eclipse Matrix Chat https://chat.eclipse.org/#/room/#tractusx-irs:matrix.eclipse.org
132 changes: 97 additions & 35 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1688,28 +1688,11 @@ components:
leftOperand:
type: string
example: string
operator:
'odrl:rightOperand':
type: string
example: eq
enum:
- eq
- neq
- lt
- gt
- in
- lteq
- gteq
- isA
- hasPart
- isPartOf
- isOneOf
- isAllOf
- isNoneOf
rightOperand:
type: array
items:
type: string
example: [string]
example: string
operator:
$ref: '#/components/schemas/Operator'
Constraints:
type: object
additionalProperties: false
Expand All @@ -1727,21 +1710,48 @@ components:
additionalProperties: false
description: Request to add a policy
properties:
permissions:
type: array
description: List of permissions that will be added to the Policy on creation.
items:
$ref: '#/components/schemas/Permission'
policyId:
type: string
description: The ID of the policy to add
payload:
type: object
additionalProperties:
$ref: '#/components/schemas/JsonValue'
example:
payload:
'@context':
odrl: http://www.w3.org/ns/odrl/2/
'@id': policy-id
policy:
'odrl:permission':
- 'odrl:action': USE
'odrl:constraint':
'odrl:and':
- 'odrl:leftOperand': Membership
'odrl:operator':
'@id': 'odrl:eq'
'odrl:rightOperand': active
- 'odrl:leftOperand': PURPOSE
'odrl:operator':
'@id': 'odrl:eq'
'odrl:rightOperand': ID 3.1 Trace
validUntil: '2025-12-12T23:59:59.999Z'
properties:
empty:
type: boolean
valueType:
type: string
enum:
- 'ARRAY'
- 'OBJECT'
- 'STRING'
- 'NUMBER'
- 'TRUE'
- 'FALSE'
- 'NULL'
validUntil:
type: string
format: date-time
description: Timestamp after which the policy will no longer be accepted in negotiations
required:
- permissions
- policyId
- payload
- validUntil
EdcNotificationResponseNotificationContent:
type: object
Expand Down Expand Up @@ -2086,6 +2096,39 @@ components:
items:
$ref: '#/components/schemas/Tombstone'
maxItems: 2147483647
JsonValue:
type: object
additionalProperties: false
properties:
valueType:
type: string
enum:
- 'ARRAY'
- 'OBJECT'
- 'STRING'
- 'NUMBER'
- 'TRUE'
- 'FALSE'
- 'NULL'
example:
payload:
'@context':
odrl: http://www.w3.org/ns/odrl/2/
'@id': policy-id
policy:
'odrl:permission':
- 'odrl:action': USE
'odrl:constraint':
'odrl:and':
- 'odrl:leftOperand': Membership
'odrl:operator':
'@id': 'odrl:eq'
'odrl:rightOperand': active
- 'odrl:leftOperand': PURPOSE
'odrl:operator':
'@id': 'odrl:eq'
'odrl:rightOperand': ID 3.1 Trace
validUntil: '2025-12-12T23:59:59.999Z'
LangString:
type: object
additionalProperties: false
Expand Down Expand Up @@ -2144,6 +2187,27 @@ components:
lexicalValue:
type: string
example: piece
Operator:
type: object
additionalProperties: false
properties:
'@id':
type: string
example: 'odrl:eq'
enum:
- eq
- neq
- lt
- gt
- in
- lteq
- gteq
- isA
- hasPart
- isPartOf
- isOneOf
- isAllOf
- isNoneOf
PageResult:
type: object
additionalProperties: false
Expand Down Expand Up @@ -2197,10 +2261,8 @@ components:
enum:
- ACCESS
- USE
constraints:
type: array
items:
$ref: '#/components/schemas/Constraints'
constraint:
$ref: '#/components/schemas/Constraints'
Policy:
type: object
additionalProperties: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.List;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -40,10 +39,13 @@
public class Constraint {

@Schema(implementation = String.class, example = "string")
@JsonAlias({"odrl:leftOperand"})
private String leftOperand;
@Schema(implementation = OperatorType.class, example = "eq")
private OperatorType operator;
@ArraySchema(arraySchema = @Schema(example = "[\"string\"]", implementation = String.class))
private List<String> rightOperand;
@JsonAlias("odrl:operator")
@Schema
private Operator operator;
@Schema(implementation = String.class, example = "string")
@JsonProperty("odrl:rightOperand")
private String rightOperand;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.Collection;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
Expand All @@ -45,8 +44,7 @@ public class ConstraintCheckerService {
public boolean hasAllConstraint(final Policy acceptedPolicy, final List<Constraint> constraints) {
final List<Constraints> acceptedConstraintsList = acceptedPolicy.getPermissions()
.stream()
.map(Permission::getConstraints)
.flatMap(Collection::stream)
.map(Permission::getConstraint)
.toList();

return constraints.stream().allMatch(constraint -> isValidOnList(constraint, acceptedConstraintsList));
Expand Down Expand Up @@ -90,8 +88,8 @@ private boolean isSameAs(final AtomicConstraint atomicConstraint,
.atomicConstraint(atomicConstraint)
.leftExpressionValue(acceptedConstraint.getLeftOperand())
.rightExpressionValue(
acceptedConstraint.getRightOperand().stream().findFirst().orElse(""))
.expectedOperator(Operator.valueOf(acceptedConstraint.getOperator().name()))
acceptedConstraint.getRightOperand())
.expectedOperator(Operator.valueOf(acceptedConstraint.getOperator().getOperatorType().name()))
.build()
.isValid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.List;

import com.fasterxml.jackson.annotation.JsonAlias;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -42,8 +43,10 @@
public class Constraints {

@ArraySchema
@JsonAlias({"odrl:and"})
private List<Constraint> and;
@ArraySchema
@JsonAlias({"odrl:or"})
private List<Constraint> or;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************
* Copyright (c) 2022,2024
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2024: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.policy;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* Wrapper for OperatorType
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Schema
public class Operator {

@JsonProperty("@id")
@Schema(implementation = OperatorType.class, example = "odrl:eq")
private OperatorType operatorType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,26 @@ public enum OperatorType {
private final String code;
private final String label;

private static final int ODRL_PREFIX_INDEX = 5;

OperatorType(final String code, final String label) {
this.code = code;
this.label = label;
}

@JsonCreator
public static OperatorType fromValue(final String value) {
String operator;
if (value.startsWith("odrl:")) {
operator = value.substring(ODRL_PREFIX_INDEX);
} else {
operator = value;
}

return Stream.of(OperatorType.values())
.filter(operatorType -> operatorType.code.equals(value))
.filter(operatorType -> operatorType.code.equals(operator))
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Unsupported OperatorType: " + value));
.orElseThrow(() -> new NoSuchElementException("Unsupported OperatorType: " + operator));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.policy;

import java.util.List;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -39,11 +38,14 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class Permission {

@Schema(implementation = PolicyType.class, example = "USE")
@JsonAlias({"odrl:action"})
private PolicyType action;
@ArraySchema
private List<Constraints> constraints;
@Schema
@JsonAlias({"odrl:constraint"})
private Constraints constraint;

}
Loading

0 comments on commit e9b9c36

Please sign in to comment.