Elffuss BraidHub

kikocis/EDC public

main · 2.0 KiBRenderedRawPermalink
1# Api Authentication Configuration
2
3## Decision
4
5A new extension will be introduced for configuring the `ApiAuthenticationRegistry`
6
7## Rationale
8
9Recently, the `ApiAuthenticationRegistry` was introduced for associating a web context to a `AuthenticationService` in
10order to use different auth mechanism for different contexts. Currently though, this association is expressed
11in each `AuthenticationService` extension, which makes ti difficult to apply an `AuthenticationService` to a different
12context compared to the current hardcoded one.
13
14## Approach
15
16Each implementor of `AuthenticationService` will also implement an `ApiAuthenticationProvider` which will provide an
17instance of `AuthenticationService` based on the input configuration.
18
19```java
20public interface ApiAuthenticationProvider {
21
22 Result<AuthenticationService> provide(Config config);
23}
24```
25
26Those providers can be registered in a registry `ApiAuthenticationProviderRegistry`, associated with the auth type (
27basic,token, delegated, ...)
28
29```java
30public interface ApiAuthenticationProviderRegistry {
31
32 void register(String type, ApiAuthenticationProvider provider);
33
34 Result<ApiAuthenticationProvider> resolve(String type);
35}
36```
37
38Then the new extension, leveraging the partition mechanism of EDC `web.http` config, will configure the association
39between the context and the auth type in the prepare phase.
40
41For example if a user wants to configure the `TokenBasedAuthenticationService` for the `management` context, a
42configuration like this could be used:
43
44```
45web.http.management.auth.type=tokenbased
46web.http.management.auth.key.alias=vaultAlias
47```
48
49For each web context the extension will read the `auth.type` if present, and will invoke the provider for that type with
50the input configuration, associating then the created instance with the configured `context` in
51the `ApiAuthenticationRegistry`.
52
53> For backward compatibility we will leave in place the current hardcoded association
54> context <-> `AuthenticationService`