Skip to content

Commit dde7c51

Browse files
Merge pull request opentripplanner#5682 from Skanetrafiken/67039-federated-identity-service-bus
Add configuration switch for Service Bus authentication with Federate…
2 parents 8ba2fb8 + f8f6dab commit dde7c51

File tree

21 files changed

+495
-47
lines changed

21 files changed

+495
-47
lines changed

doc-templates/UpdaterConfig.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ GBFS form factors:
8282
## Other updaters in sandboxes
8383

8484
- [Vehicle parking](sandbox/VehicleParking.md)
85-
- [Siri over HTTP](sandbox/SiriUpdater.md)
86-
- [Siri over Azure Message Bus](sandbox/SiriAzureUpdater.md)
85+
- [Siri over HTTP](sandbox/siri/SiriUpdater.md)
86+
- [Siri over Azure Message Bus](sandbox/siri/SiriAzureUpdater.md)
8787
- [VehicleRentalServiceDirectory](sandbox/VehicleRentalServiceDirectory.md)
8888

docs/sandbox/SiriAzureUpdater.md doc-templates/sandbox/siri/SiriAzureUpdater.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,26 @@ IT also OTP to download historical data from en HTTP endpoint on startup.
88
Skånetrafiken, Sweden
99
developer.otp@skanetrafiken.se
1010

11+
## Documentation
12+
13+
Documentation available [here](../../examples/skanetrafiken/Readme.md).
14+
15+
## Configuration
16+
17+
To enable the SIRI updater you need to add it to the updaters section of the `router-config.json`.
18+
19+
### Siri Azure ET Updater
20+
21+
<!-- INSERT: siri-azure-et-updater -->
22+
23+
### Siri Azure SX Updater
24+
25+
<!-- INSERT: siri-azure-sx-updater -->
26+
1127
## Changelog
12-
- Added configuration for turning off stop arrival time match feature.
28+
- Added configuration for turning off stop arrival time match feature.
1329
- Initial version (April 2022)
1430
- Minor changes in logging (November 2022)
1531
- Retry fetch from history endpoint if it failed (February 2023)
1632
- Solve a bug in SiriAzureETUpdater and improve error logging (March 2023)
17-
18-
## Documentation
19-
20-
Documentation available [here](../examples/skanetrafiken/Readme.md).
21-
22-
### Configuration
23-
24-
See example configuration in `examples/skanetrafiken/router-config.json`.
33+
- Add support with federated identity authentication (February 2024)
File renamed without changes.

docs/RouterConfiguration.md

+14
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,20 @@ Used to group requests when monitoring OTP.
817817
"toDateTime" : "P1D",
818818
"timeout" : 300000
819819
}
820+
},
821+
{
822+
"type" : "siri-azure-et-updater",
823+
"topic" : "some_topic",
824+
"authenticationType" : "SharedAccessKey",
825+
"fullyQualifiedNamespace" : "fully_qualified_namespace",
826+
"servicebus-url" : "service_bus_url",
827+
"feedId" : "feed_id",
828+
"customMidnight" : 4,
829+
"history" : {
830+
"url" : "endpoint_url",
831+
"fromDateTime" : "-P1D",
832+
"timeout" : 300000
833+
}
820834
}
821835
],
822836
"rideHailingServices" : [

docs/UpdaterConfig.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ HTTP headers to add to the request. Any header key, value can be inserted.
414414
## Other updaters in sandboxes
415415

416416
- [Vehicle parking](sandbox/VehicleParking.md)
417-
- [Siri over HTTP](sandbox/SiriUpdater.md)
418-
- [Siri over Azure Message Bus](sandbox/SiriAzureUpdater.md)
417+
- [Siri over HTTP](sandbox/siri/SiriUpdater.md)
418+
- [Siri over Azure Message Bus](sandbox/siri/SiriAzureUpdater.md)
419419
- [VehicleRentalServiceDirectory](sandbox/VehicleRentalServiceDirectory.md)
420420

docs/examples/skanetrafiken/Readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ id from the message. In case OTP was not able to find corresponding trip additio
9393
performed based on arrival-times/stop-patterns from the ET message. This feature turned off by default but can be
9494
activated by adding *fuzzyTripMatching* property to updater configuration.
9595

96+
### FederatedIdentity
97+
It is also possible to connect to Service Bus through FederatedIdentity. Change **authenticationType** to
98+
**FederatedIdentity** and provide **fullyQualifiedNamespace** in router-config.
9699

97100

98101

docs/examples/skanetrafiken/router-config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"type": "siri-azure-sx-updater",
4545
"topic": "<topic_name>",
4646
"feedId": "<feed_id>",
47-
"servicebus-url": "<service_bus_url>",
47+
"authenticationType": "FederatedIdentity",
48+
"fullyQualifiedNamespace": "<fully_qualified_namespace>",
4849
"customMidnight": 4,
4950
"history": {
5051
"url": "<history_endpoint_url>",

docs/sandbox/siri/SiriAzureUpdater.md

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# Siri Azure Updater
2+
3+
It is a sandbox extension developed by Skånetrafiken that allows OTP to fetch Siri ET & SX messages through *Azure Service Bus*.
4+
It also allows for OTP to download historical real-time data from an HTTP endpoint on startup.
5+
6+
## Contact Info
7+
8+
Skånetrafiken, Sweden
9+
developer.otp@skanetrafiken.se
10+
11+
## Documentation
12+
13+
Documentation available [here](../../examples/skanetrafiken/Readme.md).
14+
15+
## Configuration
16+
17+
To enable the SIRI updater you need to add it to the updaters section of the `router-config.json`.
18+
19+
### Siri Azure ET Updater
20+
21+
<!-- siri-azure-et-updater BEGIN -->
22+
<!-- NOTE! This section is auto-generated. Do not change, change doc in code instead. -->
23+
24+
| Config Parameter | Type | Summary | Req./Opt. | Default Value | Since |
25+
|------------------------------------------------------------|:---------:|----------------------------------------------------------------|:----------:|---------------------|:-----:|
26+
| type = "siri-azure-et-updater" | `enum` | The type of the updater. | *Required* | | 1.5 |
27+
| [authenticationType](#u__11__authenticationType) | `enum` | Which authentication type to use | *Optional* | `"sharedaccesskey"` | 2.5 |
28+
| [customMidnight](#u__11__customMidnight) | `integer` | Time on which time breaks into new day. | *Optional* | `0` | 2.2 |
29+
| feedId | `string` | The ID of the feed to apply the updates to. | *Optional* | | 2.2 |
30+
| [fullyQualifiedNamespace](#u__11__fullyQualifiedNamespace) | `string` | Service Bus fully qualified namespace used for authentication. | *Optional* | | 2.5 |
31+
| fuzzyTripMatching | `boolean` | Whether to apply fuzzyTripMatching on the updates | *Optional* | `false` | 2.2 |
32+
| [servicebus-url](#u__11__servicebus_url) | `string` | Service Bus connection used for authentication. | *Optional* | | 2.2 |
33+
| topic | `string` | Service Bus topic to connect to. | *Optional* | | 2.2 |
34+
| history | `object` | Configuration for fetching historical data on startup | *Optional* | | 2.2 |
35+
|    fromDateTime | `string` | Datetime boundary for historical data | *Optional* | `"-P1D"` | 2.2 |
36+
|    timeout | `integer` | Timeout in milliseconds | *Optional* | `300000` | na |
37+
|    url | `string` | Endpoint to fetch from | *Optional* | | na |
38+
39+
40+
##### Parameter details
41+
42+
<h4 id="u__11__authenticationType">authenticationType</h4>
43+
44+
**Since version:** `2.5`**Type:** `enum`**Cardinality:** `Optional`**Default value:** `"sharedaccesskey"`
45+
**Path:** /updaters/[11]
46+
**Enum values:** `sharedaccesskey` | `federatedidentity`
47+
48+
Which authentication type to use
49+
50+
<h4 id="u__11__customMidnight">customMidnight</h4>
51+
52+
**Since version:** `2.2`**Type:** `integer`**Cardinality:** `Optional`**Default value:** `0`
53+
**Path:** /updaters/[11]
54+
55+
Time on which time breaks into new day.
56+
57+
It is common that operating day date breaks a little bit later than midnight so that the switch happens when traffic is at the lowest point. Parameter uses 24-hour format. If the switch happens on 4 am then set this field to 4.
58+
59+
<h4 id="u__11__fullyQualifiedNamespace">fullyQualifiedNamespace</h4>
60+
61+
**Since version:** `2.5`**Type:** `string`**Cardinality:** `Optional`
62+
**Path:** /updaters/[11]
63+
64+
Service Bus fully qualified namespace used for authentication.
65+
66+
Has to be present for authenticationMethod FederatedIdentity.
67+
68+
<h4 id="u__11__servicebus_url">servicebus-url</h4>
69+
70+
**Since version:** `2.2`**Type:** `string`**Cardinality:** `Optional`
71+
**Path:** /updaters/[11]
72+
73+
Service Bus connection used for authentication.
74+
75+
Has to be present for authenticationMethod SharedAccessKey. This should be Primary/Secondary connection string from service bus.
76+
77+
78+
79+
##### Example configuration
80+
81+
```JSON
82+
// router-config.json
83+
{
84+
"updaters" : [
85+
{
86+
"type" : "siri-azure-et-updater",
87+
"topic" : "some_topic",
88+
"authenticationType" : "SharedAccessKey",
89+
"fullyQualifiedNamespace" : "fully_qualified_namespace",
90+
"servicebus-url" : "service_bus_url",
91+
"feedId" : "feed_id",
92+
"customMidnight" : 4,
93+
"history" : {
94+
"url" : "endpoint_url",
95+
"fromDateTime" : "-P1D",
96+
"timeout" : 300000
97+
}
98+
}
99+
]
100+
}
101+
```
102+
103+
<!-- siri-azure-et-updater END -->
104+
105+
### Siri Azure SX Updater
106+
107+
<!-- siri-azure-sx-updater BEGIN -->
108+
<!-- NOTE! This section is auto-generated. Do not change, change doc in code instead. -->
109+
110+
| Config Parameter | Type | Summary | Req./Opt. | Default Value | Since |
111+
|------------------------------------------------------------|:---------:|----------------------------------------------------------------|:----------:|---------------------|:-----:|
112+
| type = "siri-azure-sx-updater" | `enum` | The type of the updater. | *Required* | | 1.5 |
113+
| [authenticationType](#u__10__authenticationType) | `enum` | Which authentication type to use | *Optional* | `"sharedaccesskey"` | 2.5 |
114+
| [customMidnight](#u__10__customMidnight) | `integer` | Time on which time breaks into new day. | *Optional* | `0` | 2.2 |
115+
| feedId | `string` | The ID of the feed to apply the updates to. | *Optional* | | 2.2 |
116+
| [fullyQualifiedNamespace](#u__10__fullyQualifiedNamespace) | `string` | Service Bus fully qualified namespace used for authentication. | *Optional* | | 2.5 |
117+
| fuzzyTripMatching | `boolean` | Whether to apply fuzzyTripMatching on the updates | *Optional* | `false` | 2.2 |
118+
| [servicebus-url](#u__10__servicebus_url) | `string` | Service Bus connection used for authentication. | *Optional* | | 2.2 |
119+
| topic | `string` | Service Bus topic to connect to. | *Optional* | | 2.2 |
120+
| history | `object` | Configuration for fetching historical data on startup | *Optional* | | 2.2 |
121+
|    fromDateTime | `string` | Datetime boundary for historical data. | *Optional* | `"-P1D"` | 2.2 |
122+
|    timeout | `integer` | Timeout in milliseconds | *Optional* | `300000` | na |
123+
|    toDateTime | `string` | Datetime boundary for historical data. | *Optional* | `"P1D"` | 2.2 |
124+
|    url | `string` | Endpoint to fetch from | *Optional* | | na |
125+
126+
127+
##### Parameter details
128+
129+
<h4 id="u__10__authenticationType">authenticationType</h4>
130+
131+
**Since version:** `2.5`**Type:** `enum`**Cardinality:** `Optional`**Default value:** `"sharedaccesskey"`
132+
**Path:** /updaters/[10]
133+
**Enum values:** `sharedaccesskey` | `federatedidentity`
134+
135+
Which authentication type to use
136+
137+
<h4 id="u__10__customMidnight">customMidnight</h4>
138+
139+
**Since version:** `2.2`**Type:** `integer`**Cardinality:** `Optional`**Default value:** `0`
140+
**Path:** /updaters/[10]
141+
142+
Time on which time breaks into new day.
143+
144+
It is common that operating day date breaks a little bit later than midnight so that the switch happens when traffic is at the lowest point. Parameter uses 24-hour format. If the switch happens on 4 am then set this field to 4.
145+
146+
<h4 id="u__10__fullyQualifiedNamespace">fullyQualifiedNamespace</h4>
147+
148+
**Since version:** `2.5`**Type:** `string`**Cardinality:** `Optional`
149+
**Path:** /updaters/[10]
150+
151+
Service Bus fully qualified namespace used for authentication.
152+
153+
Has to be present for authenticationMethod FederatedIdentity.
154+
155+
<h4 id="u__10__servicebus_url">servicebus-url</h4>
156+
157+
**Since version:** `2.2`**Type:** `string`**Cardinality:** `Optional`
158+
**Path:** /updaters/[10]
159+
160+
Service Bus connection used for authentication.
161+
162+
Has to be present for authenticationMethod SharedAccessKey. This should be Primary/Secondary connection string from service bus.
163+
164+
165+
166+
##### Example configuration
167+
168+
```JSON
169+
// router-config.json
170+
{
171+
"updaters" : [
172+
{
173+
"type" : "siri-azure-sx-updater",
174+
"topic" : "some_topic",
175+
"servicebus-url" : "service_bus_url",
176+
"feedId" : "feed_id",
177+
"customMidnight" : 4,
178+
"history" : {
179+
"url" : "endpoint_url",
180+
"fromDateTime" : "-P1D",
181+
"toDateTime" : "P1D",
182+
"timeout" : 300000
183+
}
184+
}
185+
]
186+
}
187+
```
188+
189+
<!-- siri-azure-sx-updater END -->
190+
191+
## Changelog
192+
- Added configuration for turning off stop arrival time match feature.
193+
- Initial version (April 2022)
194+
- Minor changes in logging (November 2022)
195+
- Retry fetch from history endpoint if it failed (February 2023)
196+
- Solve a bug in SiriAzureETUpdater and improve error logging (March 2023)
197+
- Add support with federated identity authentication (February 2024)
File renamed without changes.

mkdocs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ nav:
9696
- Actuator API: 'sandbox/ActuatorAPI.md'
9797
- Direct Transfer Analyzer: 'sandbox/transferanalyzer.md'
9898
- Google Cloud Storage: 'sandbox/GoogleCloudStorage.md'
99-
- SIRI Updaters: 'sandbox/SiriUpdater.md'
100-
- SIRI Updater (Azure): 'sandbox/SiriAzureUpdater.md'
99+
- SIRI Updaters: 'sandbox/siri/SiriUpdater.md'
100+
- SIRI Updater (Azure): 'sandbox/siri/SiriAzureUpdater.md'
101101
- Vehicle Rental Service Directory API support: 'sandbox/VehicleRentalServiceDirectory.md'
102102
- Smoove Bike Rental Updator Support: 'sandbox/SmooveBikeRental.md'
103103
- Mapbox Vector Tiles API: 'sandbox/MapboxVectorTilesApi.md'

pom.xml

+6-5
Original file line numberDiff line numberDiff line change
@@ -907,17 +907,18 @@
907907
<dependency>
908908
<groupId>com.azure</groupId>
909909
<artifactId>azure-core</artifactId>
910-
<version>1.45.0</version>
910+
<version>1.46.0</version>
911911
</dependency>
912912
<dependency>
913913
<groupId>com.azure</groupId>
914914
<artifactId>azure-messaging-servicebus</artifactId>
915-
<version>7.14.5</version>
915+
<version>7.15.0</version>
916916
</dependency>
917917
<dependency>
918-
<groupId>com.azure.resourcemanager</groupId>
919-
<artifactId>azure-resourcemanager-servicebus</artifactId>
920-
<version>2.32.0</version>
918+
<groupId>com.azure</groupId>
919+
<artifactId>azure-identity</artifactId>
920+
<version>1.11.2</version>
921+
<scope>compile</scope>
921922
</dependency>
922923
<dependency>
923924
<groupId>ch.poole</groupId>

src/ext/java/org/opentripplanner/ext/siri/updater/azure/AbstractAzureSiriUpdater.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.opentripplanner.ext.siri.updater.azure;
22

3+
import com.azure.identity.DefaultAzureCredentialBuilder;
34
import com.azure.messaging.servicebus.ServiceBusClientBuilder;
45
import com.azure.messaging.servicebus.ServiceBusErrorContext;
56
import com.azure.messaging.servicebus.ServiceBusException;
@@ -36,6 +37,8 @@
3637
public abstract class AbstractAzureSiriUpdater implements GraphUpdater {
3738

3839
private final Logger LOG = LoggerFactory.getLogger(getClass());
40+
private final AuthenticationType authenticationType;
41+
private final String fullyQualifiedNamespace;
3942
private final String configRef;
4043
private final String serviceBusUrl;
4144
private final SiriFuzzyTripMatcher fuzzyTripMatcher;
@@ -63,6 +66,8 @@ public abstract class AbstractAzureSiriUpdater implements GraphUpdater {
6366

6467
public AbstractAzureSiriUpdater(SiriAzureUpdaterParameters config, TransitModel transitModel) {
6568
this.configRef = config.configRef();
69+
this.authenticationType = config.getAuthenticationType();
70+
this.fullyQualifiedNamespace = config.getFullyQualifiedNamespace();
6671
this.serviceBusUrl = config.getServiceBusUrl();
6772
this.topicName = config.getTopicName();
6873
this.dataInitializationUrl = config.getDataInitializationUrl();
@@ -105,10 +110,17 @@ public void run() {
105110
}
106111

107112
// Client with permissions to create subscription
108-
serviceBusAdmin =
109-
new ServiceBusAdministrationClientBuilder()
110-
.connectionString(serviceBusUrl)
111-
.buildAsyncClient();
113+
if (authenticationType == AuthenticationType.FederatedIdentity) {
114+
serviceBusAdmin =
115+
new ServiceBusAdministrationClientBuilder()
116+
.credential(fullyQualifiedNamespace, new DefaultAzureCredentialBuilder().build())
117+
.buildAsyncClient();
118+
} else if (authenticationType == AuthenticationType.SharedAccessKey) {
119+
serviceBusAdmin =
120+
new ServiceBusAdministrationClientBuilder()
121+
.connectionString(serviceBusUrl)
122+
.buildAsyncClient();
123+
}
112124

113125
// If Idle more then one day, then delete subscription so we don't have old obsolete subscriptions on Azure Service Bus
114126
var options = new CreateSubscriptionOptions();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.opentripplanner.ext.siri.updater.azure;
2+
3+
public enum AuthenticationType {
4+
SharedAccessKey,
5+
FederatedIdentity,
6+
}

0 commit comments

Comments
 (0)