Skip to content

Commit

Permalink
PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jul 5, 2024
1 parent 2723ca2 commit 66065ce
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
25 changes: 25 additions & 0 deletions extensions/common/auth/auth-configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Authentication Configuration

This extension allows to secure a set of APIs grouped by a web context. It inspects
all `web.http.<context>` and if the authentication is configured it applies the `AuthenticationRequestFilter`
to the `<context>` with the chosen `AuthenticationService`. The chosen `AuthenticationService` is currently registered
in the `ApiAuthenticationRegistry`. This will be removed once the `ApiAuthenticationRegistry` will be refactored out.

## Configuration

| Key | Description | Mandatory |
|:--------------------------------|:-------------------------------------------------------------------------------------------|-----------|
| web.http.<context>.auth.type | The type of authentication to apply to the `<context>` | |
| web.http.<context>.auth.context | Override the name of the context in the `ApiAuthenticationRegistry` instead of `<context>` | |

Depending on the `web.http.<context>.auth.type` chosen, additional properties might be required in order to configure
the `AuthenticationService`.

Example of a complete configuration for a custom context with token based authentication

```properties
web.http.custom.path=/custom
web.http.custom.port=8081
web.http.custom.auth.type=tokenbased
web.http.custom.auth.key=apiKey
```
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
import java.util.stream.Collectors;

import static org.eclipse.edc.api.auth.configuration.ApiAuthenticationConfigurationExtension.NAME;
import static org.eclipse.edc.web.spi.configuration.WebServiceConfigurer.WEB_HTTP_PREFIX;

@Extension(NAME)
public class ApiAuthenticationConfigurationExtension implements ServiceExtension {

public static final String NAME = "Api Authentication Configuration Extension";

public static final String WEB_HTTP_PREFIX = "web.http";

public static final String AUTH_KEY = "auth";
public static final String CONFIG_ALIAS = WEB_HTTP_PREFIX + ".<context>." + AUTH_KEY + ".";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.eclipse.edc.api.auth.configuration.ApiAuthenticationConfigurationExtension.WEB_HTTP_PREFIX;
import static org.eclipse.edc.web.spi.configuration.WebServiceConfigurer.WEB_HTTP_PREFIX;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import static com.nimbusds.jose.jwk.source.JWKSourceBuilder.DEFAULT_CACHE_TIME_TO_LIVE;
import static org.eclipse.edc.api.auth.delegated.DelegatedAuthenticationService.MANAGEMENT_API_CONTEXT;
import static org.eclipse.edc.web.spi.configuration.WebServiceConfigurer.WEB_HTTP_PREFIX;

/**
* Extension that registers an AuthenticationService that delegates authentication and authorization to a third-party IdP
Expand All @@ -52,7 +53,6 @@ public class DelegatedAuthenticationExtension implements ServiceExtension {
@Deprecated(since = "0.7.1")
@Setting(value = "URL where the third-party IdP's public key(s) can be resolved")
public static final String AUTH_SETTING_KEY_URL = "edc.api.auth.dac.key.url";
public static final String WEB_HTTP_PREFIX = "web.http";
public static final String AUTH_KEY = "auth";
public static final String CONFIG_ALIAS = WEB_HTTP_PREFIX + ".<context>." + AUTH_KEY + ".";
@Setting(context = CONFIG_ALIAS, value = "URL where the third-party IdP's public key(s) can be resolved for the configured <context>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Optional;
import java.util.UUID;

import static org.eclipse.edc.web.spi.configuration.WebServiceConfigurer.WEB_HTTP_PREFIX;

/**
* Extension that registers an AuthenticationService that uses API Keys and register
* an {@link ApiAuthenticationProvider} under the type called tokenbased
Expand All @@ -40,7 +42,6 @@
public class TokenBasedAuthenticationExtension implements ServiceExtension {

public static final String NAME = "Static token API Authentication";
public static final String WEB_HTTP_PREFIX = "web.http";
public static final String AUTH_KEY = "auth";

public static final String CONFIG_ALIAS = WEB_HTTP_PREFIX + ".<context>." + AUTH_KEY + ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.eclipse.edc.web.spi.configuration.WebServiceConfigurer.WEB_HTTP_PREFIX;

public class JettyConfiguration {

public static final String WEB_HTTP_PREFIX = "web.http";
public static final String DEFAULT_PATH = "/api";
public static final String DEFAULT_CONTEXT_NAME = "default";
public static final int DEFAULT_PORT = 8181;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
@ExtensionPoint
public interface WebServiceConfigurer {

String WEB_HTTP_PREFIX = "web.http";

/**
* Build the configuration for an API
*
* @param config The context configuration
* @param config The context configuration
* @param webServer The WebServer
* @param settings WebService settings
* @param settings WebService settings
* @return The final webservice configuration
*/
WebServiceConfiguration configure(Config config, WebServer webServer, WebServiceSettings settings);
Expand Down

0 comments on commit 66065ce

Please sign in to comment.