Elffuss BraidHub

kikocis/EDC public

feat(api): add additional scopes to the CatalogRequest (#4348)

* feat(api): add additional scopes to the CatalogRequest

* checkstyle, DEPENDENCIES

* added tests

* DEPENDENCIES

* update mgmt api version file
Changesetb3b58d6bb3bc8025b69d097fe60db3f0f876823d9dfd78883f83d69af7ba2566
AuthorPaul Latzelsperger <43503240+paullatzelsperger@users.noreply.github.com> · 2024-07-11 16:28 +02:00
CommitterGitHub <noreply@github.com> · 2024-07-11 16:28 +02:00
Parentsd3b34c182bea

Browse the files at this changeset

16 files changed

modified core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/controlplane/services/catalog/CatalogServiceImpl.java +2 −1
@@ -33,12 +33,13 @@
3333 }
3434
3535 @Override
36- public CompletableFuture<StatusResult<byte[]>> requestCatalog(String counterPartyId, String counterPartyAddress, String protocol, QuerySpec querySpec) {
36+ public CompletableFuture<StatusResult<byte[]>> requestCatalog(String counterPartyId, String counterPartyAddress, String protocol, QuerySpec querySpec, String... additionalScopes) {
3737 var request = CatalogRequestMessage.Builder.newInstance()
3838 .protocol(protocol)
3939 .counterPartyId(counterPartyId)
4040 .counterPartyAddress(counterPartyAddress)
4141 .querySpec(querySpec)
42+ .additionalScopes(additionalScopes)
4243 .build();
4344
4445 return dispatcher.dispatch(byte[].class, request);
modified data-protocols/dsp/dsp-http-core/src/main/java/org/eclipse/edc/protocol/dsp/http/dispatcher/DspHttpRemoteMessageDispatcherImpl.java +6 −0
@@ -16,6 +16,7 @@
1616
1717 import okhttp3.Response;
1818 import okhttp3.ResponseBody;
19+import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequestMessage;
1920 import org.eclipse.edc.http.spi.EdcHttpClient;
2021 import org.eclipse.edc.policy.engine.spi.PolicyContextImpl;
2122 import org.eclipse.edc.policy.engine.spi.PolicyEngine;
@@ -108,6 +109,11 @@
108109 var policyProvider = (Function<M, Policy>) policyScope.policyProvider;
109110 policyEngine.evaluate(policyScope.scope, policyProvider.apply(message), context);
110111
112+ // catalog request messages can carry additional, user-supplied scopes
113+ if (message instanceof CatalogRequestMessage catalogRequestMessage) {
114+ catalogRequestMessage.getAdditionalScopes().forEach(requestScopeBuilder::scope);
115+ }
116+
111117 var scopes = requestScopeBuilder.build().getScopes();
112118
113119 // Only add the scope claim if there are scopes returned from the policy engine evaluation
modified data-protocols/dsp/dsp-http-core/src/test/java/org/eclipse/edc/protocol/dsp/http/dispatcher/DspHttpRemoteMessageDispatcherImplTest.java +45 −0
@@ -18,6 +18,7 @@
1818 import okhttp3.Protocol;
1919 import okhttp3.Request;
2020 import okhttp3.ResponseBody;
21+import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequestMessage;
2122 import org.eclipse.edc.http.spi.EdcHttpClient;
2223 import org.eclipse.edc.policy.engine.spi.PolicyContext;
2324 import org.eclipse.edc.policy.engine.spi.PolicyEngine;
@@ -271,6 +272,50 @@
271272 verifyNoInteractions(policyEngine);
272273 }
273274
275+ @Test
276+ void dispatch_whenCatalogRequestMessage_shouldExtractScopes() {
277+ var authToken = "token";
278+ Map<String, Object> additional = Map.of("foo", "bar");
279+ var policy = Policy.Builder.newInstance().build();
280+ DspHttpRequestFactory<CatalogRequestMessage> rqFactory = mock();
281+ when(audienceResolver.resolve(any())).thenReturn(Result.success(AUDIENCE_VALUE));
282+ when(tokenDecorator.decorate(any())).thenAnswer(a -> a.getArgument(0, TokenParameters.Builder.class).claims(additional));
283+ when(rqFactory.createRequest(any())).thenReturn(new Request.Builder().url("http://url").build());
284+ when(httpClient.executeAsync(any(), isA(List.class))).thenReturn(completedFuture(dummyResponse(200)));
285+ when(identityService.obtainClientCredentials(any()))
286+ .thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token(authToken).build()));
287+
288+ dispatcher.registerPolicyScope(CatalogRequestMessage.class, "scope.test", (m) -> policy);
289+
290+ when(policyEngine.evaluate(eq("scope.test"), eq(policy), any())).thenAnswer(a -> {
291+ PolicyContext context = a.getArgument(2);
292+ var builder = context.getContextData(RequestScope.Builder.class);
293+ builder.scope("policy-test-scope");
294+ return Result.success();
295+ });
296+
297+ dispatcher.registerMessage(CatalogRequestMessage.class, rqFactory, mock());
298+
299+ var message = CatalogRequestMessage.Builder.newInstance().additionalScopes("scope1", "scope2").build();
300+ var result = dispatcher.dispatch(String.class, message);
301+
302+ assertThat(result).succeedsWithin(timeout);
303+
304+ var captor = ArgumentCaptor.forClass(TokenParameters.class);
305+ verify(identityService).obtainClientCredentials(captor.capture());
306+ verify(httpClient).executeAsync(argThat(r -> authToken.equals(r.headers().get("Authorization"))), isA(List.class));
307+ verify(rqFactory).createRequest(message);
308+ verify(policyEngine).evaluate(any(), any(), argThat(ctx -> {
309+ var requestContext = ctx.getContextData(RequestContext.class);
310+ return requestContext.getMessage().getClass().equals(CatalogRequestMessage.class) && requestContext.getDirection().equals(RequestContext.Direction.Egress);
311+ }));
312+ assertThat(captor.getValue()).satisfies(tr -> {
313+ assertThat(tr.getStringClaim(SCOPE_CLAIM)).isEqualTo("policy-test-scope scope1 scope2");
314+ assertThat(tr.getStringClaim(AUDIENCE_CLAIM)).isEqualTo(AUDIENCE_VALUE);
315+ assertThat(tr.getClaims()).containsAllEntriesOf(additional);
316+ });
317+ }
318+
274319 @Test
275320 void dispatch_shouldEvaluatePolicy() {
276321 var policy = Policy.Builder.newInstance().build();
modified extensions/common/api/management-api-configuration/src/main/resources/management-api-version.json +1 −1
@@ -8,7 +8,7 @@
88 {
99 "version": "3.1.0-alpha",
1010 "urlPath": "/v3.1alpha",
11- "lastUpdated": "2024-07-09T09:17:00Z",
11+ "lastUpdated": "2024-07-10T09:17:00Z",
1212 "maturity": "alpha"
1313 }
1414 ]
modified extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/catalog/BaseCatalogApiController.java +2 −1
@@ -50,7 +50,8 @@
5050 var request = transformerRegistry.transform(requestBody, CatalogRequest.class)
5151 .orElseThrow(InvalidRequestException::new);
5252
53- service.requestCatalog(request.getCounterPartyId(), request.getCounterPartyAddress(), request.getProtocol(), request.getQuerySpec())
53+ var scopes = request.getAdditionalScopes().toArray(new String[0]);
54+ service.requestCatalog(request.getCounterPartyId(), request.getCounterPartyAddress(), request.getProtocol(), request.getQuerySpec(), scopes)
5455 .whenComplete((result, throwable) -> {
5556 try {
5657 response.resume(toResponse(result, throwable));
modified extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/catalog/CatalogApiExtension.java +2 −0
@@ -18,6 +18,7 @@
1818 import org.eclipse.edc.connector.controlplane.api.management.catalog.transform.JsonObjectToDatasetRequestTransformer;
1919 import org.eclipse.edc.connector.controlplane.api.management.catalog.v2.CatalogApiV2Controller;
2020 import org.eclipse.edc.connector.controlplane.api.management.catalog.v3.CatalogApiV3Controller;
21+import org.eclipse.edc.connector.controlplane.api.management.catalog.v31alpha.CatalogApiV31AlphaController;
2122 import org.eclipse.edc.connector.controlplane.api.management.catalog.validation.CatalogRequestValidator;
2223 import org.eclipse.edc.connector.controlplane.api.management.catalog.validation.DatasetRequestValidator;
2324 import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogService;
@@ -67,6 +68,7 @@
6768 var managementApiTransformerRegistry = transformerRegistry.forContext("management-api");
6869 webService.registerResource(ApiContext.MANAGEMENT, new CatalogApiV2Controller(service, managementApiTransformerRegistry, validatorRegistry, context.getMonitor()));
6970 webService.registerResource(ApiContext.MANAGEMENT, new CatalogApiV3Controller(service, managementApiTransformerRegistry, validatorRegistry));
71+ webService.registerResource(ApiContext.MANAGEMENT, new CatalogApiV31AlphaController(service, managementApiTransformerRegistry, validatorRegistry));
7072
7173 validatorRegistry.register(CATALOG_REQUEST_TYPE, CatalogRequestValidator.instance(criterionOperatorRegistry));
7274 validatorRegistry.register(DATASET_REQUEST_TYPE, DatasetRequestValidator.instance());
modified extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/catalog/transform/JsonObjectToCatalogRequestTransformer.java +12 −8
@@ -22,8 +22,8 @@
2222 import org.jetbrains.annotations.NotNull;
2323 import org.jetbrains.annotations.Nullable;
2424
25-import java.util.Optional;
26-
25+import static java.util.Optional.ofNullable;
26+import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_ADDITIONAL_SCOPES;
2727 import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_COUNTER_PARTY_ADDRESS;
2828 import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_COUNTER_PARTY_ID;
2929 import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_PROTOCOL;
@@ -40,21 +40,25 @@
4040 var counterPartyAddress = transformString(object.get(CATALOG_REQUEST_COUNTER_PARTY_ADDRESS), context);
4141
4242 // For backward compatibility if the ID is not sent, fallback to the counterPartyAddress
43- var counterPartyId = Optional.ofNullable(object.get(CATALOG_REQUEST_COUNTER_PARTY_ID))
43+ var counterPartyId = ofNullable(object.get(CATALOG_REQUEST_COUNTER_PARTY_ID))
4444 .map(it -> transformString(it, context))
4545 .orElse(counterPartyAddress);
4646
47- var querySpec = Optional.of(object)
48- .map(it -> it.get(CATALOG_REQUEST_QUERY_SPEC))
47+ var querySpec = ofNullable(object.get(CATALOG_REQUEST_QUERY_SPEC))
4948 .map(it -> transformObject(it, QuerySpec.class, context))
5049 .orElse(null);
5150
52- return CatalogRequest.Builder.newInstance()
51+ var builder = CatalogRequest.Builder.newInstance()
5352 .protocol(transformString(object.get(CATALOG_REQUEST_PROTOCOL), context))
5453 .counterPartyAddress(counterPartyAddress)
5554 .counterPartyId(counterPartyId)
56- .querySpec(querySpec)
57- .build();
55+ .querySpec(querySpec);
56+
57+
58+ ofNullable(object.getJsonArray(CATALOG_REQUEST_ADDITIONAL_SCOPES))
59+ .ifPresent(ja -> builder.additionalScopes(ja.stream().map(this::nodeValue).toList()));
60+
61+ return builder.build();
5862 }
5963
6064 }
added extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/catalog/v31alpha/CatalogApiV31AlphaController.java +52 −0
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+ *
4+ * This program and the accompanying materials are made available under the
5+ * terms of the Apache License, Version 2.0 which is available at
6+ * https://www.apache.org/licenses/LICENSE-2.0
7+ *
8+ * SPDX-License-Identifier: Apache-2.0
9+ *
10+ * Contributors:
11+ * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
12+ *
13+ */
14+
15+package org.eclipse.edc.connector.controlplane.api.management.catalog.v31alpha;
16+
17+import jakarta.json.JsonObject;
18+import jakarta.ws.rs.Consumes;
19+import jakarta.ws.rs.POST;
20+import jakarta.ws.rs.Path;
21+import jakarta.ws.rs.Produces;
22+import jakarta.ws.rs.container.AsyncResponse;
23+import jakarta.ws.rs.container.Suspended;
24+import org.eclipse.edc.connector.controlplane.api.management.catalog.BaseCatalogApiController;
25+import org.eclipse.edc.connector.controlplane.services.spi.catalog.CatalogService;
26+import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
27+import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
28+
29+import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
30+
31+@Consumes(APPLICATION_JSON)
32+@Produces(APPLICATION_JSON)
33+@Path("/v3.1alpha/catalog")
34+public class CatalogApiV31AlphaController extends BaseCatalogApiController implements CatalogApiV31alpha {
35+ public CatalogApiV31AlphaController(CatalogService service, TypeTransformerRegistry transformerRegistry, JsonObjectValidatorRegistry validatorRegistry) {
36+ super(service, transformerRegistry, validatorRegistry);
37+ }
38+
39+ @POST
40+ @Path("/request")
41+ @Override
42+ public void requestCatalogV31alpha(JsonObject request, @Suspended AsyncResponse response) {
43+ requestCatalog(request, response);
44+ }
45+
46+ @POST
47+ @Path("dataset/request")
48+ @Override
49+ public void getDatasetV31alpha(JsonObject request, @Suspended AsyncResponse response) {
50+ getDataset(request, response);
51+ }
52+}
added extensions/control-plane/api/management-api/catalog-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/catalog/v31alpha/CatalogApiV31alpha.java +252 −0
@@ -0,0 +1,252 @@
1+/*
2+ * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+ *
4+ * This program and the accompanying materials are made available under the
5+ * terms of the Apache License, Version 2.0 which is available at
6+ * https://www.apache.org/licenses/LICENSE-2.0
7+ *
8+ * SPDX-License-Identifier: Apache-2.0
9+ *
10+ * Contributors:
11+ * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
12+ *
13+ */
14+
15+package org.eclipse.edc.connector.controlplane.api.management.catalog.v31alpha;
16+
17+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
18+import io.swagger.v3.oas.annotations.Operation;
19+import io.swagger.v3.oas.annotations.info.Info;
20+import io.swagger.v3.oas.annotations.media.Content;
21+import io.swagger.v3.oas.annotations.media.Schema;
22+import io.swagger.v3.oas.annotations.parameters.RequestBody;
23+import io.swagger.v3.oas.annotations.responses.ApiResponse;
24+import io.swagger.v3.oas.annotations.tags.Tag;
25+import jakarta.json.JsonObject;
26+import jakarta.ws.rs.container.AsyncResponse;
27+import jakarta.ws.rs.container.Suspended;
28+import org.eclipse.edc.api.model.ApiCoreSchema;
29+
30+import java.util.List;
31+
32+import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
33+import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
34+import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_TYPE;
35+import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT;
36+import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
37+
38+@OpenAPIDefinition(info = @Info(version = "v3"))
39+@Tag(name = "Catalog V3")
40+public interface CatalogApiV31alpha {
41+
42+ @Operation(
43+ requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = CatalogRequestSchema.class))),
44+ responses = { @ApiResponse(
45+ content = @Content(
46+ mediaType = "application/json",
47+ schema = @Schema(implementation = CatalogSchema.class)
48+ ),
49+ description = "Gets contract offers (=catalog) of a single connector") }
50+ )
51+ void requestCatalogV31alpha(JsonObject request, @Suspended AsyncResponse response);
52+
53+ @Operation(
54+ requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = DatasetRequestSchema.class))),
55+ responses = { @ApiResponse(
56+ content = @Content(
57+ mediaType = "application/json",
58+ schema = @Schema(implementation = DatasetSchema.class)
59+ ),
60+ description = "Gets single dataset from a connector") }
61+ )
62+ void getDatasetV31alpha(JsonObject request, @Suspended AsyncResponse response);
63+
64+ @Schema(name = "CatalogRequest", example = CatalogRequestSchema.CATALOG_REQUEST_EXAMPLE)
65+ record CatalogRequestSchema(
66+ @Schema(name = CONTEXT, requiredMode = REQUIRED)
67+ Object context,
68+ @Schema(name = TYPE, example = CATALOG_REQUEST_TYPE)
69+ String type,
70+ @Schema(requiredMode = REQUIRED)
71+ String counterPartyAddress,
72+ // Switch to required in the next API iteration
73+ @Schema(requiredMode = NOT_REQUIRED)
74+ String counterPartyId,
75+ @Schema(requiredMode = REQUIRED)
76+ String protocol,
77+ @Schema(requiredMode = NOT_REQUIRED)
78+ List<String> additionalScopes,
79+ ApiCoreSchema.QuerySpecSchema querySpec) {
80+
81+ public static final String CATALOG_REQUEST_EXAMPLE = """
82+ {
83+ "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/" },
84+ "@type": "CatalogRequest",
85+ "counterPartyAddress": "http://provider-address",
86+ "counterPartyId": "providerId",
87+ "protocol": "dataspace-protocol-http",
88+ "additionalScopes": [ "org.eclipse.edc.vc.type:SomeCredential:read", "org.eclipse.edc.vc.type:AnotherCredential:write" ],
89+ "querySpec": {
90+ "offset": 0,
91+ "limit": 50,
92+ "sortOrder": "DESC",
93+ "sortField": "fieldName",
94+ "filterExpression": []
95+ }
96+ }
97+ """;
98+ }
99+
100+ @Schema(name = "DatasetRequest", example = DatasetRequestSchema.DATASET_REQUEST_EXAMPLE)
101+ record DatasetRequestSchema(
102+ @Schema(name = TYPE, example = CATALOG_REQUEST_TYPE)
103+ String type,
104+ String counterPartyAddress,
105+ String counterPartyId,
106+ String protocol,
107+ ApiCoreSchema.QuerySpecSchema querySpec) {
108+
109+ public static final String DATASET_REQUEST_EXAMPLE = """
110+ {
111+ "@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/" },
112+ "@type": "DatasetRequest",
113+ "@id": "dataset-id",
114+ "counterPartyAddress": "http://counter-party-address",
115+ "counterPartyId": "counter-party-id",
116+ "protocol": "dataspace-protocol-http"
117+ }
118+ """;
119+ }
120+
121+ @Schema(name = "Catalog", description = "DCAT catalog", example = CatalogSchema.CATALOG_EXAMPLE)
122+ record CatalogSchema(
123+ ) {
124+ public static final String CATALOG_EXAMPLE = """
125+ {
126+ "@id": "7df65569-8c59-4013-b1c0-fa14f6641bf2",
127+ "@type": "dcat:Catalog",
128+ "dcat:dataset": {
129+ "@id": "bcca61be-e82e-4da6-bfec-9716a56cef35",
130+ "@type": "dcat:Dataset",
131+ "odrl:hasPolicy": {
132+ "@id": "OGU0ZTMzMGMtODQ2ZS00ZWMxLThmOGQtNWQxNWM0NmI2NmY4:YmNjYTYxYmUtZTgyZS00ZGE2LWJmZWMtOTcxNmE1NmNlZjM1:NDY2ZTZhMmEtNjQ1Yy00ZGQ0LWFlZDktMjdjNGJkZTU4MDNj",
133+ "@type": "odrl:Set",
134+ "odrl:permission": {
135+ "odrl:target": "bcca61be-e82e-4da6-bfec-9716a56cef35",
136+ "odrl:action": {
137+ "odrl:type": "http://www.w3.org/ns/odrl/2/use"
138+ },
139+ "odrl:constraint": {
140+ "odrl:and": [
141+ {
142+ "odrl:leftOperand": "https://w3id.org/edc/v0.0.1/ns/inForceDate",
143+ "odrl:operator": {
144+ "@id": "odrl:gteq"
145+ },
146+ "odrl:rightOperand": "2023-07-07T07:19:58.585601395Z"
147+ },
148+ {
149+ "odrl:leftOperand": "https://w3id.org/edc/v0.0.1/ns/inForceDate",
150+ "odrl:operator": {
151+ "@id": "odrl:lteq"
152+ },
153+ "odrl:rightOperand": "2023-07-12T07:19:58.585601395Z"
154+ }
155+ ]
156+ }
157+ },
158+ "odrl:prohibition": [],
159+ "odrl:obligation": []
160+ },
161+ "dcat:distribution": [
162+ {
163+ "@type": "dcat:Distribution",
164+ "dct:format": {
165+ "@id": "HttpData"
166+ },
167+ "dcat:accessService": "5e839777-d93e-4785-8972-1005f51cf367"
168+ }
169+ ],
170+ "description": "description",
171+ "id": "bcca61be-e82e-4da6-bfec-9716a56cef35"
172+ },
173+ "dcat:service": {
174+ "@id": "5e839777-d93e-4785-8972-1005f51cf367",
175+ "@type": "dcat:DataService",
176+ "dct:terms": "connector",
177+ "dct:endpointUrl": "http://localhost:16806/protocol"
178+ },
179+ "dspace:participantId": "urn:connector:provider",
180+ "@context": {
181+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
182+ "dct": "http://purl.org/dc/terms/",
183+ "edc": "https://w3id.org/edc/v0.0.1/ns/",
184+ "dcat": "http://www.w3.org/ns/dcat#",
185+ "odrl": "http://www.w3.org/ns/odrl/2/",
186+ "dspace": "https://w3id.org/dspace/v0.8/"
187+ }
188+ }
189+ """;
190+ }
191+
192+ @Schema(name = "Dataset", description = "DCAT dataset", example = DatasetSchema.DATASET_EXAMPLE)
193+ record DatasetSchema(
194+ ) {
195+ public static final String DATASET_EXAMPLE = """
196+ {
197+ "@id": "bcca61be-e82e-4da6-bfec-9716a56cef35",
198+ "@type": "dcat:Dataset",
199+ "odrl:hasPolicy": {
200+ "@id": "OGU0ZTMzMGMtODQ2ZS00ZWMxLThmOGQtNWQxNWM0NmI2NmY4:YmNjYTYxYmUtZTgyZS00ZGE2LWJmZWMtOTcxNmE1NmNlZjM1:NDY2ZTZhMmEtNjQ1Yy00ZGQ0LWFlZDktMjdjNGJkZTU4MDNj",
201+ "@type": "odrl:Set",
202+ "odrl:permission": {
203+ "odrl:target": "bcca61be-e82e-4da6-bfec-9716a56cef35",
204+ "odrl:action": {
205+ "odrl:type": "http://www.w3.org/ns/odrl/2/use"
206+ },
207+ "odrl:constraint": {
208+ "odrl:and": [
209+ {
210+ "odrl:leftOperand": "https://w3id.org/edc/v0.0.1/ns/inForceDate",
211+ "odrl:operator": {
212+ "@id": "odrl:gteq"
213+ },
214+ "odrl:rightOperand": "2023-07-07T07:19:58.585601395Z"
215+ },
216+ {
217+ "odrl:leftOperand": "https://w3id.org/edc/v0.0.1/ns/inForceDate",
218+ "odrl:operator": {
219+ "@id": "odrl:lteq"
220+ },
221+ "odrl:rightOperand": "2023-07-12T07:19:58.585601395Z"
222+ }
223+ ]
224+ }
225+ },
226+ "odrl:prohibition": [],
227+ "odrl:obligation": [],
228+ "odrl:target": "bcca61be-e82e-4da6-bfec-9716a56cef35"
229+ },
230+ "dcat:distribution": [
231+ {
232+ "@type": "dcat:Distribution",
233+ "dct:format": {
234+ "@id": "HttpData"
235+ },
236+ "dcat:accessService": "5e839777-d93e-4785-8972-1005f51cf367"
237+ }
238+ ],
239+ "description": "description",
240+ "id": "bcca61be-e82e-4da6-bfec-9716a56cef35",
241+ "@context": {
242+ "@vocab": "https://w3id.org/edc/v0.0.1/ns/",
243+ "dct": "http://purl.org/dc/terms/",
244+ "edc": "https://w3id.org/edc/v0.0.1/ns/",
245+ "dcat": "http://www.w3.org/ns/dcat#",
246+ "odrl": "http://www.w3.org/ns/odrl/2/",
247+ "dspace": "https://w3id.org/dspace/v0.8/"
248+ }
249+ }
250+ """;
251+ }
252+}
modified extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/catalog/CatalogApiExtensionTest.java +2 −0
@@ -16,6 +16,7 @@
1616
1717 import org.eclipse.edc.connector.controlplane.api.management.catalog.v2.CatalogApiV2Controller;
1818 import org.eclipse.edc.connector.controlplane.api.management.catalog.v3.CatalogApiV3Controller;
19+import org.eclipse.edc.connector.controlplane.api.management.catalog.v31alpha.CatalogApiV31AlphaController;
1920 import org.eclipse.edc.junit.extensions.DependencyInjectionExtension;
2021 import org.eclipse.edc.spi.system.ServiceExtensionContext;
2122 import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
@@ -58,5 +59,6 @@
5859
5960 verify(webService).registerResource(any(), isA(CatalogApiV2Controller.class));
6061 verify(webService).registerResource(any(), isA(CatalogApiV3Controller.class));
62+ verify(webService).registerResource(any(), isA(CatalogApiV31AlphaController.class));
6163 }
6264 }
modified extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/catalog/transform/JsonObjectToCatalogRequestTransformerTest.java +54 −0
@@ -14,6 +14,7 @@
1414
1515 package org.eclipse.edc.connector.controlplane.api.management.catalog.transform;
1616
17+import com.apicatalog.jsonld.document.JsonDocument;
1718 import jakarta.json.Json;
1819 import jakarta.json.JsonObject;
1920 import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest;
@@ -21,7 +22,11 @@
2122 import org.eclipse.edc.transform.spi.TransformerContext;
2223 import org.junit.jupiter.api.Test;
2324
25+import java.util.List;
26+
27+import static com.apicatalog.jsonld.JsonLd.expand;
2428 import static org.assertj.core.api.Assertions.assertThat;
29+import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_ADDITIONAL_SCOPES;
2530 import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_COUNTER_PARTY_ADDRESS;
2631 import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_COUNTER_PARTY_ID;
2732 import static org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest.CATALOG_REQUEST_PROTOCOL;
@@ -91,6 +96,48 @@
9196 verify(context).transform(querySpecJson, QuerySpec.class);
9297 }
9398
99+ @Test
100+ void transform_withAdditionalScopes() {
101+ var querySpec = QuerySpec.Builder.newInstance().build();
102+ var querySpecJson = Json.createObjectBuilder().build();
103+ when(context.transform(any(), eq(QuerySpec.class))).thenReturn(querySpec);
104+ var json = Json.createObjectBuilder()
105+ .add(TYPE, CATALOG_REQUEST_TYPE)
106+ .add(CATALOG_REQUEST_PROTOCOL, "protocol")
107+ .add(CATALOG_REQUEST_COUNTER_PARTY_ADDRESS, "http://provider/url")
108+ .add(CATALOG_REQUEST_COUNTER_PARTY_ID, "counterPartyId")
109+ .add(CATALOG_REQUEST_QUERY_SPEC, querySpecJson)
110+ .add(CATALOG_REQUEST_ADDITIONAL_SCOPES, Json.createArrayBuilder(List.of("scope1", "scope2")).build())
111+ .build();
112+
113+ var result = transformer.transform(getExpanded(json), context);
114+
115+ assertThat(result).isNotNull();
116+ assertThat(result.getAdditionalScopes()).containsExactlyInAnyOrder("scope1", "scope2");
117+ verify(context).transform(querySpecJson, QuerySpec.class);
118+ }
119+
120+ @Test
121+ void transform_withAdditionalScopes_singleObject() {
122+ var querySpec = QuerySpec.Builder.newInstance().build();
123+ var querySpecJson = Json.createObjectBuilder().build();
124+ when(context.transform(any(), eq(QuerySpec.class))).thenReturn(querySpec);
125+ var json = Json.createObjectBuilder()
126+ .add(TYPE, CATALOG_REQUEST_TYPE)
127+ .add(CATALOG_REQUEST_PROTOCOL, "protocol")
128+ .add(CATALOG_REQUEST_COUNTER_PARTY_ADDRESS, "http://provider/url")
129+ .add(CATALOG_REQUEST_COUNTER_PARTY_ID, "counterPartyId")
130+ .add(CATALOG_REQUEST_QUERY_SPEC, querySpecJson)
131+ .add(CATALOG_REQUEST_ADDITIONAL_SCOPES, "scope1")
132+ .build();
133+
134+ var result = transformer.transform(getExpanded(json), context);
135+
136+ assertThat(result).isNotNull();
137+ assertThat(result.getAdditionalScopes()).containsExactly("scope1");
138+ verify(context).transform(querySpecJson, QuerySpec.class);
139+ }
140+
94141 @Test
95142 void transform_shouldHandleEmptyQuerySpec() {
96143 var json = Json.createObjectBuilder()
@@ -106,4 +153,11 @@
106153 verifyNoInteractions(context);
107154 }
108155
156+ private JsonObject getExpanded(JsonObject message) {
157+ try {
158+ return expand(JsonDocument.of(message)).get().asJsonArray().getJsonObject(0);
159+ } catch (Exception e) {
160+ throw new AssertionError(e);
161+ }
162+ }
109163 }
added extensions/control-plane/api/management-api/catalog-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/catalog/v31alpha/CatalogApiV31AlphaControllerTest.java +76 −0
@@ -0,0 +1,76 @@
1+/*
2+ * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3+ *
4+ * This program and the accompanying materials are made available under the
5+ * terms of the Apache License, Version 2.0 which is available at
6+ * https://www.apache.org/licenses/LICENSE-2.0
7+ *
8+ * SPDX-License-Identifier: Apache-2.0
9+ *
10+ * Contributors:
11+ * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
12+ *
13+ */
14+
15+package org.eclipse.edc.connector.controlplane.api.management.catalog.v31alpha;
16+
17+import jakarta.json.Json;
18+import jakarta.json.JsonObject;
19+import org.eclipse.edc.connector.controlplane.api.management.catalog.BaseCatalogApiControllerTest;
20+import org.eclipse.edc.connector.controlplane.catalog.spi.CatalogRequest;
21+import org.eclipse.edc.spi.response.StatusResult;
22+import org.eclipse.edc.spi.result.Result;
23+import org.eclipse.edc.validator.spi.ValidationResult;
24+import org.junit.jupiter.api.Test;
25+import org.mockito.ArgumentCaptor;
26+
27+import java.util.List;
28+
29+import static io.restassured.RestAssured.given;
30+import static io.restassured.http.ContentType.JSON;
31+import static java.util.concurrent.CompletableFuture.completedFuture;
32+import static org.assertj.core.api.Assertions.assertThat;
33+import static org.mockito.ArgumentMatchers.any;
34+import static org.mockito.ArgumentMatchers.argThat;
35+import static org.mockito.ArgumentMatchers.eq;
36+import static org.mockito.Mockito.verify;
37+import static org.mockito.Mockito.when;
38+
39+class CatalogApiV31AlphaControllerTest extends BaseCatalogApiControllerTest {
40+
41+ @Test
42+ void requestCatalog_withAdditionalScopes() {
43+ var request = CatalogRequest.Builder.newInstance().counterPartyAddress("http://url").build();
44+ when(validatorRegistry.validate(any(), any())).thenReturn(ValidationResult.success());
45+ when(transformerRegistry.transform(argThat(o -> o instanceof JsonObject jo && jo.containsKey(CatalogRequest.CATALOG_REQUEST_ADDITIONAL_SCOPES)), eq(CatalogRequest.class))).thenReturn(Result.success(request));
46+ when(service.requestCatalog(any(), any(), any(), any())).thenReturn(completedFuture(StatusResult.success("{}".getBytes())));
47+ var requestBody = Json.createObjectBuilder()
48+ .add(CatalogRequest.CATALOG_REQUEST_PROTOCOL, "any")
49+ .add(CatalogRequest.CATALOG_REQUEST_ADDITIONAL_SCOPES, Json.createArrayBuilder(List.of("scope1", "scope2")).build())
50+ .build();
51+
52+ given()
53+ .port(port)
54+ .contentType(JSON)
55+ .body(requestBody)
56+ .post(baseUrl() + "/request")
57+ .then()
58+ .statusCode(200)
59+ .contentType(JSON);
60+ var captor = ArgumentCaptor.forClass(JsonObject.class);
61+ verify(transformerRegistry).transform(captor.capture(), eq(CatalogRequest.class));
62+
63+ var jo = captor.getValue();
64+ assertThat(jo).containsKey(CatalogRequest.CATALOG_REQUEST_ADDITIONAL_SCOPES);
65+ }
66+
67+ @Override
68+ protected String baseUrl() {
69+ return "/v3.1alpha/catalog";
70+ }
71+
72+ @Override
73+ protected Object controller() {
74+ return new CatalogApiV31AlphaController(service, transformerRegistry, validatorRegistry);
75+ }
76+}
No newline at the end of the file
modified spi/common/core-spi/src/main/java/org/eclipse/edc/spi/iam/RequestScope.java +2 −3
@@ -24,11 +24,10 @@
2424 */
2525 public class RequestScope {
2626
27- private RequestScope() {
28- }
29-
3027 private Set<String> scopes = new HashSet<>();
3128
29+ private RequestScope() {
30+ }
3231
3332 public Set<String> getScopes() {
3433 return scopes;
modified spi/control-plane/catalog-spi/src/main/java/org/eclipse/edc/connector/controlplane/catalog/spi/CatalogRequest.java +19 −1
@@ -18,6 +18,9 @@
1818 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
1919 import org.eclipse.edc.spi.query.QuerySpec;
2020
21+import java.util.ArrayList;
22+import java.util.List;
23+
2124 import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
2225
2326 public class CatalogRequest {
@@ -27,7 +30,8 @@
2730 public static final String CATALOG_REQUEST_COUNTER_PARTY_ADDRESS = EDC_NAMESPACE + "counterPartyAddress";
2831 public static final String CATALOG_REQUEST_COUNTER_PARTY_ID = EDC_NAMESPACE + "counterPartyId";
2932 public static final String CATALOG_REQUEST_QUERY_SPEC = EDC_NAMESPACE + "querySpec";
30-
33+ public static final String CATALOG_REQUEST_ADDITIONAL_SCOPES = EDC_NAMESPACE + "additionalScopes";
34+ private List<String> additionalScopes = new ArrayList<>();
3135 private QuerySpec querySpec;
3236 private String counterPartyAddress;
3337 private String counterPartyId;
@@ -36,6 +40,10 @@
3640 private CatalogRequest() {
3741 }
3842
43+ public List<String> getAdditionalScopes() {
44+ return additionalScopes;
45+ }
46+
3947 public String getCounterPartyAddress() {
4048 return counterPartyAddress;
4149 }
@@ -85,6 +93,16 @@
8593 return this;
8694 }
8795
96+ public Builder additionalScopes(List<String> additionalScopes) {
97+ instance.additionalScopes = additionalScopes;
98+ return this;
99+ }
100+
101+ public Builder additionalScope(String additionalScope) {
102+ instance.additionalScopes.add(additionalScope);
103+ return this;
104+ }
105+
88106 public CatalogRequest build() {
89107 return instance;
90108 }
modified spi/control-plane/catalog-spi/src/main/java/org/eclipse/edc/connector/controlplane/catalog/spi/CatalogRequestMessage.java +13 −0
@@ -21,6 +21,9 @@
2121 import org.eclipse.edc.spi.types.domain.message.RemoteMessage;
2222 import org.jetbrains.annotations.NotNull;
2323
24+import java.util.ArrayList;
25+import java.util.Arrays;
26+import java.util.List;
2427 import java.util.Objects;
2528
2629 /**
@@ -30,6 +33,7 @@
3033 public class CatalogRequestMessage implements RemoteMessage {
3134
3235 private final Policy policy;
36+ private List<String> additionalScopes = new ArrayList<>();
3337 private String protocol = "unknown";
3438 private String counterPartyAddress;
3539 private String counterPartyId;
@@ -77,6 +81,10 @@
7781 return policy;
7882 }
7983
84+ public List<String> getAdditionalScopes() {
85+ return additionalScopes;
86+ }
87+
8088 public static class Builder {
8189 private final CatalogRequestMessage message;
8290
@@ -109,6 +117,11 @@
109117 return this;
110118 }
111119
120+ public CatalogRequestMessage.Builder additionalScopes(String... additionalScopes) {
121+ this.message.additionalScopes = Arrays.asList(additionalScopes);
122+ return this;
123+ }
124+
112125 public CatalogRequestMessage build() {
113126 Objects.requireNonNull(message.protocol, "protocol");
114127
modified spi/control-plane/control-plane-spi/src/main/java/org/eclipse/edc/connector/controlplane/services/spi/catalog/CatalogService.java +2 −1
@@ -27,9 +27,10 @@
2727 * @param counterPartyAddress the url of the provider.
2828 * @param protocol the protocol id string.
2929 * @param querySpec the {@link QuerySpec} object.
30+ * @param additionalScopes optional list of additional scope values that are intended for use with the IAM subsystem
3031 * @return the provider's catalog
3132 */
32- CompletableFuture<StatusResult<byte[]>> requestCatalog(String counterPartyId, String counterPartyAddress, String protocol, QuerySpec querySpec);
33+ CompletableFuture<StatusResult<byte[]>> requestCatalog(String counterPartyId, String counterPartyAddress, String protocol, QuerySpec querySpec, String... additionalScopes);
3334
3435 /**
3536 * Return the dataset