@abgov/adsp-sdk-mcp-server 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/assets/docs/architecture.md +79 -0
- package/assets/docs/getting-started.md +118 -0
- package/assets/docs/important-notes.md +47 -0
- package/assets/docs/index.md +9 -0
- package/assets/docs/platform/deployment.md +80 -0
- package/assets/docs/platform/getting-started.md +66 -0
- package/assets/docs/platform/operations.md +8 -0
- package/assets/docs/platform/platform-django-sdk.md +330 -0
- package/assets/docs/platform/platform-dotnet-sdk.md +457 -0
- package/assets/docs/platform/platform-flask-sdk.md +355 -0
- package/assets/docs/platform/platform-node-sdk.md +433 -0
- package/assets/docs/platform/platform-spring-sdk.md +344 -0
- package/assets/docs/platform/platform.md +8 -0
- package/assets/docs/services/access-service.md +75 -0
- package/assets/docs/services/agent-service.md +316 -0
- package/assets/docs/services/cache-service.md +61 -0
- package/assets/docs/services/calendar-service.md +86 -0
- package/assets/docs/services/comment-service.md +87 -0
- package/assets/docs/services/configuration-service.md +92 -0
- package/assets/docs/services/directory-service.md +57 -0
- package/assets/docs/services/event-service.md +122 -0
- package/assets/docs/services/feedback-service.md +152 -0
- package/assets/docs/services/file-service.md +164 -0
- package/assets/docs/services/form-service.md +149 -0
- package/assets/docs/services/notification-service.md +151 -0
- package/assets/docs/services/pdf-service.md +116 -0
- package/assets/docs/services/pii-service.md +45 -0
- package/assets/docs/services/push-service.md +106 -0
- package/assets/docs/services/services.md +6 -0
- package/assets/docs/services/status-service.md +29 -0
- package/assets/docs/services/task-service.md +139 -0
- package/assets/docs/services/tenant-service.md +18 -0
- package/assets/docs/services/token-handler.md +135 -0
- package/assets/docs/services/value-service.md +80 -0
- package/assets/docs/services/verify-service.md +61 -0
- package/assets/docs/tutorials/access-service/access-service.md +9 -0
- package/assets/docs/tutorials/access-service/adsp-clients.md +29 -0
- package/assets/docs/tutorials/access-service/application-clients.md +61 -0
- package/assets/docs/tutorials/access-service/front-end-access.md +53 -0
- package/assets/docs/tutorials/access-service/introduction.md +33 -0
- package/assets/docs/tutorials/access-service/tenants.md +68 -0
- package/assets/docs/tutorials/access-service/themes.md +43 -0
- package/assets/docs/tutorials/feedback-service/accessing-data.md +41 -0
- package/assets/docs/tutorials/feedback-service/feedback-service.md +9 -0
- package/assets/docs/tutorials/feedback-service/installation.md +142 -0
- package/assets/docs/tutorials/feedback-service/introduction.md +28 -0
- package/assets/docs/tutorials/feedback-service/security.md +40 -0
- package/assets/docs/tutorials/feedback-service/triggering.md +21 -0
- package/assets/docs/tutorials/file-service/file-service.md +9 -0
- package/assets/docs/tutorials/file-service/file-types.md +35 -0
- package/assets/docs/tutorials/file-service/introduction.md +34 -0
- package/assets/docs/tutorials/file-service/security.md +31 -0
- package/assets/docs/tutorials/file-service/working-with.md +65 -0
- package/assets/docs/tutorials/form-service/Integration.md +31 -0
- package/assets/docs/tutorials/form-service/ai-agent.md +450 -0
- package/assets/docs/tutorials/form-service/building-forms.md +264 -0
- package/assets/docs/tutorials/form-service/cheat-sheet.md +1461 -0
- package/assets/docs/tutorials/form-service/custom-error-messages.md +87 -0
- package/assets/docs/tutorials/form-service/data-registers.md +204 -0
- package/assets/docs/tutorials/form-service/file-uploader.md +81 -0
- package/assets/docs/tutorials/form-service/form-app.md +72 -0
- package/assets/docs/tutorials/form-service/form-editor.md +62 -0
- package/assets/docs/tutorials/form-service/form-service.md +9 -0
- package/assets/docs/tutorials/form-service/form-submissions.md +77 -0
- package/assets/docs/tutorials/form-service/instructions.md +173 -0
- package/assets/docs/tutorials/form-service/introduction.md +66 -0
- package/assets/docs/tutorials/form-service/repeated-items.md +87 -0
- package/assets/docs/tutorials/form-service/security.md +36 -0
- package/assets/docs/tutorials/form-service/steppers.md +237 -0
- package/assets/docs/tutorials/notification-service/emailAttachment.md +75 -0
- package/assets/docs/tutorials/notification-service/events.md +20 -0
- package/assets/docs/tutorials/notification-service/introduction.md +37 -0
- package/assets/docs/tutorials/notification-service/notification-service.md +9 -0
- package/assets/docs/tutorials/notification-service/notification-types.md +86 -0
- package/assets/docs/tutorials/notification-service/subscribers.md +33 -0
- package/assets/docs/tutorials/pdf-service/building-a-template.md +339 -0
- package/assets/docs/tutorials/pdf-service/generate-a-pdf.md +150 -0
- package/assets/docs/tutorials/pdf-service/handlebars.md +51 -0
- package/assets/docs/tutorials/pdf-service/introduction.md +26 -0
- package/assets/docs/tutorials/pdf-service/pdf-service.md +9 -0
- package/assets/docs/tutorials/pdf-service/puppeteer.md +25 -0
- package/assets/docs/tutorials/pdf-service/video.md +18 -0
- package/assets/docs/tutorials/status-service/Introduction.md +46 -0
- package/assets/docs/tutorials/status-service/health.md +51 -0
- package/assets/docs/tutorials/status-service/notices.md +34 -0
- package/assets/docs/tutorials/status-service/notifications.md +107 -0
- package/assets/docs/tutorials/status-service/status-service.md +9 -0
- package/assets/docs/tutorials/status-service/status.md +35 -0
- package/assets/docs/tutorials/status-service/webhooks.md +24 -0
- package/assets/docs/tutorials/task-service/introduction.md +23 -0
- package/assets/docs/tutorials/task-service/task-app.md +43 -0
- package/assets/docs/tutorials/task-service/task-definitions.md +49 -0
- package/assets/docs/tutorials/task-service/task-queues.md +67 -0
- package/assets/docs/tutorials/task-service/task-service.md +9 -0
- package/assets/docs/tutorials/tutorials.md +8 -0
- package/package.json +18 -0
- package/src/docs/docsRepository.d.ts +22 -0
- package/src/docs/docsRepository.js +110 -0
- package/src/docs/docsRepository.js.map +1 -0
- package/src/main.d.ts +2 -0
- package/src/main.js +16 -0
- package/src/main.js.map +1 -0
- package/src/sdk-reference/reference.d.ts +17 -0
- package/src/sdk-reference/reference.js +547 -0
- package/src/sdk-reference/reference.js.map +1 -0
- package/src/sdk-reference/search.d.ts +6 -0
- package/src/sdk-reference/search.js +41 -0
- package/src/sdk-reference/search.js.map +1 -0
- package/src/server.d.ts +6 -0
- package/src/server.js +30 -0
- package/src/server.js.map +1 -0
- package/src/tools/registerDocsTools.d.ts +3 -0
- package/src/tools/registerDocsTools.js +66 -0
- package/src/tools/registerDocsTools.js.map +1 -0
- package/src/tools/registerQuickstartTool.d.ts +2 -0
- package/src/tools/registerQuickstartTool.js +82 -0
- package/src/tools/registerQuickstartTool.js.map +1 -0
- package/src/tools/registerSdkTools.d.ts +2 -0
- package/src/tools/registerSdkTools.js +43 -0
- package/src/tools/registerSdkTools.js.map +1 -0
- package/src/tools/types.d.ts +12 -0
- package/src/tools/types.js +3 -0
- package/src/tools/types.js.map +1 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: page
|
|
3
|
+
title: Service SDK (Spring)
|
|
4
|
+
nav_order: 4
|
|
5
|
+
parent: Platform development
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<details open markdown="block">
|
|
9
|
+
<summary>
|
|
10
|
+
Table of contents
|
|
11
|
+
</summary>
|
|
12
|
+
{: .text-delta }
|
|
13
|
+
1. TOC
|
|
14
|
+
{:toc}
|
|
15
|
+
</details>
|
|
16
|
+
|
|
17
|
+
# ADSP service SDK (Spring)
|
|
18
|
+
Platform services integrate into the foundational capabilities via a Software Development Kit (SDK). The SDK includes interfaces and utilities for handling tenancy, configurations, and registration. The same SDK can be used for development of tenant services.
|
|
19
|
+
|
|
20
|
+
Note that the SDK provides friendly interfaces on top of APIs. It is intended to speed up service development but is not the only way to access platform capabilities.
|
|
21
|
+
|
|
22
|
+
Package [adsp-service-spring-sdk](https://github.com/GovAlta/adsp-monorepo/packages/1657803)
|
|
23
|
+
|
|
24
|
+
```xml
|
|
25
|
+
<dependency>
|
|
26
|
+
<groupId>ca.ab.gov.alberta.adsp</groupId>
|
|
27
|
+
<artifactId>adsp-service-spring-sdk</artifactId>
|
|
28
|
+
<version>1.2.0</version>
|
|
29
|
+
</dependency>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Update maven `settings.xml` file to configure installing from the GitHub packages maven repository:
|
|
33
|
+
|
|
34
|
+
```xml
|
|
35
|
+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
|
|
36
|
+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
|
37
|
+
<activeProfiles>
|
|
38
|
+
<activeProfile>github</activeProfile>
|
|
39
|
+
</activeProfiles>
|
|
40
|
+
<profiles>
|
|
41
|
+
<profile>
|
|
42
|
+
<id>github</id>
|
|
43
|
+
<repositories>
|
|
44
|
+
<repository>
|
|
45
|
+
<id>github</id>
|
|
46
|
+
<url>https://maven.pkg.github.com/GovAlta/adsp-monorepo</url>
|
|
47
|
+
</repository>
|
|
48
|
+
...
|
|
49
|
+
</repositories>
|
|
50
|
+
</profile>
|
|
51
|
+
</profiles>
|
|
52
|
+
<servers>
|
|
53
|
+
<server>
|
|
54
|
+
<id>github</id>
|
|
55
|
+
<username>{github username}</username>
|
|
56
|
+
<password>{personal access token}</password>
|
|
57
|
+
</server>
|
|
58
|
+
</servers>
|
|
59
|
+
</settings>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Setting up a service account
|
|
63
|
+
The SDK requires credentials for a service account and uses this account for accessing platform capabilities. Fine grained configuration is possible and principle of least privilege should be applied.
|
|
64
|
+
|
|
65
|
+
In order to create the service account.
|
|
66
|
+
1. Create a confidential Client with a client ID in the format: `urn:ads:{tenant}:{service}` . The SDK does not authenticate end users and so all authentication grant types can be disabled.
|
|
67
|
+
2. Enable service account for the client.
|
|
68
|
+
3. In Service Account Roles, add the appropriate Client Roles for the capabilities that will be accessed:
|
|
69
|
+
1. Client `urn:ads:platform:tenant-service ` role `platform-service` is required.
|
|
70
|
+
2. Client `urn:ads:platform:configuration-service` role `configured-service` is needed for registration and accessing service specific configuration
|
|
71
|
+
3. Client `urn:ads:platform:event-service` role `event-sender` is needed for sending domain events.
|
|
72
|
+
4. Additional audiences in the service account access token are required for some capabilities:
|
|
73
|
+
1. Client `urn:ads:platform:push-service` needs to be include via an audience mapper for socket based configuration cache invalidation.
|
|
74
|
+
|
|
75
|
+
## Initializing the SDK
|
|
76
|
+
The SDK follows Spring conventions of using annotations to enable capabilities as well as Spring Boot conventions for auto-configuration. For Spring, add the `@EnableAdsp` annotation to configuration. For Spring Boot, customize configuration by extending `AdspConfigurationSupport` and auto-configuration will apply SDK capabilities.
|
|
77
|
+
|
|
78
|
+
```java
|
|
79
|
+
public class MyAdspConfiguration extends AdspConfigurationSupport {
|
|
80
|
+
@Override
|
|
81
|
+
protected Builder customize(Builder builder) {
|
|
82
|
+
return builder.withDisplayName("My platform service")
|
|
83
|
+
.withDescription("Hello world platform service.");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
By default properties of `AdspConfiguration` are fulfilled with application properties with an `adsp` prefix. (e.g. `adsp.accessServiceUrl`)
|
|
89
|
+
|
|
90
|
+
## Enabling service metadata
|
|
91
|
+
The service directory aggregates service metadata from the root resource of services registered in the directory. This metadata is used to simplify configuration and for OpenAPI documentation aggregation at https://api.adsp.alberta.ca/{tenant}. SDK includes components for exposing the metadata endpoint.
|
|
92
|
+
|
|
93
|
+
Enabling service metadata:
|
|
94
|
+
```java
|
|
95
|
+
@Configuration
|
|
96
|
+
public class HelloWorldMetadata extends AdspMetadataSupport {
|
|
97
|
+
@Override
|
|
98
|
+
protected Builder customize(Builder builder) {
|
|
99
|
+
return builder.withApiPath("/hello-world/v1");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Authorizing requests
|
|
105
|
+
The SDK provides the `SecurityFilterChain` bean for verifying JWT bearer tokens in tenant requests. By default, the authentication is applied with an ant pattern of `**/v?/**`, and services can modify the patterns on `AdspConfiguration`.
|
|
106
|
+
|
|
107
|
+
### Role-based authorization
|
|
108
|
+
The SDK maps Keycloak access token `realm_access` and `resource_access` roles to granted role authorities to allow for use of authorization annotations.
|
|
109
|
+
|
|
110
|
+
Keycloak issued tokens contain client roles nested under `realm_access`. SDK claim mapping flatten service specific roles from the token and qualifies roles related to other service clients with the client ID.
|
|
111
|
+
|
|
112
|
+
For example:
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"realm_access": { "roles": ["user"] },
|
|
116
|
+
"resource_access": {
|
|
117
|
+
"my-service": { "roles": ["my-user"] },
|
|
118
|
+
"other-service": { "roles": ["other-user"] }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
For my-service, the roles are mapped to role claims:
|
|
124
|
+
- user
|
|
125
|
+
- my-user
|
|
126
|
+
- other-service:other-user
|
|
127
|
+
|
|
128
|
+
Authorize based on a role:
|
|
129
|
+
```java
|
|
130
|
+
@PreAuthorize("hasRole('other-service:other-user')")
|
|
131
|
+
@GetMapping("/hello")
|
|
132
|
+
public String helloWorld() {
|
|
133
|
+
...
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Accessing user information directly and checking for role:
|
|
138
|
+
```java
|
|
139
|
+
var user = AdspRequestContextHolder.current().getUser();
|
|
140
|
+
var hasRole = user.isInRole("other-service:other-user");
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Determining tenancy
|
|
144
|
+
Requests to platform services are in the context of a specific tenant with few exceptions. The context is implicit when a request is made with a tenant bearer token. It can be explicit in cases where an endpoint allows anonymous access or when a platform service makes a request to another platform service under a core service account.
|
|
145
|
+
|
|
146
|
+
The SDK includes middleware that resolves implicit from user tenancy and explicit from a `tenantId` query parameter. Resolved tenant is set on the request object; no value is set if tenancy cannot be resolved.
|
|
147
|
+
|
|
148
|
+
Getting tenancy from the context:
|
|
149
|
+
```java
|
|
150
|
+
import ca.ab.gov.alberta.adsp.sdk.AdspRequestContextHolder;
|
|
151
|
+
|
|
152
|
+
@RestController
|
|
153
|
+
public class HelloWorldController {
|
|
154
|
+
@GetMapping("/hello")
|
|
155
|
+
public String helloWorld() {
|
|
156
|
+
var tenant = AdspRequestContextHolder.current().getTenant().blockOptional();
|
|
157
|
+
...
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The handler uses the tenant service client to retrieve tenant information. This is also available from the SDK for direct use. The tenant service is available via dependency injection.
|
|
163
|
+
|
|
164
|
+
Getting tenant information using the tenant service:
|
|
165
|
+
```java
|
|
166
|
+
import ca.ab.gov.alberta.adsp.sdk.AdspId;
|
|
167
|
+
import ca.ab.gov.alberta.adsp.sdk.tenant.TenantService;
|
|
168
|
+
|
|
169
|
+
@RestController
|
|
170
|
+
public class HelloWorldController {
|
|
171
|
+
private final TenantService tenantService;
|
|
172
|
+
public HelloWorldController(TenantService tenantService) {
|
|
173
|
+
this.tenantService = tenantService;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@GetMapping("/hello")
|
|
177
|
+
public String helloWorld(String tenantId) {
|
|
178
|
+
var tenant = this.tenantService.getTenant(AdspId.parse(tenantId)).blockOptional();
|
|
179
|
+
...
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Finding services
|
|
185
|
+
Service discovery in ADSP is handled using client side service discovery with a directory of services providing a register of available services.
|
|
186
|
+
|
|
187
|
+
Getting a service URL from the directory:
|
|
188
|
+
```java
|
|
189
|
+
import ca.ab.gov.alberta.adsp.sdk.AdspId;
|
|
190
|
+
import ca.ab.gov.alberta.adsp.sdk.directory.ServiceDirectory;
|
|
191
|
+
|
|
192
|
+
@RestController
|
|
193
|
+
public class HelloWorldController {
|
|
194
|
+
private final ServiceDirectory directory;
|
|
195
|
+
public HelloWorldController(ServiceDirectory directory) {
|
|
196
|
+
this.directory = directory;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@GetMapping("/hello")
|
|
200
|
+
public String helloWorld(String serviceId)
|
|
201
|
+
{
|
|
202
|
+
var serviceUrl = this.directory.getServiceUrl(AdspId.parse(serviceId)).blockOptional();
|
|
203
|
+
...
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Handling configuration
|
|
209
|
+
Platform services can make use of a common configuration service for managing configuration. The SDK allows services to define their configuration schema and access configuration.
|
|
210
|
+
|
|
211
|
+
Defining the configuration json schema:
|
|
212
|
+
```java
|
|
213
|
+
import ca.ab.gov.alberta.adsp.sdk.registration.ConfigurationDefinition;
|
|
214
|
+
...
|
|
215
|
+
@Override
|
|
216
|
+
protected Builder customize(Builder builder) {
|
|
217
|
+
return builder.register(
|
|
218
|
+
registration -> registration.withConfiguration(
|
|
219
|
+
new ConfigurationDefinition<HelloConfiguration>("Configuration of the hello world service.") {
|
|
220
|
+
})
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Each service can have core configuration that applies across tenants and configuration specific to each tenant. The SDK provides a configuration HttpContext extension method that will retrieve configuration in request tenant context. The tenant context is determined using `AdspRequestContextHolder.current().getTenant()`.
|
|
226
|
+
|
|
227
|
+
Getting configuration via the context:
|
|
228
|
+
```java
|
|
229
|
+
import ca.ab.gov.alberta.adsp.sdk.AdspRequestContextHolder;
|
|
230
|
+
|
|
231
|
+
@RestController
|
|
232
|
+
public class HelloWorldController {
|
|
233
|
+
|
|
234
|
+
@GetMapping("/hello")
|
|
235
|
+
public String helloWorld()
|
|
236
|
+
{
|
|
237
|
+
var configuration = AdspRequestContextHolder.current()
|
|
238
|
+
.getConfiguration(HelloConfiguration.TypeReference)
|
|
239
|
+
.blockOptional();
|
|
240
|
+
...
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The handler uses configuration service client to retrieve configuration. This is also available from the SDK via dependency injection for direct use.
|
|
246
|
+
|
|
247
|
+
Getting configuration using the configuration service:
|
|
248
|
+
```java
|
|
249
|
+
import ca.ab.gov.alberta.adsp.sdk.AdspId;
|
|
250
|
+
import ca.ab.gov.alberta.adsp.sdk.configuration.ConfigurationService;
|
|
251
|
+
|
|
252
|
+
@RestController
|
|
253
|
+
public class HelloWorldController {
|
|
254
|
+
private final ConfigurationService configurationService;
|
|
255
|
+
public HelloWorldController(ConfigurationService configurationService) {
|
|
256
|
+
this.configurationService = configurationService;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@GetMapping("/hello")
|
|
260
|
+
public String helloWorld(String serviceId, String tenantId)
|
|
261
|
+
{
|
|
262
|
+
var serviceUrl = this.configurationService.getConfiguration(AdspId.parse(serviceId), Optional.of(AdspId.parse(tenantId)), HelloConfiguration.TypeReference)
|
|
263
|
+
.blockOptional();
|
|
264
|
+
...
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
## Registering event definitions, notification types, etc.
|
|
271
|
+
The SDK allows services to register configuration for some platform services.
|
|
272
|
+
|
|
273
|
+
- `Roles` defines the client roles of the service. New tenant realms are created with a client that includes the roles specified here.
|
|
274
|
+
- `Events` defines the domain events of the service signalled for domain significant changes.
|
|
275
|
+
|
|
276
|
+
Defining configuration for other platform services:
|
|
277
|
+
```java
|
|
278
|
+
import ca.ab.gov.alberta.adsp.sdk.events.DomainEventDefinition;
|
|
279
|
+
import ca.ab.gov.alberta.adsp.sdk.registration.ServiceRole;
|
|
280
|
+
...
|
|
281
|
+
@Override
|
|
282
|
+
protected Builder customize(Builder builder) {
|
|
283
|
+
return builder.register(
|
|
284
|
+
registration -> registration.withRoles(
|
|
285
|
+
new ServiceRole(
|
|
286
|
+
ServiceRoles.HelloWorlder,
|
|
287
|
+
"Role that allows people to hello the world.",
|
|
288
|
+
true))
|
|
289
|
+
.withEvents(
|
|
290
|
+
new DomainEventDefinition<HelloWorldExecuted>(HelloWorldExecuted.EventName,
|
|
291
|
+
"Signalled when hello world is executed.") {
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Sending domain events
|
|
297
|
+
Domain events can be sent using the event service which is available via dependency injection.
|
|
298
|
+
|
|
299
|
+
```java
|
|
300
|
+
import ca.ab.gov.alberta.adsp.sdk.AdspId;
|
|
301
|
+
import ca.ab.gov.alberta.adsp.sdk.events.DomainEvent;
|
|
302
|
+
import ca.ab.gov.alberta.adsp.sdk.events.EventService;
|
|
303
|
+
|
|
304
|
+
@RestController
|
|
305
|
+
public class HelloWorldController {
|
|
306
|
+
private final EventService eventService;
|
|
307
|
+
public HelloWorldController(EventService eventService) {
|
|
308
|
+
this.eventService = eventService;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@GetMapping("/hello")
|
|
312
|
+
public String helloWorld(String message)
|
|
313
|
+
{
|
|
314
|
+
this.eventService.send(new DomainEvent<HelloWorldExecuted>(
|
|
315
|
+
HelloWorldExecuted.EventName,
|
|
316
|
+
Instant.now(),
|
|
317
|
+
new HelloWorldExecuted(message)
|
|
318
|
+
)).blockOptional();
|
|
319
|
+
...
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Connecting to push streams
|
|
325
|
+
Services can receive events via push service streams over [Socket.IO](https://socket.io).
|
|
326
|
+
|
|
327
|
+
Create a POJO component / bean with the `SocketEventListener` annotation on an appropriate method.
|
|
328
|
+
```java
|
|
329
|
+
|
|
330
|
+
@Component
|
|
331
|
+
public class MyEventSubscriber {
|
|
332
|
+
@SocketEventListener(streamId = "my-event-stream", payloadType = Map.class)
|
|
333
|
+
public void onEvent(FullDomainEvent<Map<String, Object>> received) {
|
|
334
|
+
...
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
## Additional utilities
|
|
341
|
+
The SDK provides several other useful utilities.
|
|
342
|
+
|
|
343
|
+
### ADSP ID
|
|
344
|
+
Utilities for handling ADSP URNs.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: page
|
|
3
|
+
title: Access service
|
|
4
|
+
nav_order: 2
|
|
5
|
+
parent: Services
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Access service
|
|
9
|
+
|
|
10
|
+
<!-- tags: [keycloak] -->
|
|
11
|
+
Access service is a deployment of [Keycloak](https://www.keycloak.org/). It provides _Realms_ (tenancy in Keycloak) to tenants and serves as the basis for tenant access management.
|
|
12
|
+
|
|
13
|
+
Access tokens issued by tenant realms are recognized by platform services and serve to identify the associated tenant of each request. Tenant administrators control the user and service accounts that have access to platform capabilities by adding or removing platform service client roles from accounts.
|
|
14
|
+
|
|
15
|
+
## Client roles
|
|
16
|
+
|
|
17
|
+
<!-- tags: [keycloak] -->
|
|
18
|
+
Access service roles are defined by Keycloak. Realm management related roles can be found under the `realm-management` client. Refer to keycloak documentation for specifics.
|
|
19
|
+
|
|
20
|
+
## Concepts
|
|
21
|
+
|
|
22
|
+
<!-- tags: [keycloak] -->
|
|
23
|
+
This captures some key concepts and their specific relevance to ADSP. For the complete documentation, refer to Keycloak documentation.
|
|
24
|
+
|
|
25
|
+
### Clients
|
|
26
|
+
|
|
27
|
+
<!-- tags: [keycloak] -->
|
|
28
|
+
Clients represents applications that request authentication for users or applications that verify access via bearer tokens. In ADSP, tenant realms are created with a `urn:ads:platform:tenant-admin-app` client that is used by the tenant administration application to authenticate users, as well as platform service bearer-only clients that include _client roles_.
|
|
29
|
+
|
|
30
|
+
### Clients roles
|
|
31
|
+
|
|
32
|
+
<!-- tags: [keycloak] -->
|
|
33
|
+
Client roles are roles associated with a specific client. For example, Keycloak realm administration console roles are client roles of a `realm-management` client. If an access token is requested for an account with a client role, the _Audience Resolve_ protocol mapper included in the _roles_ scope will include the client in the `aud` field of the returned access token.
|
|
34
|
+
|
|
35
|
+
To access to ADSP services, a few ADSP clients in the format of `urn:ads:<service-name>` are created as default. Mostly, client roles within those clients provide the fine-grained access control to a specific ADSP service. One exception is the `tenant-admin` role in the `urn:ads:platform:tenant-service` client. The `tenant-admin` is created as a composite role and contains other client roles. The `tenant-admin` shall be only assigned to the ADSP tenant admin.
|
|
36
|
+
|
|
37
|
+
The ADSP clients and related roles are maintained by the ADSP team. Please contact the ADSP team directly if they are misconfigured.
|
|
38
|
+
|
|
39
|
+
### Add team member as a tenant admin
|
|
40
|
+
|
|
41
|
+
<!-- tags: [keycloak] -->
|
|
42
|
+
The steps of settping up a tenant admin are described as follows:
|
|
43
|
+
|
|
44
|
+
- Request the team memeber to login to the keycloak tenant realm once.
|
|
45
|
+
- Add all of the roles in the `realm-management` client to the team member.
|
|
46
|
+
- Add the `tenant-admin` role in the `urn:ads:platform:tenant-service` client to the team member.
|
|
47
|
+
|
|
48
|
+
From keycloak point view, the tenant root admin who created the tenant is identical to other admins. However, the login URL to the tenant admin web application between the tenant root admin and other admins are different. Unlike the tenant root admin, the rest of the admins can only access to tenant admin web application through the tenant specific login URL. The login URL can be found in the right column of Dashbord page in the tenant admin webapp.
|
|
49
|
+
|
|
50
|
+
## Code examples
|
|
51
|
+
|
|
52
|
+
### Authenticate user
|
|
53
|
+
|
|
54
|
+
TODO: Add example here
|
|
55
|
+
|
|
56
|
+
See [Angular Example](https://github.com/abgov/dio-keycloak-angular-sample)
|
|
57
|
+
|
|
58
|
+
See [React Example](https://github.com/abgov/nx-tools-example/tree/actions-pipeline/apps/react-dotnet-example-app)
|
|
59
|
+
|
|
60
|
+
### Request a service account access token
|
|
61
|
+
|
|
62
|
+
Platform capabilities are often access via their API under a service account. Retrieve an access token for your client using the `client_credentials` grant.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const response = await fetch(`https://access.alberta.ca/auth/realms/${realm}/protocol/openid-connect/token`, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: new URLSearchParams({
|
|
68
|
+
grant_type: 'client_credentials',
|
|
69
|
+
client_id: clientId,
|
|
70
|
+
client_secret: clientSecret,
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const { access_token, expires_in } = await response.json();
|
|
75
|
+
```
|