Skip to content

Commit aec34de

Browse files
committed
Merge branch 'doc/milestone-080M1' of https://github.com/bsinno/ditto into doc/milestone-080M1
2 parents 9dbb059 + 53b5d65 commit aec34de

File tree

99 files changed

+5464
-1958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5464
-1958
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![Build Status](https://travis-ci.org/eclipse/ditto.svg?branch=master)](https://travis-ci.org/eclipse/ditto)
99
[![Maven Central](https://img.shields.io/maven-metadata/v/http/central.maven.org/maven2/org/eclipse/ditto/ditto/maven-metadata.xml.svg)](http://search.maven.org/#search|ga|1|org.eclipse.ditto)
1010
[![License](https://img.shields.io/badge/License-EPL%202.0-green.svg)](https://opensource.org/licenses/EPL-2.0)
11+
[![Lines of code](https://img.shields.io/badge/dynamic/xml.svg?label=Lines%20of%20code&url=https%3A%2F%2Fwww.openhub.net%2Fprojects%2Feclipse-ditto.xml%3Fapi_key%3D11ac3aa12a364fd87b461559a7eedcc53e18fb5a4cf1e43e02cb7a615f1f3d4f&query=%2Fresponse%2Fresult%2Fproject%2Fanalysis%2Ftotal_code_lines&colorB=lightgrey)](https://www.openhub.net/p/eclipse-ditto)
1112

1213
[Eclipse Ditto](https://eclipse.org/ditto/) is the open-source project of Eclipse IoT that provides a ready-to-use functionality to manage the state of Digital Twins. It provides access to them and mediates between the physical world and this digital representation.
1314

documentation/src/main/resources/_posts/2018-05-02-connecting-ditto-hono.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ $ curl -X POST -i -u devops:devopsPw1! -H 'Content-Type: application/json' -d '{
202202
"connectionType": "amqp-10",
203203
"connectionStatus": "open",
204204
"uri": "amqp://consumer@HONO:[email protected]:15672",
205-
"authorizationContext": ["nginx:demo5"],
206205
"failoverEnabled": true,
207206
"sources": [{
208207
"addresses": [
209208
"telemetry/org.eclipse.ditto",
210209
"event/org.eclipse.ditto"
211-
]
210+
],
211+
"authorizationContext": ["nginx:demo5"]
212212
}]
213213
}
214214
}
@@ -345,13 +345,13 @@ $ curl -X POST -i -u devops:devopsPw1! -H 'Content-Type: application/json' -d '{
345345
"connectionType": "amqp-10",
346346
"connectionStatus": "open",
347347
"uri": "amqp://consumer@HONO:[email protected]:15672",
348-
"authorizationContext": ["nginx:demo5"],
349348
"failoverEnabled": true,
350349
"sources": [{
351350
"addresses": [
352351
"telemetry/org.eclipse.ditto",
353352
"event/org.eclipse.ditto"
354-
]
353+
],
354+
"authorizationContext": ["nginx:demo5"],
355355
}],
356356
"mappingContext": {
357357
"mappingEngine": "JavaScript",

documentation/src/main/resources/jsonschema/connection.json

+83-18
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,6 @@
4242
"amqps://user:password@localhost:5671"
4343
]
4444
},
45-
"authorizationContext": {
46-
"$id": "/properties/authorizationContext",
47-
"type": "array",
48-
"title": "The authorization context",
49-
"description": "The authorization context defines all authorization subjects associated with this connection",
50-
"uniqueItems": true,
51-
"items": {
52-
"$id": "/properties/authorizationContext/items",
53-
"type": "string",
54-
"title": "Authorization Subject",
55-
"description": "An authorization subject associated with this connection",
56-
"examples": [
57-
"myAuthorizationSubject"
58-
]
59-
}
60-
},
6145
"sources": {
6246
"$id": "/properties/sources",
6347
"type": "array",
@@ -68,7 +52,46 @@
6852
"$id": "/properties/sources/items",
6953
"type": "object",
7054
"title": "Source",
71-
"description": "A subscription source subscribed by this connection"
55+
"description": "A subscription source subscribed by this connection",
56+
"properties": {
57+
"addresses": {
58+
"$id": "/properties/sources/properties/addresses",
59+
"type": "array",
60+
"uniqueItems": true,
61+
"title": "Array of source addresses",
62+
"description": "The source addresses this connection consumes messages from.",
63+
"items": {
64+
"$id": "/properties/sources/items/addresses/items",
65+
"type": "string",
66+
"title": "Source address",
67+
"description": "A source address to consume messages from."
68+
}
69+
},
70+
"consumerCount": {
71+
"$id": "/properties/sources/items/properties/consumerCount",
72+
"type": "integer",
73+
"title": "Consumer count",
74+
"description": "The number of consumers that should be attached to each source address.",
75+
"default": 1
76+
},
77+
"authorizationContext": {
78+
"$id": "/properties/sources/items/properties/authorizationContext",
79+
"type": "array",
80+
"title": "The authorisation context",
81+
"description": "The authorization context defines all authorization subjects associated for this source. ",
82+
"uniqueItems": true,
83+
"items": {
84+
"$id": "/properties/authorizationContext/items",
85+
"type": "string",
86+
"title": "Authorization Subject",
87+
"description": "An authorization subject associated with this source. You can either use a fixed subject or use a placeholder that resolves header values from incoming messages. For example to use the `device_id` header in the subject, you can specify the placeholder `{{ header:device_id }}` which is then replaced by Ditto when a message from this source is processed. By using a placeholder you can access any header value: `{{ header:<any-header-name> }}`.",
88+
"examples": [
89+
"ditto:myAuthorizationSubject",
90+
"device:{{ header:device-id }}"
91+
]
92+
}
93+
}
94+
}
7295
}
7396
},
7497
"targets": {
@@ -81,7 +104,49 @@
81104
"$id": "/properties/targets/items",
82105
"type": "object",
83106
"title": "Target",
84-
"description": "A publish target served by this connection"
107+
"description": "A publish target served by this connection",
108+
"properties": {
109+
"address": {
110+
"$id": "/properties/targets/properties/address",
111+
"type": "string",
112+
"title": "Target address",
113+
"description": "The target address where events, commands and messages are published to. The following placeholders are allowed within the target address:\n * Thing ID: `{{ thing:id }}`\n * Thing Namespace: `{{ thing:namespace }}`\n * Thing Name: `{{ thing:name }}` (the part of the ID without the namespace)"
114+
},
115+
"topics": {
116+
"$id": "/properties/targets/items/properties/topics",
117+
"type": "array",
118+
"title": "Topics",
119+
"description": "The topics to which this target is registered for.",
120+
"uniqueItems": true,
121+
"items": {
122+
"type": "string",
123+
"enum": [
124+
"_/_/things/twin/events",
125+
"_/_/things/live/commands",
126+
"_/_/things/live/events",
127+
"_/_/things/live/messages"
128+
],
129+
"title": "Subscribed topics.",
130+
"description": "Contains the type of messages that are delivered to this target. You can receive\n * Thing events: `_/_/things/twin/events` (notification about twin change) \n * Live events: `_/_/things/live/events`\n * Live commands: `_/_/things/live/commands`\n * Live messages: `_/_/things/live/messages`"
131+
}
132+
},
133+
"authorizationContext": {
134+
"$id": "/properties/targets/items/properties/authorizationContext",
135+
"type": "array",
136+
"title": "The authorisation context",
137+
"description": "The authorization context defines all authorization subjects associated for this target. ",
138+
"uniqueItems": true,
139+
"items": {
140+
"$id": "/properties/authorizationContext/items",
141+
"type": "string",
142+
"title": "Authorization Subject",
143+
"description": "An authorization subject associated with this target.",
144+
"examples": [
145+
"ditto:myAuthorizationSubject"
146+
]
147+
}
148+
}
149+
}
85150
}
86151
},
87152
"clientCount": {

documentation/src/main/resources/pages/ditto/basic-connections.md

+77-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ tags: [connectivity]
55
permalink: basic-connections.html
66
---
77

8+
## Connection model
9+
810
{%
9-
include note.html content="To get started with connections right away, consolidate the [Manage connections](connectivity-manage-connections.html)
10-
page. "
11+
include note.html content="To get started with connections right away, consult the [Manage connections]
12+
(connectivity-manage-connections.html) page. "
1113
%}
1214

1315
You can integrate your Ditto instance with external messaging services such as
1416
[Eclipse Hono](https://eclipse.org/hono/) or a [RabbitMQ](https://www.rabbitmq.com/) broker via custom "connections".
1517

1618
A connection represents a communication channel for the exchange of messages between any service and Ditto. It
1719
requires a transport protocol, which is used to transmit [Ditto Protocol] messages. Ditto supports one-way and two-way
18-
communication over connections. This enables consumer/producer scenarios as well as fully-fledged command and response use cases. Nevertheless, those options might be limited by the used transport protocol and/or the other endpoint's
20+
communication over connections. This enables consumer/producer scenarios as well as fully-fledged command and response
21+
use cases. Nevertheless, those options might be limited by the transport protocol or the other endpoint's
1922
capabilities.
2023

2124
All connections are configured and supervised via Ditto's
@@ -35,15 +38,81 @@ for custom payload formats. Currently the following connection types are support
3538
The `sources` and `targets` identifier format depends on the `connectionType` and has therefore `connectionType`
3639
specific limitations. Those are documented with the corresponding protocol bindings.
3740

38-
A connection is initiated by the connectivity service. This obsoletes the need for client authorization, because
41+
A connection is initiated by the connectivity service. This obviates the need for client authorization, because
3942
Ditto becomes the client in this case. Nevertheless, to access resources within Ditto, the connection must know on
40-
which instance’s behalf it is acting. This is controlled via the configured `authorizationContext`, which holds a list of
41-
self-assigned authorization subjects. Before a connection can access a Ditto resource, one of its
42-
`authorizationSubject`s must be referenced in the used authorization mechanism, having the needed access rights. You
43-
can achieve this via [ACLs](basic-acl.html) or [Policies](basic-policy.html).
43+
whose behalf it is acting. This is controlled via the configured `authorisationContext`, which holds a list of
44+
self-assigned authorization subjects. Before a connection can access a Ditto resource, one of its
45+
`authorizationSubject`s must be granted the access rights by an authorization mechanism such as
46+
[ACLs](basic-acl.html) or [Policies](basic-policy.html).
4447

4548
For more information on the `mappingContext` see the corresponding [Payload Mapping Documentation](connectivity-mapping.html)
4649

50+
## Placeholders
51+
52+
The configuration of a connection allows to use placeholders at certain places. This allows more fine grained control
53+
over how messages are consumed or where they are published to. The general syntax of a placeholder is
54+
`{% raw %}{{ placeholder }}{% endraw %}`. A missing placeholder results in an error which is passed back to the sender (if a _reply-to_
55+
header was provided). Which placeholder values are available depends on the context where the placeholder is used.
56+
57+
### Placeholder for source authorization subjects
58+
Processing the messages received via a source using the _same fixed authorization subject_ may not be
59+
suitable for every scenario. For example you want to declare fine-grained write permissions per device which would not
60+
be possible with a fixed global subject. For this use case we introduced placeholder substitution for authorization subjects of
61+
source addresses that are resolved when processing messages from a source. Of course this requires the sender of the
62+
message to provide necessary information about the original issuer of the message.
63+
64+
{%
65+
include important.html content="Only use this kind of placeholder if you trust the source of the message. The value from the header is used as the **authorized subject**."
66+
%}
67+
68+
You can access any header value of the incoming message by using a placeholder like `{% raw %}{{ header:name }}{% endraw %}`.
69+
70+
Example:
71+
Assuming the messages received from the source _telemetry_ contain a `device_id` header (e.g. _sensor-123_),
72+
you may configure your source's authorization subject as follows:
73+
```json
74+
{
75+
"id": "auth-subject-placeholder-example",
76+
"sources": [
77+
{
78+
"addresses": [ "telemetry" ],
79+
"authorizationContext": ["device:{% raw %}{{ header:device_id }}{% endraw %}"]
80+
}
81+
]
82+
}
83+
```
84+
The placeholder is then replaced by the value from the message headers and the message is forwarded and processed under the
85+
subject _device:sensor-123_.
86+
In case the header cannot be resolved or the header contains unexpected characters an exception is thrown which is sent
87+
back to the sender as an error message, if a valid _reply-to_ header was provided, otherwise the message is dropped.
88+
89+
### Placeholder for target addresses
90+
Another use case for placeholders may be to publish thing events or live commands and events to a target address
91+
containing Thing-specific information e.g. you can distribute Things from different namespaces to different target addresses.
92+
You can use the placeholders `{% raw %}{{ thing:id }}{% endraw %}`, `{% raw %}{{ thing:namespace }}{% endraw %}` and `{% raw %}{{ thing:name }}{% endraw %}` in the target address for this purpose.
93+
For a Thing with the ID _org.eclipse.ditto:device-123_ these placeholders are resolved as follows:
94+
95+
| Placeholder | Description | Resolved value |
96+
|--------|------------|------------|
97+
| `thing:id` | Full ID composed of _namespace_ + _:_ as a separator + _name_ | org.eclipse.ditto:device-123 |
98+
| `thing:namespace` | Namespace (i.e. first part of an ID) | org.eclipse.ditto |
99+
| `thing:name` | Name (i.e. second part of an ID ) | device-123 |
100+
101+
102+
Example:
103+
Sending live commands and events to a target address that contains the Things' namespace.
104+
```json
105+
{
106+
"id": "target-placeholder-example",
107+
"targets": [
108+
{
109+
"addresses": [ "live/{% raw %}{{ thing:namespace }}{% endraw %}" ],
110+
"authorizationContext": ["ditto:auth-subject"],
111+
"topics": [ "_/_/things/live/events", "_/_/things/live/commands" ]
112+
}
113+
]
114+
}
115+
```
47116

48117
[Connectivity API]: connectivity-overview.html
49118
[Ditto Protocol]: protocol-overview.html

documentation/src/main/resources/pages/ditto/connectivity-manage-connections.md

+30
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,36 @@ The only parameter necessary for connection retrieval is the `connectionId`:
7777
}
7878
```
7979

80+
### Open connection
81+
82+
The only parameter necessary for opening a connection is the `connectionId`:
83+
84+
```json
85+
{
86+
"targetActorSelection": "/system/sharding/connection",
87+
"headers": {},
88+
"piggybackCommand": {
89+
"type": "connectivity.commands:openConnection",
90+
"connectionId":"<connectionID>"
91+
}
92+
}
93+
```
94+
95+
### Close connection
96+
97+
The only parameter necessary for closing a connection is the `connectionId`:
98+
99+
```json
100+
{
101+
"targetActorSelection": "/system/sharding/connection",
102+
"headers": {},
103+
"piggybackCommand": {
104+
"type": "connectivity.commands:closeConnection",
105+
"connectionId":"<connectionID>"
106+
}
107+
}
108+
```
109+
80110
### Delete connection
81111

82112
The only parameter necessary for connection deletion is the `connectionId`:

documentation/src/main/resources/pages/ditto/connectivity-protocol-bindings-amqp091.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,30 @@ Supported AMQP 0.9.1 properties which are interpreted in a specific way are:
2727
### Source format
2828

2929
An AMQP 0.9.1 connection requires the protocol configuration source object to have an `addresses` property with a list
30-
of queue names.
30+
of queue names and `authorizationContext` array that contains the authorization subjects in whose context
31+
incoming messages are processed. These subjects may contain placeholders, see
32+
[placeholders](basic-connections.html#placeholder-for-source-authorization-subjects) section for more information.
33+
3134

3235
```json
3336
{
3437
"addresses": [
3538
"<queue_name>",
3639
"..."
37-
]
40+
],
41+
"authorizationContext": ["ditto:inbound-auth-subject", "..."]
3842
}
3943
```
4044

4145
### Target format
4246

4347
An AMQP 0.9.1 connection requires the protocol configuration target object to have an `address` property with a combined
44-
value of the `exchange_name` and `routing_key`. It is continued with a list of topic strings, each representing a
45-
subscription of a Ditto [protocol topic](protocol-specification-topic.html).
48+
value of the `exchange_name` and `routing_key`. The target address may contain placeholders, see
49+
[placeholders](basic-connections.html#placeholder-for-target-addresses) section for more information.
50+
It is continued with a list of topic strings, each representing a
51+
subscription of a Ditto [protocol topic](protocol-specification-topic.html) and an array of authorization subjects.
52+
Outbound messages are published to the configured target address if one of these subjects have READ permission
53+
on the Thing that is associated with a message.
4654

4755

4856
```json
@@ -51,7 +59,8 @@ An AMQP 0.9.1 connection requires the protocol configuration target object to ha
5159
"topics": [
5260
"_/_/things/twin/events",
5361
"_/_/things/live/messages"
54-
]
62+
],
63+
"authorizationContext": ["ditto:outbound-auth-subject", "..."]
5564
}
5665
```
5766

@@ -76,13 +85,13 @@ Example connection configuration to create a new AMQP 0.9.1 connection (e.g. in
7685
"connectionType": "amqp-091",
7786
"connectionStatus": "open",
7887
"failoverEnabled": true,
79-
"uri": "amqp://user:password@localhost:5672",
88+
"uri": "amqp://user:password@localhost:5672/vhost",
8089
"sources": [
8190
{
8291
"addresses": [
8392
"queueName"
8493
],
85-
"authorizationContext": ["<<<my-subject-id-included-in-policy-or-acl>>>"]
94+
"authorizationContext": ["ditto:inbound-auth-subject", "..."]
8695
}
8796
],
8897
"targets": [
@@ -92,7 +101,7 @@ Example connection configuration to create a new AMQP 0.9.1 connection (e.g. in
92101
"_/_/things/twin/events",
93102
"_/_/things/live/messages"
94103
],
95-
"authorizationContext": ["<<<my-subject-id-included-in-policy-or-acl>>>"]
104+
"authorizationContext": ["ditto:outbound-auth-subject", "..."]
96105
}
97106
]
98107
}

0 commit comments

Comments
 (0)