Elffuss BraidHub

kikocis/EDC public

a74f4e2d1913 · 18.8 KiBRenderedRawPermalink
1# Dataspace Protocol Endpoints and Services Architecture
2
3The Dataspace Protocol requires all protocol message types to be serialized as JSON-LD. The IDS REST binding specifications further define how those serialized message types are bound to
4endpoints over HTTPS. Controller endpoints will be added to the EDC that support marshalling and unmarshalling JSON-LD messages as specified
5in [JSON-LD Processing Architecture document](json-ld-processing-architecture.md)
6
7IDS controller endpoints will be organized in two extensions to support separate deployments of control plane and catalog runtimes:
8
9| Description | Repository | Extension |
10|----------------------|------------|-------------------|
11| Contract Negotiation | Connector | control-plane-ids |
12| Transfer Process | Connector | control-plane-ids |
13| Catalog requests | Connector | catalog-ids |
14
15## Message (De)Marshalling
16
17Message demarshalling will be done by deserializing IDS JSON-LD messages and expanding them using the [Titanium JSON-LD Library](https://github.com/filip26/titanium-json-ld):
18
19```
20var document = JsonDocument.of(jsonObject);
21var expanded = JsonLd.expand(document).get();
22```
23
24__NOTE__: we need to verify if Jersey controllers can use `jakarta.json.JsonObject` as a type parameter directly. This will involve using the `ObjectMapper` from serialization
25context configured on the `TypeManager` with Jersey. If this is not possible, the controller parameters will need to be of type `Map<String, Object>` and we will need to
26transform them manually (or via a Jersey `ContainerRequestFilter`) using:
27
28```
29var converted = objectMapper.convertValue(message,JsonObject.class);
30```
31
32Message marshalling will be done by writing and compacting an in-memory `JsonObject` instance as follows:
33
34```
35var document = JsonDocument.of(jsonObject);
36var compacted = JsonLd.compact(document,EMPTY_CONTEXT).get();
37var compacted = mapper.convertValue(compacted,Map.class);
38```
39
40## Migrating to DCAT and ODRL Types: Catalog, Dataset, and Policy
41
42The Dataspace Protocol specifications overhaul the infomodel that underpins IDS by basing it directly on the [DCAT](https://www.w3.org/TR/vocab-dcat-3/)
43and [ODRL](https://w3c.github.io/poe/model/) specifications. One of the most significant changes is that assets (or datasets in DCAT terms) contain offers, which are ODRL policies.
44Moreover, datasets are contained in a catalog. This relationship corresponds to the core design of the EDC and should resolve the complexity mandated by the current IDS infomodel
45where contract offers contain assets.
46
47### The Catalog Type
48
49The existing `org.eclipse.edc.catalog.spi.Catalog` type will need to be migrated to the new DCAT-based model defined by IDS Dataspace Protocol. This section outlines three key aspects of the
50required refactoring: dataset projections; distribution projections; and support for open/extensible types.
51
52#### Dataset Projections
53
54Instead of `ContractOffer` instances, A `Catalog` will contain `DataSet` instances that correspond to an EDC `Asset` and a collection of policies that derive from
55matching `ContractDefinition`s. A replacement for the `ContractOfferResolver` will be needed that matches all `ContractDefinition`s for a `ParticipantAgent` and derives a
56collection of `Dataset`s that contain `Asset` properties and ODRL Offers corresponding to the usage policies of all matching `ContractDefinition`s for the asset. This can be
57represented as:
58
59```
60CD = Contract Definition
61A = Asset
62DS = Dataset
63O = ODRL Offer
64
65If the Contract Definitions are:
66
67CD 1 --selects--> [A1, A2]
68CD 2 --selects--> [A1, A3]
69
70the resulting Catalog containing Datasets is:
71
72DS 1 -> A1 [O:CD1, O:CD2]
73DS 2 -> A2 [O:CD1]
74DS 3 -> A3 [O:CD2]
75```
76
77#### Distribution Projections
78
79A DCAT Distribution is used to convey how to access a dataset: the endpoint for requesting a contract negotiation and the transport types supported by the provider. A Distribution
80is therefore a combination of connector endpoint metadata and the transport type attribute of the `DataAddress` associated with an `Asset`. Since Distributions are a projection, a
81single Distribution entry may be referenced by multiple Dataset instances. For example, if two assets are accessible from the same connector endpoint and have equal transport type
82attributes, they will reference the same Distribution.
83
84> The EDC does not currently have facilities for associating an asset with a connector endpoint. This will need to be defined and created.
85
86> When a `Catalog` is generated for a request, Distributions will also need to be created for the Dataset entries. The replacement for `ContractOfferResolver` will need to track
87> Distributions across Datasets as they are created. Another issue that will need to be dealt with is Assets and DataAddresses are stored independently since they are logically
88> distinct. The replacement service will need access to the associated DataAddress to generate Distributions. An efficient mechanism for accessing this data will need to be
89> designed.
90
91#### Open/Extensible Types
92
93Another consideration that will need to be made is that the DCAT `Catalog` and `Dataset` types are open: they may be arbitrarily extended using namespaced properties. Preserving
94namespace information will be handled by expanding JSON-LD messages, which will concatenate referenced namespaces with properties names (which can then in turn be stored in
95the `Asset` properties). The EDC will need to provide a mechanism for decorating `Catalog` instances with arbitrary properties when they are returned in response to catalog
96queries. For example, an EDC provider may wish to include a catalog description property. This mechanism can be implemented by creating a registry of `CatalogDecorator`s that can
97set arbitrary information as part of request processing.
98
99In a subsequent release, it may be desirable to create a generic `CatalogDecorator` that pulls arbitrary properties from an extensible source such as a database or configuration
100file.
101
102## Type Transformation
103
104The existing `IdsTypeTransformer` implementations will need to be re-written to accommodate the new IDS infomodel and message types. The expectation is that the number of
105transformers will be greatly reduced.
106
107`IdsTypeTransformer` for each message type will return types used by JSON-P such as `jakarta.json.JsonValue`. These types will then be set on an appropriate IDS message instance
108and the latter compacted before being returned by the controller.
109
110### Using JsonObject
111
112When processing a request, responses may include transforming from an EDC representation to an IDS JSON-LD structure. This can be achieved using `IdsTypeTransformer`
113implementations that produce `JsonObject` types. For example, assuming `org.eclipse.edc.catalog.spi.Catalog` is refactored to include a `Dataset` type as described above, a
114`FromCatalogTransformer` transformer can produce a `JsonObject` as follows:
115
116```
117public class FromCatalogTransformer extends AbstractJsonLdTransformer<Catalog, JsonObject> {
118 private final JsonBuilderFactory jsonFactory;
119 private final ObjectMapper mapper;
120
121 public FromCatalogTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) {
122 super(Catalog.class, JsonObject.class);
123 this.jsonFactory = jsonFactory;
124 this.mapper = mapper;
125 }
126
127 @Override
128 public @Nullable JsonObject transform(@Nullable Catalog catalog, @NotNull TransformerContext context) {
129 if (catalog == null) {
130 return null;
131 }
132
133 var objectBuilder = jsonFactory.createObjectBuilder();
134
135 var datasets = catalog.getDatasets().stream()
136 .map(offer -> context.transform(offer, JsonObject.class))
137 .collect(jsonFactory::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
138 .build();
139
140 objectBuilder.add(DCAT_SCHEMA + "dataset", datasets);
141
142 // transform properties, which are generic JSON values.
143 catalog.getProperties().forEach((k, v) -> objectBuilder.add(k, mapper.convertValue(v, JsonValue.class)));
144
145 return objectBuilder.build();
146 }
147}
148```
149
150The `catalog-ids` extension can register the transformer as follows:
151
152```
153// registry is injected on the extension instance
154
155builderFactory = Json.createBuilderFactory(Map.of());
156
157var fromCatalogTransformer = new FromCatalogTransformer(builderFactory, mapper);
158registry.register(fromCatalogTransformer);
159```
160
161Similarly, a `ToCatalogTransformer` can convert from a JSON=LD structure to the EDC `Catalog` type:
162
163```
164public class ToCatalogTransformer extends AbstractJsonLdTransformer<JsonObject, Catalog> {
165 private static final String DCAT_CATALOG = "http://www.w3.org/ns/dcat#Catalog";
166 private static final String DCAT_DATASET = "http://www.w3.org/ns/dcat#dataset";
167 private static final String DCAT_DISTRIBUTION = "http://www.w3.org/ns/dcat#distribution";
168 private static final String DCAT_DATA_SERVICE = "http://www.w3.org/ns/dcat#DataService";
169
170 public ToCatalogTransformer() {
171 super(JsonObject.class, Catalog.class);
172 }
173
174 @Override
175 public @Nullable Catalog transform(@Nullable JsonObject object, @NotNull TransformerContext context) {
176 if (object == null) {
177 return null;
178 }
179 var type = nodeType(object, context);
180 if (DCAT_CATALOG.equals(type)) {
181 var builder = Catalog.Builder.newInstance();
182
183 builder.id(nodeId(object));
184
185 visitProperties(object, (key, value) -> transformProperties(key, value, builder, context));
186
187 return builder.build();
188 }
189 return null;
190 }
191
192 private void transformProperties(String key, JsonValue value, Catalog.Builder builder, TransformerContext context) {
193 if (DCAT_DATASET.equals(key)) {
194 transformDatasets(value, builder, context);
195 } else if (DCAT_DISTRIBUTION.equals(key)) {
196 transformDistributions(value, builder, context);
197 } else if (DCAT_DATA_SERVICE.equals(key)) {
198 transformDataServices(value, builder, context);
199 } else {
200 transformGenericProperty(key, value, builder, context);
201 }
202 }
203
204 private void transformDatasets(JsonValue value, Catalog.Builder builder, TransformerContext context) {
205 if (value instanceof JsonArray) {
206 var jsonArray = (JsonArray) value;
207 var datasets = jsonArray.stream().map(entry -> context.transform(entry, Dataset.class)).collect(toList());
208 builder.datasets(datasets);
209 } else if (value instanceof JsonObject) {
210 var dataset = context.transform(value, Dataset.class);
211 builder.dataset(dataset);
212 } else {
213 context.reportProblem("Invalid dataset property");
214 }
215 }
216
217 private void transformDataServices(JsonValue value, Catalog.Builder builder, TransformerContext context) {
218 if (value instanceof JsonArray) {
219 var jsonArray = (JsonArray) value;
220 var dataServices = jsonArray.stream().map(entry -> context.transform(entry, DataService.class)).collect(toList());
221 // .... processing
222 } else if (value instanceof JsonObject) {
223 var dataService = context.transform(value, DataService.class);
224 // .... processing
225 } else {
226 context.reportProblem("Invalid DataService property");
227 }
228 }
229
230 private void transformDistributions(JsonValue value, Catalog.Builder builder, TransformerContext context) {
231 if (value instanceof JsonArray) {
232 var jsonArray = (JsonArray) value;
233 var distributions = jsonArray.stream().map(entry -> context.transform(entry, Distribution.class)).collect(toList());
234 // .... processing
235 } else if (value instanceof JsonObject) {
236 var distribution = context.transform(value, Distribution.class);
237 // .... processing
238 } else {
239 context.reportProblem("Invalid DataService property");
240 }
241 }
242
243 private void transformGenericProperty(String key, JsonValue value, Catalog.Builder builder, TransformerContext context) {
244 if (value instanceof JsonArray) {
245 var jsonArray = (JsonArray) value;
246 if (jsonArray.isEmpty()) {
247 builder.property(key, List.of());
248 } else if (jsonArray.size() == 1) {
249 // unwrap array
250 var result = context.transform(jsonArray.get(0), Object.class);
251 builder.property(key, result);
252 } else {
253 var result = jsonArray.stream().map(prop -> context.transform(prop, Object.class)).collect(toList());
254 builder.property(key, result);
255 }
256 } else {
257 var result = context.transform(value, Object.class);
258 builder.property(key, result);
259 }
260 }
261}
262```
263
264### Policy Transformation
265
266When transforming policies, there should be one `IdsTypeTransformer` for the root policy type that in turn dispatches to Policy.Visitor<T> instances to
267build the transformed object graph. This was not done in the original IDS transformer implementations. A sketch of the `FromPolicyTransformer` which converts an EDC `Policy`
268instance to a `JsonObject` using this approach is:
269
270```
271public class FromPolicyTransformer extends AbstractJsonLdTransformer<Policy, JsonObject> {
272 private final JsonBuilderFactory jsonFactory;
273 private final ObjectMapper mapper;
274
275 public FromPolicyTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) {
276 super(Policy.class, JsonObject.class);
277 this.jsonFactory = jsonFactory;
278 this.mapper = mapper;
279 }
280
281 @Override
282 public @Nullable JsonObject transform(@Nullable Policy policy, @NotNull TransformerContext context) {
283 if (policy == null) {
284 return null;
285 }
286 return policy.accept(new Visitor(context));
287 }
288
289 /**
290 * Walks the policy object model, transforming it to a JsonObject.
291 */
292 private static class Visitor implements Policy.Visitor<JsonObject>, Rule.Visitor<JsonObject>, Constraint.Visitor<JsonObject>, Expression.Visitor<JsonObject> {
293 private TransformerContext context;
294
295 public Visitor(TransformerContext context) {
296 this.context = context;
297 }
298
299 @Override
300 public JsonObject visitAndConstraint(AndConstraint andConstraint) {
301 for (var constraint : andConstraint.getConstraints()) {
302 var constraintObject = constraint.accept(this);
303 }
304
305 // .... create an AndConstraint representation and return it
306 return jsonObject;
307 }
308
309 @Override
310 public JsonObject visitOrConstraint(OrConstraint orConstraint) {
311 for (var constraint : orConstraint.getConstraints()) {
312 var constraintObject = constraint.accept(this);
313 }
314
315 // .... create an OrConstraint representation and return it
316 return jsonObject;
317 }
318
319 @Override
320 public JsonObject visitXoneConstraint(XoneConstraint xoneConstraint) {
321 for (var constraint : xoneConstraint.getConstraints()) {
322 var constraintObject = constraint.accept(this);
323 }
324
325 // .... create an XoneConstraint representation and return it
326 return jsonObject;
327 }
328
329 @Override
330 public JsonObject visitAtomicConstraint(AtomicConstraint atomicConstraint) {
331 var leftObject = atomicConstraint.getLeftExpression().accept(this);
332 var rightObject = atomicConstraint.getRightExpression().accept(this);
333
334 // .... create an AtomicConstraint representation and return it
335 return jsonObject;
336 }
337
338 @Override
339 public JsonObject visitLiteralExpression(LiteralExpression expression) {
340
341 // .... create an LiteralConstraint representation and return it (may be a JsonValue)
342 return jsonObject;
343 }
344
345 @Override
346 public JsonObject visitPolicy(Policy policy) {
347 policy.getPermissions().forEach(permission -> permission.accept(this));
348 policy.getProhibitions().forEach(prohibition -> prohibition.accept(this));
349 policy.getObligations().forEach(duty -> duty.accept(this));
350
351 // .... create an Policy representation and return it
352 return jsonObject;
353 }
354
355 @Override
356 public JsonObject visitPermission(Permission permission) {
357 if (permission.getDuties() != null) {
358 for (var duty : permission.getDuties()) {
359 var constraintsArray = visitRule(duty);
360 }
361 }
362 var constraintsArray = visitRule(permission);
363
364 // .... create an Permission representation and return it
365 return jsonObject;
366 }
367
368 @Override
369 public JsonObject visitProhibition(Prohibition prohibition) {
370 var constraintsArray = visitRule(prohibition);
371
372 // .... create an Prohibition representation and return it
373 return jsonObject;
374 }
375
376 @Override
377 public JsonObject visitDuty(Duty duty) {
378 var constraintsArray = visitRule(duty);
379
380 // .... create a Duty representation and return it
381 return jsonObject;
382 }
383
384 private JsonArray visitRule(Rule rule) {
385 // .... create an JsonArray representation and return it
386
387 for (Constraint constraint : rule.getConstraints()) {
388 var result = constraint.accept(this);
389 // ... add results to the array
390 }
391
392 return jsonArray;
393 }
394 }
395}
396```
397
398> Note that the policy transformers may eventually be moved to a lower-level JSON-LD extension if they can be reused by other subsystems such as the Management API extensions.
399
400### Asset Transformation and Extensible Properties
401
402Asset properties may be extensible complex types.
403
404TODO Can be transformed here but DataManagement API will need to be updated
405
406## Identity Providers
407
408> Note: DAT tokens are no longer supported for provider responses.
409
410> Note: The IDS specifications need a way for a catalog to declare supported trust anchors. For example, information on what identity systems are supported and where a client
411> connector can obtain a security token. This can be added as part of a `CatalogDecorator`. This will require the `CatalogDecorator` to have access to the requesting participant
412> agent's claims to determine which trust anchor's to include. For example, a participant agent may request data in the context of a particular dataspace that mandates a
413> centralized trust anchor.
414
415## Remote Message Dispatching
416
417The remote message dispatching infrastructure (`RemoteMessageDispatcher`) will need to be updated to support REST-based catalog requests, transfer requests, and contract
418negotiation requests. The protocol identifier will be "IDS Dataspace Protocol" until a specification version is officially assigned. This can be done in parallel to the existing IDS multipart
419dispatchers.
420
421