From 892b4a498326332cebd3a180cfc88a83b9e973dc Mon Sep 17 00:00:00 2001 From: Paul Latzelsperger <43503240+paullatzelsperger@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:58:56 +0100 Subject: [PATCH] feat: update codebase to use Config Injection (#491) --- .../identityhub/DefaultServicesExtension.java | 20 +++---- .../DefaultServicesExtensionTest.java | 14 +++-- .../eclipse/edc/test/bom/BomSmokeTests.java | 2 + .../CredentialWatchdogExtension.java | 27 ++++----- .../CredentialWatchdogExtensionTest.java | 59 +++++++++++-------- .../SqlCredentialStoreExtension.java | 16 ++--- .../sql/SqlDidResourceStoreExtension.java | 16 ++--- .../SqlKeyPairResourceStoreExtension.java | 15 ++--- .../SqlParticipantContextStoreExtension.java | 15 ++--- .../RemoteStsAccountServiceExtension.java | 24 +++----- 10 files changed, 93 insertions(+), 115 deletions(-) diff --git a/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java b/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java index c3324796a..c695c252e 100644 --- a/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java +++ b/core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/DefaultServicesExtension.java @@ -56,12 +56,11 @@ public class DefaultServicesExtension implements ServiceExtension { public static final String NAME = "IdentityHub Default Services Extension"; public static final long DEFAULT_REVOCATION_CACHE_VALIDITY_MILLIS = 15 * 60 * 1000L; - @Setting(value = "Validity period of cached StatusList2021 credential entries in milliseconds.", defaultValue = DEFAULT_REVOCATION_CACHE_VALIDITY_MILLIS + "", type = "long") - public static final String REVOCATION_CACHE_VALIDITY = "edc.iam.credential.revocation.cache.validity"; - - @Setting(value = "Activates the JTI check: access tokens can only be used once to guard against replay attacks", defaultValue = "false", type = "boolean") - public static final String ACCESSTOKEN_JTI_VALIDATION_ACTIVATE = "edc.iam.accesstoken.jti.validation"; - + static final String ACCESSTOKEN_JTI_VALIDATION_ACTIVATE = "edc.iam.accesstoken.jti.validation"; + @Setting(description = "Activates the JTI check: access tokens can only be used once to guard against replay attacks", defaultValue = "false", key = ACCESSTOKEN_JTI_VALIDATION_ACTIVATE) + private boolean activateJtiCheck; + @Setting(description = "Validity period of cached StatusList2021 credential entries in milliseconds.", defaultValue = DEFAULT_REVOCATION_CACHE_VALIDITY_MILLIS + "", key = "edc.iam.credential.revocation.cache.validity") + private long revocationCacheValidity; @Inject private TokenValidationRulesRegistry registry; @Inject @@ -86,7 +85,7 @@ public void initialize(ServiceExtensionContext context) { var scopeIsPresentRule = new ClaimIsPresentRule(ACCESS_TOKEN_SCOPE_CLAIM); registry.addRule(DCP_ACCESS_TOKEN_CONTEXT, scopeIsPresentRule); - if (context.getSetting(ACCESSTOKEN_JTI_VALIDATION_ACTIVATE, false)) { + if (activateJtiCheck) { registry.addRule(DCP_ACCESS_TOKEN_CONTEXT, new JtiValidationRule(jwtValidationStore, context.getMonitor())); } else { context.getMonitor().warning("JWT Token ID (\"jti\" claim) Validation is not active. Please consider setting '%s=true' for protection against replay attacks".formatted(ACCESSTOKEN_JTI_VALIDATION_ACTIVATE)); @@ -111,7 +110,7 @@ public KeyPairResourceStore createDefaultKeyPairResourceStore() { @Provider(isDefault = true) public ScopeToCriterionTransformer createScopeTransformer(ServiceExtensionContext context) { context.getMonitor().warning("Using the default EdcScopeToCriterionTransformer. This is not intended for production use and should be replaced " + - "with a specialized implementation for your dataspace"); + "with a specialized implementation for your dataspace"); return new EdcScopeToCriterionTransformer(); } @@ -119,9 +118,8 @@ public ScopeToCriterionTransformer createScopeTransformer(ServiceExtensionContex public RevocationServiceRegistry createRevocationListService(ServiceExtensionContext context) { if (revocationService == null) { revocationService = new RevocationServiceRegistryImpl(context.getMonitor()); - var validity = context.getConfig().getLong(REVOCATION_CACHE_VALIDITY, DEFAULT_REVOCATION_CACHE_VALIDITY_MILLIS); - revocationService.addService(StatusList2021Status.TYPE, new StatusList2021RevocationService(typeManager.getMapper(), validity)); - revocationService.addService(BitstringStatusListStatus.TYPE, new BitstringStatusListRevocationService(typeManager.getMapper(), validity)); + revocationService.addService(StatusList2021Status.TYPE, new StatusList2021RevocationService(typeManager.getMapper(), revocationCacheValidity)); + revocationService.addService(BitstringStatusListStatus.TYPE, new BitstringStatusListRevocationService(typeManager.getMapper(), revocationCacheValidity)); } return revocationService; } diff --git a/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/DefaultServicesExtensionTest.java b/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/DefaultServicesExtensionTest.java index b6a414c96..fec5d5207 100644 --- a/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/DefaultServicesExtensionTest.java +++ b/core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/DefaultServicesExtensionTest.java @@ -14,17 +14,20 @@ package org.eclipse.edc.identityhub; +import org.eclipse.edc.boot.system.injection.ObjectFactory; import org.eclipse.edc.identityhub.accesstoken.rules.ClaimIsPresentRule; import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; import org.eclipse.edc.token.spi.TokenValidationRulesRegistry; import org.eclipse.edc.verifiablecredentials.jwt.rules.JtiValidationRule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import java.util.Map; + import static org.eclipse.edc.identityhub.DefaultServicesExtension.ACCESSTOKEN_JTI_VALIDATION_ACTIVATE; -import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; @@ -50,10 +53,11 @@ void initialize_verifyTokenRules(DefaultServicesExtension extension, ServiceExte } @Test - void initialize_verifyTokenRules_withJtiRule(DefaultServicesExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(ACCESSTOKEN_JTI_VALIDATION_ACTIVATE), anyBoolean())) - .thenReturn(true); - extension.initialize(context); + void initialize_verifyTokenRules_withJtiRule(ServiceExtensionContext context, ObjectFactory factory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of(ACCESSTOKEN_JTI_VALIDATION_ACTIVATE, Boolean.TRUE.toString()))); + + + factory.constructInstance(DefaultServicesExtension.class).initialize(context); verify(registry).addRule(eq("dcp-si"), isA(ClaimIsPresentRule.class)); verify(registry).addRule(eq("dcp-access-token"), isA(ClaimIsPresentRule.class)); verify(registry).addRule(eq("dcp-access-token"), isA(JtiValidationRule.class)); diff --git a/e2e-tests/bom-tests/src/test/java/org/eclipse/edc/test/bom/BomSmokeTests.java b/e2e-tests/bom-tests/src/test/java/org/eclipse/edc/test/bom/BomSmokeTests.java index 779ca6aff..1b7b0462f 100644 --- a/e2e-tests/bom-tests/src/test/java/org/eclipse/edc/test/bom/BomSmokeTests.java +++ b/e2e-tests/bom-tests/src/test/java/org/eclipse/edc/test/bom/BomSmokeTests.java @@ -99,6 +99,8 @@ class IdentityHubWithSts extends SmokeTest { put("web.http.accounts.path", "/api/accounts"); put("web.http.version.port", valueOf(getFreePort())); put("web.http.version.path", "/api/version"); + put("web.http.sts.port", valueOf(getFreePort())); + put("web.http.sts.path", "/api/sts"); put("edc.api.accounts.key", "password"); } }, diff --git a/extensions/common/credential-watchdog/src/main/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtension.java b/extensions/common/credential-watchdog/src/main/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtension.java index 382bb6697..0910c96f6 100644 --- a/extensions/common/credential-watchdog/src/main/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtension.java +++ b/extensions/common/credential-watchdog/src/main/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtension.java @@ -30,6 +30,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import static java.util.Optional.ofNullable; import static org.eclipse.edc.identityhub.common.credentialwatchdog.CredentialWatchdogExtension.NAME; @Extension(value = NAME) @@ -37,16 +38,17 @@ public class CredentialWatchdogExtension implements ServiceExtension { public static final String NAME = "VerifiableCredential Watchdog Extension"; public static final int DEFAULT_WATCHDOG_PERIOD = 60; - @Setting(value = "Period (in seconds) at which the Watchdog thread checks all stored credentials for their status. Configuring a number <=0 disables the Watchdog.", - type = "integer", min = 0, defaultValue = DEFAULT_WATCHDOG_PERIOD + "") - public static final String WATCHDOG_PERIOD_PROPERTY = "edc.iam.credential.status.check.period"; - public static final int DEFAULT_WATCHDOG_INITIAL_DELAY = 5; - @Setting(value = "Initial delay (in seconds) before the Watchdog thread begins its work.", - type = "integer", min = 0, defaultValue = "random number [1.." + DEFAULT_WATCHDOG_INITIAL_DELAY + "]") - public static final String WATCHDOG_DELAY_PROPERTY = "edc.iam.credential.status.check.delay"; public static final String CREDENTIAL_WATCHDOG = "CredentialWatchdog"; private final SecureRandom random = new SecureRandom(); + + @Setting(description = "Period (in seconds) at which the Watchdog thread checks all stored credentials for their status. Configuring a number <=0 disables the Watchdog.", + min = 0, defaultValue = DEFAULT_WATCHDOG_PERIOD + "", key = "edc.iam.credential.status.check.period") + private int watchdogPeriod; + @Setting(description = "Initial delay (in seconds) before the Watchdog thread begins its work.", + min = 0, key = "edc.iam.credential.status.check.delay", required = false) + private Integer initialDelay; + @Inject private ExecutorInstrumentation executorInstrumentation; @Inject @@ -56,9 +58,7 @@ public class CredentialWatchdogExtension implements ServiceExtension { @Inject private TransactionContext transactionContext; private ScheduledExecutorService scheduledExecutorService; - private Integer watchdogPeriod; private Monitor monitor; - private int initialDelay; @Override public String name() { @@ -67,15 +67,14 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - watchdogPeriod = context.getSetting(WATCHDOG_PERIOD_PROPERTY, DEFAULT_WATCHDOG_PERIOD); monitor = context.getMonitor().withPrefix(CREDENTIAL_WATCHDOG); - if (watchdogPeriod <= 0) { - monitor.debug(() -> "Config property '%s' was <= 0 (%d). The Credential Watchdog is disabled.".formatted(WATCHDOG_PERIOD_PROPERTY, watchdogPeriod)); - } else { - initialDelay = context.getSetting(WATCHDOG_DELAY_PROPERTY, randomDelay()); + if (watchdogPeriod > 0) { + initialDelay = ofNullable(initialDelay).orElseGet((this::randomDelay)); monitor.debug(() -> "Credential watchdog will run with a delay of %d seconds, at an interval of %d seconds".formatted(initialDelay, watchdogPeriod)); scheduledExecutorService = executorInstrumentation.instrument(Executors.newSingleThreadScheduledExecutor(), CREDENTIAL_WATCHDOG); + } else { + monitor.debug(() -> "The Credential Watchdog is disabled."); } } diff --git a/extensions/common/credential-watchdog/src/test/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtensionTest.java b/extensions/common/credential-watchdog/src/test/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtensionTest.java index d0f082434..0f5e43979 100644 --- a/extensions/common/credential-watchdog/src/test/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtensionTest.java +++ b/extensions/common/credential-watchdog/src/test/java/org/eclipse/edc/identityhub/common/credentialwatchdog/CredentialWatchdogExtensionTest.java @@ -15,10 +15,12 @@ package org.eclipse.edc.identityhub.common.credentialwatchdog; +import org.eclipse.edc.boot.system.injection.ObjectFactory; import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.system.ExecutorInstrumentation; import org.eclipse.edc.spi.system.ServiceExtensionContext; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -27,15 +29,13 @@ import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentMatchers; +import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import static org.eclipse.edc.identityhub.common.credentialwatchdog.CredentialWatchdogExtension.CREDENTIAL_WATCHDOG; -import static org.eclipse.edc.identityhub.common.credentialwatchdog.CredentialWatchdogExtension.WATCHDOG_DELAY_PROPERTY; -import static org.eclipse.edc.identityhub.common.credentialwatchdog.CredentialWatchdogExtension.WATCHDOG_PERIOD_PROPERTY; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; @@ -48,6 +48,8 @@ class CredentialWatchdogExtensionTest { + private static final String WATCHDOG_PERIOD_PROPERTY = "edc.iam.credential.status.check.period"; + private static final String WATCHDOG_DELAY_PROPERTY = "edc.iam.credential.status.check.delay"; private final ExecutorInstrumentation executorInstrumentationMock = mock(); private Monitor monitor; @@ -62,12 +64,12 @@ void setUp(ServiceExtensionContext context) { @DisplayName("Disable watchdog on negative or zero second period") @ParameterizedTest(name = "Disable on delay of {0} seconds") @ValueSource(ints = { 0, -1, -100 }) - void initialize_whenNegativePeriod_shouldDisable(int period, CredentialWatchdogExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(WATCHDOG_PERIOD_PROPERTY), anyInt())).thenReturn(period); - extension.initialize(context); + void initialize_whenNegativePeriod_shouldDisable(int period, ServiceExtensionContext context, ObjectFactory objectFactory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of(WATCHDOG_PERIOD_PROPERTY, String.valueOf(period)))); + objectFactory.constructInstance(CredentialWatchdogExtension.class).initialize(context); - verifyNoInteractions(executorInstrumentationMock); verify(monitor).debug(ArgumentMatchers.>argThat(stringSupplier -> stringSupplier.get().contains("Credential Watchdog is disabled"))); + verifyNoInteractions(executorInstrumentationMock); } @DisplayName("Verify random delay [1..5] if no initial delay is configured") @@ -82,10 +84,12 @@ void initialize_whenNoDelay_shouldUseRandomBetweenZeroAndFive(CredentialWatchdog @DisplayName("Verify a configured delay is used") @Test - void initialize_whenDelay_shouldUseConfiguredDelay(CredentialWatchdogExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(WATCHDOG_DELAY_PROPERTY), anyInt())).thenReturn(42); + void initialize_whenDelay_shouldUseConfiguredDelay(ServiceExtensionContext context, ObjectFactory factory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of( + WATCHDOG_DELAY_PROPERTY, String.valueOf(42) + ))); + factory.constructInstance(CredentialWatchdogExtension.class).initialize(context); - extension.initialize(context); verify(monitor).debug(ArgumentMatchers.>argThat(stringSupplier -> stringSupplier.get().endsWith("delay of 42 seconds, at an interval of 60 seconds"))); verify(executorInstrumentationMock).instrument(any(), eq(CREDENTIAL_WATCHDOG)); @@ -93,9 +97,11 @@ void initialize_whenDelay_shouldUseConfiguredDelay(CredentialWatchdogExtension e @DisplayName("Verify the watchdog is not start if a <=0 period is configured") @Test - void start_whenWatchdogDisabled_shouldNotStart(CredentialWatchdogExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(WATCHDOG_PERIOD_PROPERTY), anyInt())).thenReturn(-10); - + void start_whenWatchdogDisabled_shouldNotStart(ServiceExtensionContext context, ObjectFactory factory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of( + WATCHDOG_PERIOD_PROPERTY, String.valueOf(-10) + ))); + var extension = factory.constructInstance(CredentialWatchdogExtension.class); extension.initialize(context); extension.start(); verifyNoInteractions(executorInstrumentationMock); @@ -105,13 +111,16 @@ void start_whenWatchdogDisabled_shouldNotStart(CredentialWatchdogExtension exten @DisplayName("Verify watchdog starts when properly configured, at the expected timing intervals") @Test - void start_shouldStartWatchdog(CredentialWatchdogExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(WATCHDOG_PERIOD_PROPERTY), anyInt())).thenReturn(1); - when(context.getSetting(eq(WATCHDOG_DELAY_PROPERTY), anyInt())).thenReturn(1); + void start_shouldStartWatchdog(ServiceExtensionContext context, ObjectFactory factory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of( + WATCHDOG_PERIOD_PROPERTY, String.valueOf(1), + WATCHDOG_DELAY_PROPERTY, String.valueOf(1) + ))); var executorMock = mock(ScheduledExecutorService.class); when(executorInstrumentationMock.instrument(any(), eq(CREDENTIAL_WATCHDOG))) .thenReturn(executorMock); when(executorMock.isShutdown()).thenReturn(false); + var extension = factory.constructInstance(CredentialWatchdogExtension.class); extension.initialize(context); extension.start(); @@ -122,11 +131,12 @@ void start_shouldStartWatchdog(CredentialWatchdogExtension extension, ServiceExt @DisplayName("Verify shutting down the extension is a NOOP if the watchdog is not started") @Test - void shutdown_whenNotRunning_shouldNoop(CredentialWatchdogExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(WATCHDOG_PERIOD_PROPERTY), anyInt())).thenReturn(-1); // executor will not be initialized - when(context.getSetting(eq(WATCHDOG_DELAY_PROPERTY), anyInt())).thenReturn(1); - var executorMock = mock(ScheduledExecutorService.class); + void shutdown_whenNotRunning_shouldNoop(ServiceExtensionContext context, ObjectFactory factory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of( + WATCHDOG_PERIOD_PROPERTY, String.valueOf(-1), + WATCHDOG_DELAY_PROPERTY, String.valueOf(1)))); + var extension = factory.constructInstance(CredentialWatchdogExtension.class); extension.initialize(context); extension.shutdown(); @@ -136,9 +146,12 @@ void shutdown_whenNotRunning_shouldNoop(CredentialWatchdogExtension extension, S @DisplayName("Verify shutting down the extension stops the watchdog thread") @Test - void shutdown_whenRunning_shouldStop(CredentialWatchdogExtension extension, ServiceExtensionContext context) { - when(context.getSetting(eq(WATCHDOG_PERIOD_PROPERTY), anyInt())).thenReturn(1); - when(context.getSetting(eq(WATCHDOG_DELAY_PROPERTY), anyInt())).thenReturn(1); + void shutdown_whenRunning_shouldStop(ServiceExtensionContext context, ObjectFactory factory) { + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of( + WATCHDOG_PERIOD_PROPERTY, String.valueOf(1), + WATCHDOG_DELAY_PROPERTY, String.valueOf(1)))); + + var extension = factory.constructInstance(CredentialWatchdogExtension.class); var executorMock = mock(ScheduledExecutorService.class); when(executorInstrumentationMock.instrument(any(), eq(CREDENTIAL_WATCHDOG))).thenReturn(executorMock); diff --git a/extensions/store/sql/identity-hub-credentials-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/credentials/SqlCredentialStoreExtension.java b/extensions/store/sql/identity-hub-credentials-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/credentials/SqlCredentialStoreExtension.java index 6dcefc11e..8d435aa31 100644 --- a/extensions/store/sql/identity-hub-credentials-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/credentials/SqlCredentialStoreExtension.java +++ b/extensions/store/sql/identity-hub-credentials-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/credentials/SqlCredentialStoreExtension.java @@ -25,7 +25,6 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; -import org.eclipse.edc.sql.configuration.DataSourceName; import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; import org.eclipse.edc.transaction.spi.TransactionContext; @@ -35,11 +34,8 @@ public class SqlCredentialStoreExtension implements ServiceExtension { public static final String NAME = "CredentialResource SQL Store Extension"; - @Deprecated(since = "0.8.1") - @Setting(value = "Datasource name for the DidResource database", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_SETTING_NAME = "edc.datasource.credentials.name"; - @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_NAME = "edc.sql.store.credentials.datasource"; + @Setting(description = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE, key = "edc.sql.store.credentials.datasource") + private String dataSourceName; @Inject private DataSourceRegistry dataSourceRegistry; @@ -57,12 +53,12 @@ public class SqlCredentialStoreExtension implements ServiceExtension { @Override public void initialize(ServiceExtensionContext context) { - sqlSchemaBootstrapper.addStatementFromResource(getDataSourceName(context), "credentials-schema.sql"); + sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "credentials-schema.sql"); } @Provider public CredentialStore createSqlStore(ServiceExtensionContext context) { - return new SqlCredentialStore(dataSourceRegistry, getDataSourceName(context), transactionContext, typemanager.getMapper(), + return new SqlCredentialStore(dataSourceRegistry, dataSourceName, transactionContext, typemanager.getMapper(), queryExecutor, getStatementImpl()); } @@ -70,8 +66,4 @@ private CredentialStoreStatements getStatementImpl() { return statements != null ? statements : new PostgresDialectStatements(); } - private String getDataSourceName(ServiceExtensionContext context) { - return DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); - } - } diff --git a/extensions/store/sql/identity-hub-did-store-sql/src/main/java/org/eclipse/edc/identityhub/did/store/sql/SqlDidResourceStoreExtension.java b/extensions/store/sql/identity-hub-did-store-sql/src/main/java/org/eclipse/edc/identityhub/did/store/sql/SqlDidResourceStoreExtension.java index 6a59e39d9..eb7ce151f 100644 --- a/extensions/store/sql/identity-hub-did-store-sql/src/main/java/org/eclipse/edc/identityhub/did/store/sql/SqlDidResourceStoreExtension.java +++ b/extensions/store/sql/identity-hub-did-store-sql/src/main/java/org/eclipse/edc/identityhub/did/store/sql/SqlDidResourceStoreExtension.java @@ -25,7 +25,6 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; -import org.eclipse.edc.sql.configuration.DataSourceName; import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; import org.eclipse.edc.transaction.spi.TransactionContext; @@ -35,11 +34,8 @@ public class SqlDidResourceStoreExtension implements ServiceExtension { public static final String NAME = "DID Resource SQL Store Extension"; - @Deprecated(since = "0.8.1") - @Setting(value = "Datasource name for the DidResource database", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_SETTING_NAME = "edc.datasource.didresource.name"; - @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_NAME = "edc.sql.store.didresource.datasource"; + @Setting(description = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE, key = "edc.sql.store.didresource.datasource") + private String dataSourceName; @Inject private DataSourceRegistry dataSourceRegistry; @@ -56,20 +52,16 @@ public class SqlDidResourceStoreExtension implements ServiceExtension { @Override public void initialize(ServiceExtensionContext context) { - sqlSchemaBootstrapper.addStatementFromResource(getDataSourceName(context), "did-schema.sql"); + sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "did-schema.sql"); } @Provider public DidResourceStore createSqlStore(ServiceExtensionContext context) { - return new SqlDidResourceStore(dataSourceRegistry, getDataSourceName(context), transactionContext, typemanager.getMapper(), + return new SqlDidResourceStore(dataSourceRegistry, dataSourceName, transactionContext, typemanager.getMapper(), queryExecutor, getStatementImpl()); } private DidResourceStatements getStatementImpl() { return statements != null ? statements : new PostgresDialectStatements(); } - - private String getDataSourceName(ServiceExtensionContext context) { - return DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); - } } diff --git a/extensions/store/sql/identity-hub-keypair-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/keypair/SqlKeyPairResourceStoreExtension.java b/extensions/store/sql/identity-hub-keypair-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/keypair/SqlKeyPairResourceStoreExtension.java index 5b1485db4..3b45c80d1 100644 --- a/extensions/store/sql/identity-hub-keypair-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/keypair/SqlKeyPairResourceStoreExtension.java +++ b/extensions/store/sql/identity-hub-keypair-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/keypair/SqlKeyPairResourceStoreExtension.java @@ -25,7 +25,6 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; -import org.eclipse.edc.sql.configuration.DataSourceName; import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; import org.eclipse.edc.transaction.spi.TransactionContext; @@ -35,11 +34,8 @@ public class SqlKeyPairResourceStoreExtension implements ServiceExtension { public static final String NAME = "KeyPair Resource SQL Store Extension"; - @Deprecated(since = "0.8.1") - @Setting(value = "Datasource name for the KeyPairResource database", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_SETTING_NAME = "edc.datasource.keypair.name"; - @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_NAME = "edc.sql.store.keypair.datasource"; + @Setting(description = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE, key = "edc.sql.store.keypair.datasource") + private String dataSourceName; @Inject private DataSourceRegistry dataSourceRegistry; @@ -66,12 +62,12 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - sqlSchemaBootstrapper.addStatementFromResource(getDataSourceName(context), "keypairs-schema.sql"); + sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "keypairs-schema.sql"); } @Provider public KeyPairResourceStore createSqlStore(ServiceExtensionContext context) { - return new SqlKeyPairResourceStore(dataSourceRegistry, getDataSourceName(context), transactionContext, typemanager.getMapper(), + return new SqlKeyPairResourceStore(dataSourceRegistry, dataSourceName, transactionContext, typemanager.getMapper(), queryExecutor, getStatementImpl()); } @@ -79,7 +75,4 @@ private KeyPairResourceStoreStatements getStatementImpl() { return statements != null ? statements : new PostgresDialectStatements(); } - private String getDataSourceName(ServiceExtensionContext context) { - return DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); - } } diff --git a/extensions/store/sql/identity-hub-participantcontext-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/participantcontext/SqlParticipantContextStoreExtension.java b/extensions/store/sql/identity-hub-participantcontext-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/participantcontext/SqlParticipantContextStoreExtension.java index a467185b9..61b2a95f0 100644 --- a/extensions/store/sql/identity-hub-participantcontext-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/participantcontext/SqlParticipantContextStoreExtension.java +++ b/extensions/store/sql/identity-hub-participantcontext-store-sql/src/main/java/org/eclipse/edc/identityhub/store/sql/participantcontext/SqlParticipantContextStoreExtension.java @@ -25,7 +25,6 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.sql.bootstrapper.SqlSchemaBootstrapper; -import org.eclipse.edc.sql.configuration.DataSourceName; import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; import org.eclipse.edc.transaction.spi.TransactionContext; @@ -35,11 +34,8 @@ public class SqlParticipantContextStoreExtension implements ServiceExtension { public static final String NAME = "ParticipantContext SQL Store Extension"; - @Deprecated(since = "0.8.1") - @Setting(value = "Datasource name for the ParticipantContext database", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_SETTING_NAME = "edc.datasource.participantcontext.name"; - @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE) - public static final String DATASOURCE_NAME = "edc.sql.store.participantcontext.datasource"; + @Setting(value = "The datasource to be used", defaultValue = DataSourceRegistry.DEFAULT_DATASOURCE, key = "edc.sql.store.participantcontext.datasource") + private String dataSourceName; @Inject private DataSourceRegistry dataSourceRegistry; @@ -56,12 +52,12 @@ public class SqlParticipantContextStoreExtension implements ServiceExtension { @Override public void initialize(ServiceExtensionContext context) { - sqlSchemaBootstrapper.addStatementFromResource(getDataSourceName(context), "participant-schema.sql"); + sqlSchemaBootstrapper.addStatementFromResource(dataSourceName, "participant-schema.sql"); } @Provider public ParticipantContextStore createSqlStore(ServiceExtensionContext context) { - return new SqlParticipantContextStore(dataSourceRegistry, getDataSourceName(context), transactionContext, typemanager.getMapper(), + return new SqlParticipantContextStore(dataSourceRegistry, dataSourceName, transactionContext, typemanager.getMapper(), queryExecutor, getStatementImpl()); } @@ -69,7 +65,4 @@ private ParticipantContextStoreStatements getStatementImpl() { return statements != null ? statements : new PostgresDialectStatements(); } - private String getDataSourceName(ServiceExtensionContext context) { - return DataSourceName.getDataSourceName(DATASOURCE_NAME, DATASOURCE_SETTING_NAME, context.getConfig(), context.getMonitor()); - } } diff --git a/extensions/sts/sts-account-service-remote/src/main/java/org/eclipse/edc/identityhub/sts/accountservice/RemoteStsAccountServiceExtension.java b/extensions/sts/sts-account-service-remote/src/main/java/org/eclipse/edc/identityhub/sts/accountservice/RemoteStsAccountServiceExtension.java index 887791149..5b85532b9 100644 --- a/extensions/sts/sts-account-service-remote/src/main/java/org/eclipse/edc/identityhub/sts/accountservice/RemoteStsAccountServiceExtension.java +++ b/extensions/sts/sts-account-service-remote/src/main/java/org/eclipse/edc/identityhub/sts/accountservice/RemoteStsAccountServiceExtension.java @@ -35,14 +35,12 @@ public class RemoteStsAccountServiceExtension implements ServiceExtension { public static final String DEFAULT_AUTH_HEADER = "x-api-key"; public static final String NAME = "Remote STS Account Service Extension"; - @Setting(value = "The name of the Auth header to use. Could be 'Authorization', some custom auth header, etc.", defaultValue = DEFAULT_AUTH_HEADER) - public static final String AUTH_HEADER = "edc.sts.accounts.api.auth.header.name"; - @Setting(value = "The value of the Auth header to use. Currently we only support static values, e.g. tokens etc.") - public static final String AUTH_HEADER_VALUE = "edc.sts.accounts.api.auth.header.value"; - - @Setting(value = "The base URL of the remote STS Accounts API") - public static final String REMOTE_STS_API_BASE_URL = "edc.sts.account.api.url"; - + @Setting(description = "The base URL of the remote STS Accounts API", key = "edc.sts.account.api.url") + private String baseUrl; + @Setting(description = "The name of the Auth header to use. Could be 'Authorization', some custom auth header, etc.", defaultValue = DEFAULT_AUTH_HEADER, key = "edc.sts.accounts.api.auth.header.name") + private String authHeader; + @Setting(description = "The value of the Auth header to use. Currently we only support static values, e.g. tokens etc.", key = "edc.sts.accounts.api.auth.header.value") + private String authHeaderValue; @Inject private EdcHttpClient edcHttpClient; @Inject @@ -57,17 +55,11 @@ public String name() { public StsAccountService createAccountManager(ServiceExtensionContext context) { var monitor = context.getMonitor().withPrefix("STS-Account"); monitor.info("This IdentityHub runtime is configured to manage STS Accounts remotely using the STS Accounts API. That means ParticipantContexts and STS Accounts will be synchronized automatically."); - return new RemoteStsAccountService(getAccountApiBaseUrl(context), edcHttpClient, getAuthHeaderSupplier(context), monitor, typeManager.getMapper()); + return new RemoteStsAccountService(baseUrl, edcHttpClient, getAuthHeaderSupplier(context), monitor, typeManager.getMapper()); } private @NotNull Supplier> getAuthHeaderSupplier(ServiceExtensionContext context) { //obtain the auth header value outside the supplier to make it fail fast - var authHeaderValue = context.getConfig().getString(AUTH_HEADER_VALUE); - return () -> Map.of(context.getConfig().getString(AUTH_HEADER, DEFAULT_AUTH_HEADER), authHeaderValue); + return () -> Map.of(authHeader, authHeaderValue); } - - private String getAccountApiBaseUrl(ServiceExtensionContext context) { - return context.getConfig().getString(REMOTE_STS_API_BASE_URL); - } - }