Changesets · Branches · Tags · Compare
| Changeset | f2706f2c552fbb2ca64ab64105451975699a3cadd631c11c6ca78c95d4dd8ad3 |
|---|---|
| Author | ndr_brt <andrea.bertagnolli@gmail.com> · 2024-08-20 14:20 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-08-20 14:20 +02:00 |
| Parents | f2941742a18d |
35 files changed
modified DEPENDENCIES +0 −7
| @@ -306,19 +306,12 @@ | ||
| 306 | 306 | maven/mavencentral/org.jetbrains/annotations/17.0.0, Apache-2.0, approved, clearlydefined |
| 307 | 307 | maven/mavencentral/org.jetbrains/annotations/24.1.0, Apache-2.0, approved, clearlydefined |
| 308 | 308 | maven/mavencentral/org.junit-pioneer/junit-pioneer/2.2.0, EPL-2.0, approved, #11857 |
| 309 | -maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.10.3, EPL-2.0, approved, #9714 | |
| 310 | 309 | maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.11.0, EPL-2.0, approved, #15935 |
| 311 | -maven/mavencentral/org.junit.jupiter/junit-jupiter-engine/5.10.3, EPL-2.0, approved, #9711 | |
| 312 | 310 | maven/mavencentral/org.junit.jupiter/junit-jupiter-engine/5.11.0, EPL-2.0, approved, #15939 |
| 313 | -maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.10.3, EPL-2.0, approved, #15250 | |
| 314 | 311 | maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.11.0, EPL-2.0, approved, #15940 |
| 315 | -maven/mavencentral/org.junit.platform/junit-platform-commons/1.10.3, EPL-2.0, approved, #9715 | |
| 316 | 312 | maven/mavencentral/org.junit.platform/junit-platform-commons/1.11.0, EPL-2.0, approved, #15936 |
| 317 | -maven/mavencentral/org.junit.platform/junit-platform-engine/1.10.3, EPL-2.0, approved, #9709 | |
| 318 | 313 | maven/mavencentral/org.junit.platform/junit-platform-engine/1.11.0, EPL-2.0, approved, #15932 |
| 319 | -maven/mavencentral/org.junit.platform/junit-platform-launcher/1.10.3, EPL-2.0, approved, #15216 | |
| 320 | 314 | maven/mavencentral/org.junit.platform/junit-platform-launcher/1.11.0, EPL-2.0, approved, #15934 |
| 321 | -maven/mavencentral/org.junit/junit-bom/5.10.3, EPL-2.0, approved, #9844 | |
| 322 | 315 | maven/mavencentral/org.junit/junit-bom/5.11.0, , restricted, clearlydefined |
| 323 | 316 | maven/mavencentral/org.junit/junit-bom/5.9.2, EPL-2.0, approved, #4711 |
| 324 | 317 | maven/mavencentral/org.jvnet.mimepull/mimepull/1.9.15, CDDL-1.1 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, CQ21484 |
modified build.gradle.kts +2 −16
| @@ -20,36 +20,22 @@ | ||
| 20 | 20 | val javaVersion: String by project |
| 21 | 21 | val edcScmUrl: String by project |
| 22 | 22 | val edcScmConnection: String by project |
| 23 | -val annotationProcessorVersion: String by project | |
| 24 | 23 | |
| 25 | 24 | buildscript { |
| 26 | 25 | dependencies { |
| 27 | - val edcGradlePluginsVersion: String by project | |
| 28 | - classpath("org.eclipse.edc.edc-build:org.eclipse.edc.edc-build.gradle.plugin:${edcGradlePluginsVersion}") | |
| 26 | + val version: String by project | |
| 27 | + classpath("org.eclipse.edc.edc-build:org.eclipse.edc.edc-build.gradle.plugin:$version") | |
| 29 | 28 | } |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | 31 | allprojects { |
| 33 | 32 | apply(plugin = "${group}.edc-build") |
| 34 | 33 | |
| 35 | - // configure which version of the annotation processor to use. defaults to the same version as the plugin | |
| 36 | - configure<org.eclipse.edc.plugins.autodoc.AutodocExtension> { | |
| 37 | - processorVersion.set(annotationProcessorVersion) | |
| 38 | - outputDirectory.set(project.layout.buildDirectory.asFile) | |
| 39 | - } | |
| 40 | - | |
| 41 | 34 | configure<org.eclipse.edc.plugins.edcbuild.extensions.BuildExtension> { |
| 42 | 35 | pom { |
| 43 | 36 | scmUrl.set(edcScmUrl) |
| 44 | 37 | scmConnection.set(edcScmConnection) |
| 45 | 38 | } |
| 46 | - swagger { | |
| 47 | - title.set((project.findProperty("apiTitle") ?: "EDC REST API") as String) | |
| 48 | - description = | |
| 49 | - (project.findProperty("apiDescription") ?: "EDC REST APIs - merged by OpenApiMerger") as String | |
| 50 | - outputFilename.set(project.name) | |
| 51 | - outputDirectory.set(file("${rootProject.projectDir.path}/resources/openapi/yaml")) | |
| 52 | - } | |
| 53 | 39 | } |
| 54 | 40 | |
| 55 | 41 | configure<CheckstyleExtension> { |
modified core/common/junit/build.gradle.kts +0 −1
| @@ -35,7 +35,6 @@ | ||
| 35 | 35 | |
| 36 | 36 | runtimeOnly(libs.junit.jupiter.engine) |
| 37 | 37 | |
| 38 | - implementation(libs.junit.pioneer) | |
| 39 | 38 | implementation(libs.testcontainers.junit) |
| 40 | 39 | testImplementation(project(":core:common:connector-core")) |
| 41 | 40 |
modified core/data-plane/data-plane-core/build.gradle.kts +0 −3
| @@ -24,11 +24,8 @@ | ||
| 24 | 24 | |
| 25 | 25 | implementation(project(":spi:common:token-spi")) |
| 26 | 26 | implementation(project(":core:common:lib:store-lib")) |
| 27 | - implementation(project(":core:common:token-core")) // for the JwtGenerationService | |
| 28 | - implementation(project(":core:common:boot")) | |
| 29 | 27 | implementation(project(":core:common:lib:util-lib")) |
| 30 | 28 | implementation(project(":core:data-plane:data-plane-util")) |
| 31 | - implementation(project(":extensions:common:http")) | |
| 32 | 29 | implementation(project(":core:common:lib:state-machine-lib")) |
| 33 | 30 | |
| 34 | 31 | implementation(libs.opentelemetry.instrumentation.annotations) |
deleted core/data-plane/data-plane-core/src/main/java/org/eclipse/edc/connector/dataplane/framework/DataPlaneDefaultIamServicesExtension.java +0 −83
| @@ -1,83 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.dataplane.framework; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.connector.dataplane.framework.iam.DefaultDataPlaneAccessTokenServiceImpl; | |
| 18 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 19 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 20 | -import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; | |
| 21 | -import org.eclipse.edc.jwt.signer.spi.JwsSignerProvider; | |
| 22 | -import org.eclipse.edc.keys.spi.LocalPublicKeyService; | |
| 23 | -import org.eclipse.edc.keys.spi.PrivateKeyResolver; | |
| 24 | -import org.eclipse.edc.runtime.metamodel.annotation.Extension; | |
| 25 | -import org.eclipse.edc.runtime.metamodel.annotation.Inject; | |
| 26 | -import org.eclipse.edc.runtime.metamodel.annotation.Provider; | |
| 27 | -import org.eclipse.edc.runtime.metamodel.annotation.Setting; | |
| 28 | -import org.eclipse.edc.spi.result.Result; | |
| 29 | -import org.eclipse.edc.spi.system.ServiceExtension; | |
| 30 | -import org.eclipse.edc.spi.system.ServiceExtensionContext; | |
| 31 | -import org.eclipse.edc.token.JwtGenerationService; | |
| 32 | -import org.eclipse.edc.token.spi.TokenValidationService; | |
| 33 | - | |
| 34 | -import java.util.function.Supplier; | |
| 35 | - | |
| 36 | - | |
| 37 | -@Extension(value = DataPlaneDefaultIamServicesExtension.NAME) | |
| 38 | -public class DataPlaneDefaultIamServicesExtension implements ServiceExtension { | |
| 39 | - | |
| 40 | - public static final String NAME = "Data Plane Framework Default IAM Services"; | |
| 41 | - | |
| 42 | - @Setting(value = "Alias of private key used for signing tokens, retrieved from private key resolver") | |
| 43 | - public static final String TOKEN_SIGNER_PRIVATE_KEY_ALIAS = "edc.transfer.proxy.token.signer.privatekey.alias"; | |
| 44 | - @Setting(value = "Alias of public key used for verifying the tokens, retrieved from the vault") | |
| 45 | - public static final String TOKEN_VERIFIER_PUBLIC_KEY_ALIAS = "edc.transfer.proxy.token.verifier.publickey.alias"; | |
| 46 | - | |
| 47 | - @Inject | |
| 48 | - private AccessTokenDataStore accessTokenDataStore; | |
| 49 | - @Inject | |
| 50 | - private TokenValidationService tokenValidationService; | |
| 51 | - @Inject | |
| 52 | - private PrivateKeyResolver privateKeyResolver; | |
| 53 | - @Inject | |
| 54 | - private LocalPublicKeyService localPublicKeyService; | |
| 55 | - @Inject | |
| 56 | - private JwsSignerProvider jwsSignerProvider; | |
| 57 | - | |
| 58 | - @Override | |
| 59 | - public String name() { | |
| 60 | - return NAME; | |
| 61 | - } | |
| 62 | - | |
| 63 | - @Provider(isDefault = true) | |
| 64 | - public DataPlaneAccessControlService defaultAccessControlService(ServiceExtensionContext context) { | |
| 65 | - context.getMonitor().debug("DataPlane Access Control: default implementation is used, will always return Result.success()"); | |
| 66 | - return (claimToken, address, requestData, additionalData) -> Result.success(); | |
| 67 | - } | |
| 68 | - | |
| 69 | - @Provider(isDefault = true) | |
| 70 | - public DataPlaneAccessTokenService defaultAccessTokenService(ServiceExtensionContext context) { | |
| 71 | - var tokenVerifierPublicKeyAlias = context.getConfig().getString(TOKEN_VERIFIER_PUBLIC_KEY_ALIAS); | |
| 72 | - var tokenSignerPrivateKeyAlias = context.getConfig().getString(TOKEN_SIGNER_PRIVATE_KEY_ALIAS); | |
| 73 | - var monitor = context.getMonitor().withPrefix("DataPlane IAM"); | |
| 74 | - return new DefaultDataPlaneAccessTokenServiceImpl(new JwtGenerationService(jwsSignerProvider), | |
| 75 | - accessTokenDataStore, monitor, () -> tokenSignerPrivateKeyAlias, | |
| 76 | - publicKeyIdSupplier(tokenVerifierPublicKeyAlias), tokenValidationService, localPublicKeyService); | |
| 77 | - } | |
| 78 | - | |
| 79 | - private Supplier<String> publicKeyIdSupplier(String tokenVerifierPublicKeyAlias) { | |
| 80 | - return () -> tokenVerifierPublicKeyAlias; | |
| 81 | - } | |
| 82 | - | |
| 83 | -} |
modified core/data-plane/data-plane-core/src/main/java/org/eclipse/edc/connector/dataplane/framework/DataPlaneDefaultServicesExtension.java +8 −0
| @@ -18,6 +18,8 @@ | ||
| 18 | 18 | import org.eclipse.edc.connector.dataplane.framework.registry.TransferServiceSelectionStrategy; |
| 19 | 19 | import org.eclipse.edc.connector.dataplane.framework.store.InMemoryAccessTokenDataStore; |
| 20 | 20 | import org.eclipse.edc.connector.dataplane.framework.store.InMemoryDataPlaneStore; |
| 21 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService; | |
| 22 | +import org.eclipse.edc.connector.dataplane.spi.iam.NoOpDataPlaneAuthorizationService; | |
| 21 | 23 | import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; |
| 22 | 24 | import org.eclipse.edc.connector.dataplane.spi.pipeline.PipelineService; |
| 23 | 25 | import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; |
| @@ -70,4 +72,10 @@ | ||
| 70 | 72 | public PublicEndpointGeneratorService publicEndpointGenerator() { |
| 71 | 73 | return new PublicEndpointGeneratorServiceImpl(); |
| 72 | 74 | } |
| 75 | + | |
| 76 | + @Provider(isDefault = true) | |
| 77 | + public DataPlaneAuthorizationService dataPlaneAuthorizationService(ServiceExtensionContext context) { | |
| 78 | + context.getMonitor().info("No proper DataPlaneAuthorizationService provided. The data-plane won't support PULL transfer types."); | |
| 79 | + return new NoOpDataPlaneAuthorizationService(); | |
| 80 | + } | |
| 73 | 81 | } |
modified core/data-plane/data-plane-core/src/main/java/org/eclipse/edc/connector/dataplane/framework/DataPlaneFrameworkExtension.java +0 −19
| @@ -15,14 +15,10 @@ | ||
| 15 | 15 | package org.eclipse.edc.connector.dataplane.framework; |
| 16 | 16 | |
| 17 | 17 | import org.eclipse.edc.connector.controlplane.api.client.spi.transferprocess.TransferProcessApiClient; |
| 18 | -import org.eclipse.edc.connector.dataplane.framework.iam.DataPlaneAuthorizationServiceImpl; | |
| 19 | 18 | import org.eclipse.edc.connector.dataplane.framework.manager.DataPlaneManagerImpl; |
| 20 | 19 | import org.eclipse.edc.connector.dataplane.framework.registry.TransferServiceRegistryImpl; |
| 21 | 20 | import org.eclipse.edc.connector.dataplane.framework.registry.TransferServiceSelectionStrategy; |
| 22 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 23 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 24 | 21 | import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService; |
| 25 | -import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | |
| 26 | 22 | import org.eclipse.edc.connector.dataplane.spi.manager.DataPlaneManager; |
| 27 | 23 | import org.eclipse.edc.connector.dataplane.spi.pipeline.DataTransferExecutorServiceContainer; |
| 28 | 24 | import org.eclipse.edc.connector.dataplane.spi.pipeline.PipelineService; |
| @@ -110,12 +106,6 @@ | ||
| 110 | 106 | @Inject |
| 111 | 107 | private PipelineService pipelineService; |
| 112 | 108 | @Inject |
| 113 | - private DataPlaneAccessTokenService accessTokenService; | |
| 114 | - @Inject | |
| 115 | - private DataPlaneAccessControlService accessControlService; | |
| 116 | - @Inject | |
| 117 | - private PublicEndpointGeneratorService endpointGenerator; | |
| 118 | - | |
| 119 | 109 | private DataPlaneAuthorizationService authorizationService; |
| 120 | 110 | |
| 121 | 111 | @Override |
| @@ -144,7 +134,6 @@ | ||
| 144 | 134 | .transferServiceRegistry(transferServiceRegistry) |
| 145 | 135 | .store(store) |
| 146 | 136 | .transferProcessClient(transferProcessApiClient) |
| 147 | - .authorizationService(authorizationService(context)) | |
| 148 | 137 | .monitor(monitor) |
| 149 | 138 | .telemetry(telemetry) |
| 150 | 139 | .build(); |
| @@ -172,14 +161,6 @@ | ||
| 172 | 161 | executorInstrumentation.instrument(executorService, "Data plane transfers")); |
| 173 | 162 | } |
| 174 | 163 | |
| 175 | - @Provider | |
| 176 | - public DataPlaneAuthorizationService authorizationService(ServiceExtensionContext context) { | |
| 177 | - if (authorizationService == null) { | |
| 178 | - authorizationService = new DataPlaneAuthorizationServiceImpl(accessTokenService, endpointGenerator, accessControlService, context.getParticipantId(), clock); | |
| 179 | - } | |
| 180 | - return authorizationService; | |
| 181 | - } | |
| 182 | - | |
| 183 | 164 | @NotNull |
| 184 | 165 | private EntityRetryProcessConfiguration getEntityRetryProcessConfiguration(ServiceExtensionContext context) { |
| 185 | 166 | var retryLimit = context.getSetting(DATAPLANE_SEND_RETRY_LIMIT, DEFAULT_SEND_RETRY_LIMIT); |
deleted core/data-plane/data-plane-core/src/main/java/org/eclipse/edc/connector/dataplane/framework/iam/DataPlaneAuthorizationServiceImpl.java +0 −113
| @@ -1,113 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.dataplane.framework.iam; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.connector.dataplane.spi.Endpoint; | |
| 18 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 19 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 20 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService; | |
| 21 | -import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | |
| 22 | -import org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames; | |
| 23 | -import org.eclipse.edc.spi.iam.TokenParameters; | |
| 24 | -import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 25 | -import org.eclipse.edc.spi.result.Result; | |
| 26 | -import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 27 | -import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; | |
| 28 | - | |
| 29 | -import java.time.Clock; | |
| 30 | -import java.util.HashMap; | |
| 31 | -import java.util.Map; | |
| 32 | -import java.util.UUID; | |
| 33 | - | |
| 34 | -import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 35 | -import static org.eclipse.edc.spi.result.Result.success; | |
| 36 | - | |
| 37 | -public class DataPlaneAuthorizationServiceImpl implements DataPlaneAuthorizationService { | |
| 38 | - public static final String PROPERTY_AGREEMENT_ID = "agreement_id"; | |
| 39 | - public static final String PROPERTY_ASSET_ID = "asset_id"; | |
| 40 | - public static final String PROPERTY_PROCESS_ID = "process_id"; | |
| 41 | - public static final String PROPERTY_FLOW_TYPE = "flow_type"; | |
| 42 | - private static final String PROPERTY_PARTICIPANT_ID = "participant_id"; | |
| 43 | - private final DataPlaneAccessTokenService accessTokenService; | |
| 44 | - private final PublicEndpointGeneratorService endpointGenerator; | |
| 45 | - private final DataPlaneAccessControlService accessControlService; | |
| 46 | - private final String ownParticipantId; | |
| 47 | - private final Clock clock; | |
| 48 | - | |
| 49 | - public DataPlaneAuthorizationServiceImpl(DataPlaneAccessTokenService accessTokenService, | |
| 50 | - PublicEndpointGeneratorService endpointGenerator, | |
| 51 | - DataPlaneAccessControlService accessControlService, | |
| 52 | - String ownParticipantId, | |
| 53 | - Clock clock) { | |
| 54 | - this.accessTokenService = accessTokenService; | |
| 55 | - this.endpointGenerator = endpointGenerator; | |
| 56 | - this.accessControlService = accessControlService; | |
| 57 | - this.ownParticipantId = ownParticipantId; | |
| 58 | - this.clock = clock; | |
| 59 | - } | |
| 60 | - | |
| 61 | - @Override | |
| 62 | - public Result<DataAddress> createEndpointDataReference(DataFlowStartMessage message) { | |
| 63 | - return endpointGenerator.generateFor(message.getTransferType().destinationType(), message.getSourceDataAddress()) | |
| 64 | - .compose(endpoint -> { | |
| 65 | - var additionalProperties = new HashMap<String, Object>(message.getProperties()); | |
| 66 | - additionalProperties.put(PROPERTY_AGREEMENT_ID, message.getAgreementId()); | |
| 67 | - additionalProperties.put(PROPERTY_ASSET_ID, message.getAssetId()); | |
| 68 | - additionalProperties.put(PROPERTY_PROCESS_ID, message.getProcessId()); | |
| 69 | - additionalProperties.put(PROPERTY_FLOW_TYPE, message.getFlowType().toString()); | |
| 70 | - additionalProperties.put(PROPERTY_PARTICIPANT_ID, message.getParticipantId()); | |
| 71 | - | |
| 72 | - return accessTokenService.obtainToken(createTokenParams(message), message.getSourceDataAddress(), additionalProperties) | |
| 73 | - .compose(tokenRepresentation -> createDataAddress(tokenRepresentation, endpoint)); | |
| 74 | - } | |
| 75 | - ); | |
| 76 | - } | |
| 77 | - | |
| 78 | - @Override | |
| 79 | - public Result<DataAddress> authorize(String token, Map<String, Object> requestData) { | |
| 80 | - return accessTokenService.resolve(token) | |
| 81 | - .compose(atd -> accessControlService.checkAccess(atd.claimToken(), atd.dataAddress(), requestData, atd.additionalProperties()) | |
| 82 | - .map(u -> atd.dataAddress()) | |
| 83 | - ); | |
| 84 | - } | |
| 85 | - | |
| 86 | - @Override | |
| 87 | - public Result<Void> revokeEndpointDataReference(String transferProcessId, String reason) { | |
| 88 | - return accessTokenService.revoke(transferProcessId, reason); | |
| 89 | - } | |
| 90 | - | |
| 91 | - private Result<DataAddress> createDataAddress(TokenRepresentation tokenRepresentation, Endpoint publicEndpoint) { | |
| 92 | - var address = DataAddress.Builder.newInstance() | |
| 93 | - .type(publicEndpoint.endpointType()) | |
| 94 | - .property(EDC_NAMESPACE + "endpoint", publicEndpoint.endpoint()) | |
| 95 | - .property(EDC_NAMESPACE + "endpointType", publicEndpoint.endpointType()) //this is duplicated in the type() field, but will make serialization easier | |
| 96 | - .properties(tokenRepresentation.getAdditional()) // would contain the "authType = bearer" entry | |
| 97 | - .property(EDC_NAMESPACE + "authorization", tokenRepresentation.getToken()) | |
| 98 | - .build(); | |
| 99 | - | |
| 100 | - return success(address); | |
| 101 | - } | |
| 102 | - | |
| 103 | - private TokenParameters createTokenParams(DataFlowStartMessage message) { | |
| 104 | - return TokenParameters.Builder.newInstance() | |
| 105 | - .claims(JwtRegisteredClaimNames.JWT_ID, UUID.randomUUID().toString()) | |
| 106 | - .claims(JwtRegisteredClaimNames.AUDIENCE, message.getParticipantId()) | |
| 107 | - .claims(JwtRegisteredClaimNames.ISSUER, ownParticipantId) | |
| 108 | - .claims(JwtRegisteredClaimNames.SUBJECT, ownParticipantId) | |
| 109 | - .claims(JwtRegisteredClaimNames.ISSUED_AT, clock.instant().toEpochMilli()) // todo: milli or second? | |
| 110 | - .build(); | |
| 111 | - } | |
| 112 | - | |
| 113 | -} |
deleted core/data-plane/data-plane-core/src/main/java/org/eclipse/edc/connector/dataplane/framework/iam/DefaultDataPlaneAccessTokenServiceImpl.java +0 −160
| @@ -1,160 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.dataplane.framework.iam; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.connector.dataplane.spi.AccessTokenData; | |
| 18 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 19 | -import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; | |
| 20 | -import org.eclipse.edc.keys.spi.PublicKeyResolver; | |
| 21 | -import org.eclipse.edc.spi.iam.ClaimToken; | |
| 22 | -import org.eclipse.edc.spi.iam.TokenParameters; | |
| 23 | -import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 24 | -import org.eclipse.edc.spi.monitor.Monitor; | |
| 25 | -import org.eclipse.edc.spi.query.Criterion; | |
| 26 | -import org.eclipse.edc.spi.query.QuerySpec; | |
| 27 | -import org.eclipse.edc.spi.result.Result; | |
| 28 | -import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 29 | -import org.eclipse.edc.token.spi.KeyIdDecorator; | |
| 30 | -import org.eclipse.edc.token.spi.TokenDecorator; | |
| 31 | -import org.eclipse.edc.token.spi.TokenGenerationService; | |
| 32 | -import org.eclipse.edc.token.spi.TokenValidationRule; | |
| 33 | -import org.eclipse.edc.token.spi.TokenValidationService; | |
| 34 | - | |
| 35 | -import java.util.ArrayList; | |
| 36 | -import java.util.List; | |
| 37 | -import java.util.Map; | |
| 38 | -import java.util.Objects; | |
| 39 | -import java.util.UUID; | |
| 40 | -import java.util.function.Supplier; | |
| 41 | -import java.util.stream.Stream; | |
| 42 | - | |
| 43 | -import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 44 | - | |
| 45 | -/** | |
| 46 | - * This implementation of the {@link DataPlaneAccessTokenService} uses a backing storage ({@link AccessTokenDataStore}) to keep a record of all | |
| 47 | - * tokens it has issued. Tokens are in JWT format. | |
| 48 | - */ | |
| 49 | -public class DefaultDataPlaneAccessTokenServiceImpl implements DataPlaneAccessTokenService { | |
| 50 | - public static final String TOKEN_ID = "jti"; | |
| 51 | - private static final List<TokenValidationRule> DATAPLANE_ACCESS_TOKEN_RULES = List.of( | |
| 52 | - (claimtoken, additional) -> Objects.equals(claimtoken.getStringClaim("sub"), claimtoken.getStringClaim("iss")) ? Result.success() : Result.failure("'sub' and 'iss' claim must be equal and non-null"), | |
| 53 | - (toVerify, additional) -> toVerify.getStringClaim(TOKEN_ID) != null ? Result.success() : Result.failure("%s claim must be present on token".formatted(TOKEN_ID)) | |
| 54 | - ); | |
| 55 | - private final TokenGenerationService tokenGenerationService; | |
| 56 | - private final AccessTokenDataStore accessTokenDataStore; | |
| 57 | - private final Monitor monitor; | |
| 58 | - private final Supplier<String> privateKeyIdSupplier; | |
| 59 | - private final Supplier<String> publicKeyIdSupplier; | |
| 60 | - private final TokenValidationService tokenValidationService; | |
| 61 | - private final PublicKeyResolver publicKeyResolver; | |
| 62 | - | |
| 63 | - public DefaultDataPlaneAccessTokenServiceImpl(TokenGenerationService tokenGenerationService, | |
| 64 | - AccessTokenDataStore accessTokenDataStore, | |
| 65 | - Monitor monitor, | |
| 66 | - Supplier<String> privateKeyIdSupplier, | |
| 67 | - Supplier<String> publicKeyIdSupplier, | |
| 68 | - TokenValidationService tokenValidationService, | |
| 69 | - PublicKeyResolver publicKeyResolver) { | |
| 70 | - this.tokenGenerationService = tokenGenerationService; | |
| 71 | - this.accessTokenDataStore = accessTokenDataStore; | |
| 72 | - this.monitor = monitor; | |
| 73 | - this.privateKeyIdSupplier = privateKeyIdSupplier; | |
| 74 | - this.publicKeyIdSupplier = publicKeyIdSupplier; | |
| 75 | - this.tokenValidationService = tokenValidationService; | |
| 76 | - this.publicKeyResolver = publicKeyResolver; | |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * Generates JWT tokens based on the {@link TokenParameters}. A representation of the claims and the data address is stored for subsequent use, using the token ID ("jti") | |
| 81 | - * as correlation id. | |
| 82 | - * | |
| 83 | - * @param parameters Headers and claims that are to be included in the token. If the claims do <em>not</em> contain a "jti" claim, one is generated randomly and inserted into the claims. | |
| 84 | - * @param backendDataAddress Information about the data resource for which the token is to be generated. May contain additional information about the token, such as an {@code authType} | |
| 85 | - * @param additionalTokenData Additional data that further characterizes the token, but should not be included in the resulting {@link TokenRepresentation}. Will be persisted in the {@link AccessTokenDataStore}. | |
| 86 | - * @return A token representation in serialized JWT format (signed). The JWTs "kid" header contains the ID of the public key that can be used to verify the token. | |
| 87 | - */ | |
| 88 | - @Override | |
| 89 | - public Result<TokenRepresentation> obtainToken(TokenParameters parameters, DataAddress backendDataAddress, Map<String, Object> additionalTokenData) { | |
| 90 | - Objects.requireNonNull(parameters, "TokenParameters must be non-null."); | |
| 91 | - Objects.requireNonNull(backendDataAddress, "DataAddress must be non-null."); | |
| 92 | - var claimDecorators = parameters.getClaims().entrySet().stream().map(e -> (TokenDecorator) claimDecorator -> claimDecorator.claims(e.getKey(), e.getValue())); | |
| 93 | - var headerDecorators = parameters.getHeaders().entrySet().stream().map(e -> (TokenDecorator) headerDecorator -> headerDecorator.header(e.getKey(), e.getValue())); | |
| 94 | - | |
| 95 | - var id = parameters.getStringClaim(TOKEN_ID); | |
| 96 | - var allDecorators = new ArrayList<>(Stream.concat(claimDecorators, headerDecorators).toList()); | |
| 97 | - var keyIdDecorator = new KeyIdDecorator(publicKeyIdSupplier.get()); | |
| 98 | - allDecorators.add(keyIdDecorator); | |
| 99 | - | |
| 100 | - // if there is no "jti" header on the token params, we'll assign a random one, and add it back to the decorators | |
| 101 | - if (id == null) { | |
| 102 | - monitor.info("No '%s' claim found on TokenParameters. Will generate a random one.".formatted(TOKEN_ID)); | |
| 103 | - id = UUID.randomUUID().toString(); | |
| 104 | - var tokenIdDecorator = new TokenIdDecorator(id); | |
| 105 | - allDecorators.add(tokenIdDecorator); | |
| 106 | - } | |
| 107 | - | |
| 108 | - var tokenResult = tokenGenerationService.generate(privateKeyIdSupplier.get(), allDecorators.toArray(new TokenDecorator[0])); | |
| 109 | - if (tokenResult.failed()) { | |
| 110 | - return tokenResult.mapEmpty(); | |
| 111 | - } | |
| 112 | - | |
| 113 | - // store a record of the token for future reference. We'll need that when we resolve the AccessTokenData later. | |
| 114 | - var claimToken = ClaimToken.Builder.newInstance().claims(parameters.getClaims()).build(); | |
| 115 | - var accessTokenData = new AccessTokenData(id, claimToken, backendDataAddress, additionalTokenData); | |
| 116 | - | |
| 117 | - var storeResult = accessTokenDataStore.store(accessTokenData); | |
| 118 | - var content = tokenResult.getContent(); | |
| 119 | - content.getAdditional().put(EDC_NAMESPACE + "authType", "bearer"); | |
| 120 | - return storeResult.succeeded() ? Result.success(content) : Result.failure(storeResult.getFailureMessages()); | |
| 121 | - } | |
| 122 | - | |
| 123 | - | |
| 124 | - @Override | |
| 125 | - public Result<AccessTokenData> resolve(String token) { | |
| 126 | - var validationResult = tokenValidationService.validate(token, publicKeyResolver, DATAPLANE_ACCESS_TOKEN_RULES); | |
| 127 | - if (validationResult.failed()) { | |
| 128 | - return validationResult.mapTo(); | |
| 129 | - } | |
| 130 | - var tokenId = validationResult.getContent().getStringClaim(TOKEN_ID); | |
| 131 | - var existingAccessToken = accessTokenDataStore.getById(tokenId); | |
| 132 | - | |
| 133 | - return existingAccessToken == null ? | |
| 134 | - Result.failure("AccessTokenData with ID '%s' does not exist.".formatted(tokenId)) : | |
| 135 | - Result.success(existingAccessToken); | |
| 136 | - } | |
| 137 | - | |
| 138 | - @Override | |
| 139 | - public Result<Void> revoke(String transferProcessId, String reason) { | |
| 140 | - | |
| 141 | - var query = QuerySpec.Builder.newInstance() | |
| 142 | - .filter(new Criterion("additionalProperties.process_id", "=", transferProcessId)) | |
| 143 | - .build(); | |
| 144 | - | |
| 145 | - var tokens = accessTokenDataStore.query(query); | |
| 146 | - return tokens.stream().map(this::deleteTokenData) | |
| 147 | - .reduce(Result::merge) | |
| 148 | - .orElseGet(() -> Result.failure("AccessTokenData associated to the transfer with ID '%s' does not exist.".formatted(transferProcessId))); | |
| 149 | - | |
| 150 | - } | |
| 151 | - | |
| 152 | - private Result<Void> deleteTokenData(AccessTokenData tokenData) { | |
| 153 | - var result = accessTokenDataStore.deleteById(tokenData.id()); | |
| 154 | - if (result.failed()) { | |
| 155 | - return Result.failure(result.getFailureDetail()); | |
| 156 | - } else { | |
| 157 | - return Result.success(); | |
| 158 | - } | |
| 159 | - } | |
| 160 | -} |
deleted core/data-plane/data-plane-core/src/main/java/org/eclipse/edc/connector/dataplane/framework/iam/TokenIdDecorator.java +0 −34
| @@ -1,34 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.dataplane.framework.iam; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.spi.iam.TokenParameters; | |
| 18 | -import org.eclipse.edc.token.spi.TokenDecorator; | |
| 19 | - | |
| 20 | -import static org.eclipse.edc.connector.dataplane.framework.iam.DefaultDataPlaneAccessTokenServiceImpl.TOKEN_ID; | |
| 21 | - | |
| 22 | -public class TokenIdDecorator implements TokenDecorator { | |
| 23 | - private final String tokenId; | |
| 24 | - | |
| 25 | - public TokenIdDecorator(String tokenId) { | |
| 26 | - this.tokenId = tokenId; | |
| 27 | - } | |
| 28 | - | |
| 29 | - @Override | |
| 30 | - public TokenParameters.Builder decorate(TokenParameters.Builder tokenParameters) { | |
| 31 | - tokenParameters.claims(TOKEN_ID, tokenId); | |
| 32 | - return tokenParameters; | |
| 33 | - } | |
| 34 | -} |
modified core/data-plane/data-plane-core/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension +0 −1
| @@ -1,3 +1,2 @@ | ||
| 1 | 1 | org.eclipse.edc.connector.dataplane.framework.DataPlaneFrameworkExtension |
| 2 | 2 | org.eclipse.edc.connector.dataplane.framework.DataPlaneDefaultServicesExtension |
| 3 | -org.eclipse.edc.connector.dataplane.framework.DataPlaneDefaultIamServicesExtension |
deleted core/data-plane/data-plane-core/src/test/java/org/eclipse/edc/connector/dataplane/framework/iam/DataPlaneAuthorizationServiceImplTest.java +0 −198
| @@ -1,198 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.dataplane.framework.iam; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.connector.dataplane.spi.AccessTokenData; | |
| 18 | -import org.eclipse.edc.connector.dataplane.spi.Endpoint; | |
| 19 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 20 | -import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 21 | -import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | |
| 22 | -import org.eclipse.edc.spi.iam.ClaimToken; | |
| 23 | -import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 24 | -import org.eclipse.edc.spi.result.Result; | |
| 25 | -import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 26 | -import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; | |
| 27 | -import org.eclipse.edc.spi.types.domain.transfer.FlowType; | |
| 28 | -import org.eclipse.edc.spi.types.domain.transfer.TransferType; | |
| 29 | -import org.junit.jupiter.api.BeforeEach; | |
| 30 | -import org.junit.jupiter.api.Test; | |
| 31 | -import org.mockito.ArgumentMatchers; | |
| 32 | - | |
| 33 | -import java.time.Clock; | |
| 34 | -import java.util.Map; | |
| 35 | -import java.util.Set; | |
| 36 | - | |
| 37 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 38 | -import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 39 | -import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.AUDIENCE; | |
| 40 | -import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.ISSUED_AT; | |
| 41 | -import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.ISSUER; | |
| 42 | -import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.JWT_ID; | |
| 43 | -import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.SUBJECT; | |
| 44 | -import static org.mockito.ArgumentMatchers.any; | |
| 45 | -import static org.mockito.ArgumentMatchers.anyMap; | |
| 46 | -import static org.mockito.ArgumentMatchers.argThat; | |
| 47 | -import static org.mockito.ArgumentMatchers.eq; | |
| 48 | -import static org.mockito.Mockito.mock; | |
| 49 | -import static org.mockito.Mockito.verify; | |
| 50 | -import static org.mockito.Mockito.verifyNoMoreInteractions; | |
| 51 | -import static org.mockito.Mockito.when; | |
| 52 | - | |
| 53 | -class DataPlaneAuthorizationServiceImplTest { | |
| 54 | - | |
| 55 | - public static final String OWN_PARTICIPANT_ID = "test-ownParticipantId"; | |
| 56 | - private final DataPlaneAccessTokenService accessTokenService = mock(); | |
| 57 | - private final PublicEndpointGeneratorService endpointGenerator = mock(); | |
| 58 | - private final DataPlaneAccessControlService accessControlService = mock(); | |
| 59 | - private final DataPlaneAuthorizationServiceImpl authorizationService = new DataPlaneAuthorizationServiceImpl(accessTokenService, endpointGenerator, accessControlService, OWN_PARTICIPANT_ID, Clock.systemUTC()); | |
| 60 | - | |
| 61 | - @BeforeEach | |
| 62 | - void setup() { | |
| 63 | - when(endpointGenerator.generateFor(any(), any())).thenReturn(Result.success(Endpoint.url("http://example.com"))); | |
| 64 | - } | |
| 65 | - | |
| 66 | - @Test | |
| 67 | - void createEndpointDataReference() { | |
| 68 | - when(accessTokenService.obtainToken(any(), any(), anyMap())).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("footoken").build())); | |
| 69 | - var startMsg = createStartMessage() | |
| 70 | - .transferType(new TransferType("DestinationType", FlowType.PULL)) | |
| 71 | - .build(); | |
| 72 | - | |
| 73 | - var result = authorizationService.createEndpointDataReference(startMsg); | |
| 74 | - assertThat(result).isSucceeded() | |
| 75 | - .satisfies(da -> { | |
| 76 | - assertThat(da.getType()).isEqualTo("https://w3id.org/idsa/v4.1/HTTP"); | |
| 77 | - assertThat(da.getStringProperty("endpoint")).isEqualTo("http://example.com"); | |
| 78 | - assertThat(da.getStringProperty("endpointType")).isEqualTo(da.getType()); | |
| 79 | - assertThat(da.getStringProperty("authorization")).isEqualTo("footoken"); | |
| 80 | - }); | |
| 81 | - | |
| 82 | - var requiredClaims = Set.of(JWT_ID, AUDIENCE, ISSUER, SUBJECT, ISSUED_AT); | |
| 83 | - verify(accessTokenService).obtainToken(ArgumentMatchers.assertArg(tp -> { | |
| 84 | - assertThat(tp.getClaims().keySet()).containsAll(requiredClaims); | |
| 85 | - assertThat(tp.getStringClaim(AUDIENCE)).isEqualTo(startMsg.getParticipantId()); | |
| 86 | - assertThat(tp.getStringClaim(ISSUER)).isEqualTo(OWN_PARTICIPANT_ID); | |
| 87 | - assertThat(tp.getStringClaim(SUBJECT)).isEqualTo(OWN_PARTICIPANT_ID); | |
| 88 | - assertThat(tp.getClaims().get(ISSUED_AT)).isNotNull(); | |
| 89 | - }), any(), argThat(m -> | |
| 90 | - m.containsKey("agreement_id") && | |
| 91 | - m.containsKey("participant_id") && | |
| 92 | - m.containsKey("asset_id") && | |
| 93 | - m.containsKey("process_id") && | |
| 94 | - m.containsKey("flow_type"))); | |
| 95 | - verify(endpointGenerator).generateFor("DestinationType", startMsg.getSourceDataAddress()); | |
| 96 | - } | |
| 97 | - | |
| 98 | - @Test | |
| 99 | - void createEndpointDataReference_withAuthType() { | |
| 100 | - when(accessTokenService.obtainToken(any(), any(), anyMap())).thenReturn(Result.success(TokenRepresentation.Builder.newInstance() | |
| 101 | - .token("footoken") | |
| 102 | - .additional(Map.of("authType", "bearer", "fizz", "buzz")) | |
| 103 | - .build())); | |
| 104 | - var startMsg = createStartMessage().build(); | |
| 105 | - | |
| 106 | - var result = authorizationService.createEndpointDataReference(startMsg); | |
| 107 | - assertThat(result).isSucceeded() | |
| 108 | - .satisfies(da -> { | |
| 109 | - assertThat(da.getType()).isEqualTo("https://w3id.org/idsa/v4.1/HTTP"); | |
| 110 | - assertThat(da.getStringProperty("endpoint")).isEqualTo("http://example.com"); | |
| 111 | - assertThat(da.getStringProperty("authorization")).isEqualTo("footoken"); | |
| 112 | - assertThat(da.getStringProperty("authType")).isEqualTo("bearer"); | |
| 113 | - assertThat(da.getStringProperty("fizz")).isEqualTo("buzz"); | |
| 114 | - }); | |
| 115 | - } | |
| 116 | - | |
| 117 | - @Test | |
| 118 | - void createEndpointDataReference_tokenServiceFails() { | |
| 119 | - when(accessTokenService.obtainToken(any(), any(), anyMap())).thenReturn(Result.failure("test-failure")); | |
| 120 | - var startMsg = createStartMessage().build(); | |
| 121 | - assertThat(authorizationService.createEndpointDataReference(startMsg)).isFailed() | |
| 122 | - .detail().isEqualTo("test-failure"); | |
| 123 | - } | |
| 124 | - | |
| 125 | - @Test | |
| 126 | - void authorize() { | |
| 127 | - var claimToken = ClaimToken.Builder.newInstance().build(); | |
| 128 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 129 | - when(accessTokenService.resolve(eq("foo-token"))).thenReturn(Result.success(new AccessTokenData("test-id", | |
| 130 | - claimToken, | |
| 131 | - address))); | |
| 132 | - when(accessControlService.checkAccess(eq(claimToken), eq(address), any(), anyMap())).thenReturn(Result.success()); | |
| 133 | - | |
| 134 | - assertThat(authorizationService.authorize("foo-token", Map.of())).isSucceeded(); | |
| 135 | - verify(accessTokenService).resolve(eq("foo-token")); | |
| 136 | - verify(accessControlService).checkAccess(eq(claimToken), eq(address), any(), anyMap()); | |
| 137 | - verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 138 | - } | |
| 139 | - | |
| 140 | - @Test | |
| 141 | - void authorize_tokenNotFound() { | |
| 142 | - when(accessTokenService.resolve(eq("foo-token"))).thenReturn(Result.failure("not found")); | |
| 143 | - | |
| 144 | - assertThat(authorizationService.authorize("foo-token", Map.of())).isFailed() | |
| 145 | - .detail().isEqualTo("not found"); | |
| 146 | - verify(accessTokenService).resolve(eq("foo-token")); | |
| 147 | - verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 148 | - } | |
| 149 | - | |
| 150 | - @Test | |
| 151 | - void authorize_accessNotGranted() { | |
| 152 | - var claimToken = ClaimToken.Builder.newInstance().build(); | |
| 153 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 154 | - when(accessTokenService.resolve(eq("foo-token"))).thenReturn(Result.success(new AccessTokenData("test-id", | |
| 155 | - claimToken, | |
| 156 | - address))); | |
| 157 | - when(accessControlService.checkAccess(eq(claimToken), eq(address), any(), anyMap())).thenReturn(Result.failure("not granted")); | |
| 158 | - | |
| 159 | - assertThat(authorizationService.authorize("foo-token", Map.of())).isFailed() | |
| 160 | - .detail().isEqualTo("not granted"); | |
| 161 | - verify(accessTokenService).resolve(eq("foo-token")); | |
| 162 | - verify(accessControlService).checkAccess(eq(claimToken), eq(address), any(), anyMap()); | |
| 163 | - verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 164 | - } | |
| 165 | - | |
| 166 | - @Test | |
| 167 | - void revoke() { | |
| 168 | - when(accessTokenService.revoke(eq("id"), eq("reason"))).thenReturn(Result.success()); | |
| 169 | - | |
| 170 | - assertThat(authorizationService.revokeEndpointDataReference("id", "reason")).isSucceeded(); | |
| 171 | - | |
| 172 | - verify(accessTokenService).revoke(eq("id"), eq("reason")); | |
| 173 | - verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 174 | - } | |
| 175 | - | |
| 176 | - @Test | |
| 177 | - void revoke_error() { | |
| 178 | - when(accessTokenService.revoke(eq("id"), eq("reason"))).thenReturn(Result.failure("failure")); | |
| 179 | - | |
| 180 | - assertThat(authorizationService.revokeEndpointDataReference("id", "reason")).isFailed() | |
| 181 | - .detail().contains("failure"); | |
| 182 | - | |
| 183 | - verify(accessTokenService).revoke(eq("id"), eq("reason")); | |
| 184 | - verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 185 | - } | |
| 186 | - | |
| 187 | - private DataFlowStartMessage.Builder createStartMessage() { | |
| 188 | - return DataFlowStartMessage.Builder.newInstance() | |
| 189 | - .processId("test-processid") | |
| 190 | - .transferType(new TransferType("DestinationType", FlowType.PULL)) | |
| 191 | - .agreementId("test-agreementid") | |
| 192 | - .participantId("test-participantid") | |
| 193 | - .assetId("test-assetid") | |
| 194 | - .sourceDataAddress(DataAddress.Builder.newInstance().type("test-src").build()) | |
| 195 | - .destinationDataAddress(DataAddress.Builder.newInstance().type("test-dest").build()) | |
| 196 | - .properties(Map.of("foo", "bar", "fizz", "buzz")); | |
| 197 | - } | |
| 198 | -} |
deleted core/data-plane/data-plane-core/src/test/java/org/eclipse/edc/connector/dataplane/framework/iam/DefaultDataPlaneAccessTokenServiceImplTest.java +0 −241
| @@ -1,241 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.dataplane.framework.iam; | |
| 16 | - | |
| 17 | -import org.assertj.core.api.Assertions; | |
| 18 | -import org.eclipse.edc.connector.dataplane.spi.AccessTokenData; | |
| 19 | -import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; | |
| 20 | -import org.eclipse.edc.spi.iam.ClaimToken; | |
| 21 | -import org.eclipse.edc.spi.iam.TokenParameters; | |
| 22 | -import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 23 | -import org.eclipse.edc.spi.query.Criterion; | |
| 24 | -import org.eclipse.edc.spi.query.QuerySpec; | |
| 25 | -import org.eclipse.edc.spi.result.Result; | |
| 26 | -import org.eclipse.edc.spi.result.StoreResult; | |
| 27 | -import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 28 | -import org.eclipse.edc.token.spi.TokenDecorator; | |
| 29 | -import org.eclipse.edc.token.spi.TokenGenerationService; | |
| 30 | -import org.eclipse.edc.token.spi.TokenValidationService; | |
| 31 | -import org.junit.jupiter.api.Test; | |
| 32 | - | |
| 33 | -import java.util.List; | |
| 34 | -import java.util.Map; | |
| 35 | -import java.util.regex.Pattern; | |
| 36 | - | |
| 37 | -import static org.assertj.core.api.Assertions.assertThatThrownBy; | |
| 38 | -import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 39 | -import static org.mockito.ArgumentMatchers.any; | |
| 40 | -import static org.mockito.ArgumentMatchers.anyList; | |
| 41 | -import static org.mockito.ArgumentMatchers.anyString; | |
| 42 | -import static org.mockito.ArgumentMatchers.argThat; | |
| 43 | -import static org.mockito.ArgumentMatchers.eq; | |
| 44 | -import static org.mockito.Mockito.mock; | |
| 45 | -import static org.mockito.Mockito.never; | |
| 46 | -import static org.mockito.Mockito.verify; | |
| 47 | -import static org.mockito.Mockito.verifyNoInteractions; | |
| 48 | -import static org.mockito.Mockito.verifyNoMoreInteractions; | |
| 49 | -import static org.mockito.Mockito.when; | |
| 50 | - | |
| 51 | -class DefaultDataPlaneAccessTokenServiceImplTest { | |
| 52 | - | |
| 53 | - private static final Pattern UUID_PATTERN = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); | |
| 54 | - private final AccessTokenDataStore store = mock(); | |
| 55 | - private final TokenGenerationService tokenGenService = mock(); | |
| 56 | - private final TokenValidationService tokenValidationService = mock(); | |
| 57 | - private final DefaultDataPlaneAccessTokenServiceImpl accessTokenService = new DefaultDataPlaneAccessTokenServiceImpl(tokenGenService, | |
| 58 | - store, mock(), mock(), mock(), tokenValidationService, mock()); | |
| 59 | - | |
| 60 | - @Test | |
| 61 | - void obtainToken() { | |
| 62 | - var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 63 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 64 | - | |
| 65 | - when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 66 | - when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.success()); | |
| 67 | - | |
| 68 | - var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 69 | - assertThat(result).isSucceeded().extracting(TokenRepresentation::getToken).isEqualTo("foo-token"); | |
| 70 | - | |
| 71 | - verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 72 | - verify(store).store(any(AccessTokenData.class)); | |
| 73 | - } | |
| 74 | - | |
| 75 | - @Test | |
| 76 | - void obtainToken_withAdditionalProperties() { | |
| 77 | - var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 78 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 79 | - | |
| 80 | - when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 81 | - when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.success()); | |
| 82 | - | |
| 83 | - var result = accessTokenService.obtainToken(params, address, Map.of("foo", "bar")); | |
| 84 | - assertThat(result).isSucceeded().extracting(TokenRepresentation::getToken).isEqualTo("foo-token"); | |
| 85 | - | |
| 86 | - verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 87 | - verify(store).store(argThat(accessTokenData -> accessTokenData.additionalProperties().get("foo").equals("bar"))); | |
| 88 | - } | |
| 89 | - | |
| 90 | - @Test | |
| 91 | - void obtainToken_invalidParams() { | |
| 92 | - assertThatThrownBy(() -> accessTokenService.obtainToken(null, DataAddress.Builder.newInstance().type("foo").build(), Map.of())) | |
| 93 | - .isInstanceOf(NullPointerException.class); | |
| 94 | - assertThatThrownBy(() -> accessTokenService.obtainToken(TokenParameters.Builder.newInstance().build(), null, Map.of())) | |
| 95 | - .isInstanceOf(NullPointerException.class); | |
| 96 | - | |
| 97 | - } | |
| 98 | - | |
| 99 | - @Test | |
| 100 | - void obtainToken_noTokenId() { | |
| 101 | - var params = TokenParameters.Builder.newInstance().claims("foo", "bar")/* missing: .claims("jti", "baz")*/.header("qux", "quz").build(); | |
| 102 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 103 | - | |
| 104 | - when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 105 | - when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.success()); | |
| 106 | - | |
| 107 | - var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 108 | - assertThat(result).isSucceeded().extracting(TokenRepresentation::getToken).isEqualTo("foo-token"); | |
| 109 | - | |
| 110 | - verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 111 | - verify(store).store(argThat(accessTokenData -> UUID_PATTERN.matcher(accessTokenData.id()).matches())); | |
| 112 | - } | |
| 113 | - | |
| 114 | - @Test | |
| 115 | - void obtainToken_creationFails() { | |
| 116 | - var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 117 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 118 | - | |
| 119 | - when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.failure("test failure")); | |
| 120 | - | |
| 121 | - var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 122 | - assertThat(result).isFailed().detail().isEqualTo("test failure"); | |
| 123 | - | |
| 124 | - verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 125 | - verifyNoMoreInteractions(store); | |
| 126 | - } | |
| 127 | - | |
| 128 | - @Test | |
| 129 | - void obtainToken_storingFails() { | |
| 130 | - var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 131 | - var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 132 | - | |
| 133 | - when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 134 | - when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.alreadyExists("test failure")); | |
| 135 | - | |
| 136 | - var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 137 | - assertThat(result).isFailed().detail().isEqualTo("test failure"); | |
| 138 | - | |
| 139 | - verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 140 | - verify(store).store(any(AccessTokenData.class)); | |
| 141 | - } | |
| 142 | - | |
| 143 | - @Test | |
| 144 | - void resolve() { | |
| 145 | - var tokenId = "test-id"; | |
| 146 | - var claimToken = ClaimToken.Builder.newInstance().claim("jti", tokenId).build(); | |
| 147 | - when(tokenValidationService.validate(anyString(), any(), anyList())) | |
| 148 | - .thenReturn(Result.success(claimToken)); | |
| 149 | - when(store.getById(eq(tokenId))).thenReturn(new AccessTokenData(tokenId, ClaimToken.Builder.newInstance().build(), | |
| 150 | - DataAddress.Builder.newInstance().type("test-type").build())); | |
| 151 | - | |
| 152 | - var result = accessTokenService.resolve("some-jwt"); | |
| 153 | - assertThat(result).isSucceeded() | |
| 154 | - .satisfies(atd -> Assertions.assertThat(atd.id()).isEqualTo(tokenId)); | |
| 155 | - verify(tokenValidationService).validate(eq("some-jwt"), any(), anyList()); | |
| 156 | - verify(store).getById(eq(tokenId)); | |
| 157 | - } | |
| 158 | - | |
| 159 | - @Test | |
| 160 | - void resolve_whenValidationFails() { | |
| 161 | - var tokenId = "test-id"; | |
| 162 | - var claimToken = ClaimToken.Builder.newInstance().claim("jti", tokenId).build(); | |
| 163 | - when(tokenValidationService.validate(anyString(), any(), anyList())) | |
| 164 | - .thenReturn(Result.failure("test-failure")); | |
| 165 | - | |
| 166 | - var result = accessTokenService.resolve("some-jwt"); | |
| 167 | - assertThat(result).isFailed() | |
| 168 | - .detail().isEqualTo("test-failure"); | |
| 169 | - verify(tokenValidationService).validate(eq("some-jwt"), any(), anyList()); | |
| 170 | - verifyNoInteractions(store); | |
| 171 | - } | |
| 172 | - | |
| 173 | - @Test | |
| 174 | - void resolve_whenTokenIdNotFound() { | |
| 175 | - var tokenId = "test-id"; | |
| 176 | - var claimToken = ClaimToken.Builder.newInstance().claim("jti", tokenId).build(); | |
| 177 | - when(tokenValidationService.validate(anyString(), any(), anyList())) | |
| 178 | - .thenReturn(Result.success(claimToken)); | |
| 179 | - when(store.getById(eq(tokenId))).thenReturn(null); | |
| 180 | - | |
| 181 | - var result = accessTokenService.resolve("some-jwt"); | |
| 182 | - assertThat(result).isFailed() | |
| 183 | - .detail().isEqualTo("AccessTokenData with ID 'test-id' does not exist."); | |
| 184 | - verify(tokenValidationService).validate(eq("some-jwt"), any(), anyList()); | |
| 185 | - verify(store).getById(eq(tokenId)); | |
| 186 | - } | |
| 187 | - | |
| 188 | - | |
| 189 | - @Test | |
| 190 | - void revoke() { | |
| 191 | - var tokenId = "test-id"; | |
| 192 | - var processId = "tp-id"; | |
| 193 | - | |
| 194 | - var querySpec = QuerySpec.Builder.newInstance().filter(new Criterion("additionalProperties.process_id", "=", processId)).build(); | |
| 195 | - | |
| 196 | - var tokenData = new AccessTokenData(tokenId, ClaimToken.Builder.newInstance().build(), | |
| 197 | - DataAddress.Builder.newInstance().type("test-type").build()); | |
| 198 | - | |
| 199 | - when(store.query(querySpec)).thenReturn(List.of(tokenData)); | |
| 200 | - when(store.deleteById(tokenId)).thenReturn(StoreResult.success()); | |
| 201 | - | |
| 202 | - var result = accessTokenService.revoke("tp-id", "reason"); | |
| 203 | - assertThat(result).isSucceeded(); | |
| 204 | - | |
| 205 | - verify(store).deleteById(eq(tokenId)); | |
| 206 | - | |
| 207 | - } | |
| 208 | - | |
| 209 | - @Test | |
| 210 | - void revoke_storeError() { | |
| 211 | - var tokenId = "test-id"; | |
| 212 | - var processId = "tp-id"; | |
| 213 | - | |
| 214 | - var querySpec = QuerySpec.Builder.newInstance().filter(new Criterion("additionalProperties.process_id", "=", processId)).build(); | |
| 215 | - | |
| 216 | - var tokenData = new AccessTokenData(tokenId, ClaimToken.Builder.newInstance().build(), | |
| 217 | - DataAddress.Builder.newInstance().type("test-type").build()); | |
| 218 | - | |
| 219 | - when(store.query(querySpec)).thenReturn(List.of(tokenData)); | |
| 220 | - when(store.deleteById(tokenId)).thenReturn(StoreResult.generalError("storeError")); | |
| 221 | - | |
| 222 | - var result = accessTokenService.revoke("tp-id", "reason"); | |
| 223 | - assertThat(result).isFailed().detail().contains("storeError"); | |
| 224 | - | |
| 225 | - verify(store).deleteById(eq(tokenId)); | |
| 226 | - } | |
| 227 | - | |
| 228 | - @Test | |
| 229 | - void revoke_notTokensFound() { | |
| 230 | - var processId = "tp-id"; | |
| 231 | - var querySpec = QuerySpec.Builder.newInstance().filter(new Criterion("additionalProperties.process_id", "=", processId)).build(); | |
| 232 | - | |
| 233 | - when(store.query(querySpec)).thenReturn(List.of()); | |
| 234 | - | |
| 235 | - var result = accessTokenService.revoke("tp-id", "reason"); | |
| 236 | - assertThat(result).isFailed().detail().contains("AccessTokenData associated to the transfer with ID"); | |
| 237 | - | |
| 238 | - verify(store, never()).deleteById(any()); | |
| 239 | - | |
| 240 | - } | |
| 241 | -} |
added extensions/common/sql/sql-core/src/test/java/org/eclipse/edc/sql/configuration/DataSourceNameTest.java +63 −0
| @@ -0,0 +1,63 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.sql.configuration; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.spi.monitor.Monitor; | |
| 18 | +import org.eclipse.edc.spi.system.configuration.ConfigFactory; | |
| 19 | +import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 20 | +import org.junit.jupiter.api.Test; | |
| 21 | + | |
| 22 | +import java.util.Map; | |
| 23 | + | |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | +import static org.mockito.ArgumentMatchers.anyString; | |
| 26 | +import static org.mockito.Mockito.mock; | |
| 27 | +import static org.mockito.Mockito.verify; | |
| 28 | +import static org.mockito.Mockito.verifyNoInteractions; | |
| 29 | + | |
| 30 | +class DataSourceNameTest { | |
| 31 | + | |
| 32 | + private final Monitor monitor = mock(); | |
| 33 | + | |
| 34 | + @Test | |
| 35 | + void shouldReturnDefaultDatasource_whenNoConfiguration() { | |
| 36 | + var config = ConfigFactory.empty(); | |
| 37 | + | |
| 38 | + var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 39 | + | |
| 40 | + assertThat(datasourceName).isEqualTo(DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 41 | + verifyNoInteractions(monitor); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Test | |
| 45 | + void shouldReturnDatasource_whenIsInConfiguration() { | |
| 46 | + var config = ConfigFactory.fromMap(Map.of("key", "value")); | |
| 47 | + | |
| 48 | + var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 49 | + | |
| 50 | + assertThat(datasourceName).isEqualTo("value"); | |
| 51 | + verifyNoInteractions(monitor); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Test | |
| 55 | + void shouldLogWarning_whenDeprecatedKeyIsUsed() { | |
| 56 | + var config = ConfigFactory.fromMap(Map.of("deprecatedKey", "value")); | |
| 57 | + | |
| 58 | + var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 59 | + | |
| 60 | + assertThat(datasourceName).isEqualTo("value"); | |
| 61 | + verify(monitor).warning(anyString()); | |
| 62 | + } | |
| 63 | +} |
modified extensions/control-plane/api/control-plane-api-client/build.gradle.kts +1 −0
| @@ -31,6 +31,7 @@ | ||
| 31 | 31 | testImplementation(project(":extensions:control-plane:api:control-plane-api")) |
| 32 | 32 | testImplementation(project(":extensions:common:api:control-api-configuration")) |
| 33 | 33 | testImplementation(project(":extensions:common:auth:auth-tokenbased")) |
| 34 | + testImplementation(project(":extensions:common:http")) | |
| 34 | 35 | testImplementation(project(":extensions:common:json-ld")) |
| 35 | 36 | testImplementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-client")) |
| 36 | 37 | testImplementation(testFixtures(project(":core:common:lib:http-lib"))) |
modified extensions/control-plane/api/control-plane-api-client/src/test/java/org/eclipse/edc/connector/controlplane/api/client/transferprocess/TransferProcessHttpClientIntegrationTest.java +1 −3
| @@ -82,9 +82,7 @@ | ||
| 82 | 82 | "web.http.control.port", String.valueOf(port), |
| 83 | 83 | "web.http.control.path", "/control", |
| 84 | 84 | "edc.core.retry.retries.max", "0", |
| 85 | - "edc.dataplane.send.retry.limit", "0", | |
| 86 | - "edc.transfer.proxy.token.verifier.publickey.alias", "alias", | |
| 87 | - "edc.transfer.proxy.token.signer.privatekey.alias", "alias" | |
| 85 | + "edc.dataplane.send.retry.limit", "0" | |
| 88 | 86 | )); |
| 89 | 87 | |
| 90 | 88 | extension.registerSystemExtension(ServiceExtension.class, new TransferServiceMockExtension(service)); |
modified extensions/data-plane/data-plane-http/src/test/java/org/eclipse/edc/connector/dataplane/http/DataPlaneHttpExtensionTest.java +0 −5
| @@ -30,7 +30,6 @@ | ||
| 30 | 30 | import org.mockserver.integration.ClientAndServer; |
| 31 | 31 | import org.mockserver.model.HttpResponse; |
| 32 | 32 | |
| 33 | -import java.util.Map; | |
| 34 | 33 | import java.util.UUID; |
| 35 | 34 | |
| 36 | 35 | import static java.util.Collections.emptyMap; |
| @@ -52,10 +51,6 @@ | ||
| 52 | 51 | |
| 53 | 52 | @RegisterExtension |
| 54 | 53 | private static final RuntimeExtension RUNTIME = new RuntimePerClassExtension() |
| 55 | - .setConfiguration(Map.of( | |
| 56 | - "edc.transfer.proxy.token.verifier.publickey.alias", "alias", | |
| 57 | - "edc.transfer.proxy.token.signer.privatekey.alias", "alias" | |
| 58 | - )) | |
| 59 | 54 | .registerServiceMock(TransferProcessApiClient.class, mock()); |
| 60 | 55 | |
| 61 | 56 | @BeforeAll |
added extensions/data-plane/data-plane-iam/build.gradle.kts +30 −0
| @@ -0,0 +1,30 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2022 Contributors to the Eclipse Foundation | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Contributors to the Eclipse Foundation - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +plugins { | |
| 16 | + `java-library` | |
| 17 | +} | |
| 18 | + | |
| 19 | +dependencies { | |
| 20 | + api(project(":spi:common:jwt-spi")) | |
| 21 | + api(project(":spi:common:jwt-signer-spi")) | |
| 22 | + api(project(":spi:common:token-spi")) | |
| 23 | + api(project(":spi:data-plane:data-plane-spi")) | |
| 24 | + | |
| 25 | + implementation(project(":core:common:token-core")) | |
| 26 | + | |
| 27 | + testImplementation(project(":core:common:junit")) | |
| 28 | +} | |
| 29 | + | |
| 30 | + |
added extensions/data-plane/data-plane-iam/src/main/java/org/eclipse/edc/connector/dataplane/iam/DataPlaneIamDefaultServicesExtension.java +75 −0
| @@ -0,0 +1,75 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.connector.dataplane.iam.service.DefaultDataPlaneAccessTokenServiceImpl; | |
| 18 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 19 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 20 | +import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; | |
| 21 | +import org.eclipse.edc.jwt.signer.spi.JwsSignerProvider; | |
| 22 | +import org.eclipse.edc.keys.spi.LocalPublicKeyService; | |
| 23 | +import org.eclipse.edc.runtime.metamodel.annotation.Extension; | |
| 24 | +import org.eclipse.edc.runtime.metamodel.annotation.Inject; | |
| 25 | +import org.eclipse.edc.runtime.metamodel.annotation.Provider; | |
| 26 | +import org.eclipse.edc.runtime.metamodel.annotation.Setting; | |
| 27 | +import org.eclipse.edc.spi.result.Result; | |
| 28 | +import org.eclipse.edc.spi.system.ServiceExtension; | |
| 29 | +import org.eclipse.edc.spi.system.ServiceExtensionContext; | |
| 30 | +import org.eclipse.edc.token.JwtGenerationService; | |
| 31 | +import org.eclipse.edc.token.spi.TokenValidationService; | |
| 32 | + | |
| 33 | +@Extension(value = DataPlaneIamDefaultServicesExtension.NAME) | |
| 34 | +public class DataPlaneIamDefaultServicesExtension implements ServiceExtension { | |
| 35 | + | |
| 36 | + public static final String NAME = "Data Plane Default IAM Services"; | |
| 37 | + | |
| 38 | + @Setting(value = "Alias of private key used for signing tokens, retrieved from private key resolver") | |
| 39 | + public static final String TOKEN_SIGNER_PRIVATE_KEY_ALIAS = "edc.transfer.proxy.token.signer.privatekey.alias"; | |
| 40 | + @Setting(value = "Alias of public key used for verifying the tokens, retrieved from the vault") | |
| 41 | + public static final String TOKEN_VERIFIER_PUBLIC_KEY_ALIAS = "edc.transfer.proxy.token.verifier.publickey.alias"; | |
| 42 | + | |
| 43 | + @Inject | |
| 44 | + private AccessTokenDataStore accessTokenDataStore; | |
| 45 | + @Inject | |
| 46 | + private TokenValidationService tokenValidationService; | |
| 47 | + @Inject | |
| 48 | + private LocalPublicKeyService localPublicKeyService; | |
| 49 | + @Inject | |
| 50 | + private JwsSignerProvider jwsSignerProvider; | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public String name() { | |
| 54 | + return NAME; | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Provider(isDefault = true) | |
| 58 | + public DataPlaneAccessControlService defaultAccessControlService(ServiceExtensionContext context) { | |
| 59 | + context.getMonitor().debug("DataPlane Access Control: default implementation is used, will always return Result.success()"); | |
| 60 | + return (claimToken, address, requestData, additionalData) -> Result.success(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Provider(isDefault = true) | |
| 64 | + public DataPlaneAccessTokenService defaultAccessTokenService(ServiceExtensionContext context) { | |
| 65 | + var tokenVerifierPublicKeyAlias = context.getConfig().getString(TOKEN_VERIFIER_PUBLIC_KEY_ALIAS); | |
| 66 | + var tokenSignerPrivateKeyAlias = context.getConfig().getString(TOKEN_SIGNER_PRIVATE_KEY_ALIAS); | |
| 67 | + var monitor = context.getMonitor().withPrefix("DataPlane IAM"); | |
| 68 | + return new DefaultDataPlaneAccessTokenServiceImpl(new JwtGenerationService(jwsSignerProvider), | |
| 69 | + accessTokenDataStore, monitor, | |
| 70 | + () -> tokenSignerPrivateKeyAlias, | |
| 71 | + () -> tokenVerifierPublicKeyAlias, | |
| 72 | + tokenValidationService, localPublicKeyService); | |
| 73 | + } | |
| 74 | + | |
| 75 | +} |
added extensions/data-plane/data-plane-iam/src/main/java/org/eclipse/edc/connector/dataplane/iam/DataPlaneIamExtension.java +54 −0
| @@ -0,0 +1,54 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Contributors to the Eclipse Foundation | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Contributors to the Eclipse Foundation - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.connector.dataplane.iam.service.DataPlaneAuthorizationServiceImpl; | |
| 18 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 19 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 20 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService; | |
| 21 | +import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | |
| 22 | +import org.eclipse.edc.runtime.metamodel.annotation.Extension; | |
| 23 | +import org.eclipse.edc.runtime.metamodel.annotation.Inject; | |
| 24 | +import org.eclipse.edc.runtime.metamodel.annotation.Provider; | |
| 25 | +import org.eclipse.edc.spi.system.ServiceExtension; | |
| 26 | +import org.eclipse.edc.spi.system.ServiceExtensionContext; | |
| 27 | + | |
| 28 | +import java.time.Clock; | |
| 29 | + | |
| 30 | +@Extension(value = DataPlaneIamExtension.NAME) | |
| 31 | +public class DataPlaneIamExtension implements ServiceExtension { | |
| 32 | + | |
| 33 | + public static final String NAME = "Data Plane IAM"; | |
| 34 | + | |
| 35 | + @Inject | |
| 36 | + private Clock clock; | |
| 37 | + @Inject | |
| 38 | + private DataPlaneAccessTokenService accessTokenService; | |
| 39 | + @Inject | |
| 40 | + private DataPlaneAccessControlService accessControlService; | |
| 41 | + @Inject | |
| 42 | + private PublicEndpointGeneratorService endpointGenerator; | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public String name() { | |
| 46 | + return NAME; | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Provider | |
| 50 | + public DataPlaneAuthorizationService authorizationService(ServiceExtensionContext context) { | |
| 51 | + return new DataPlaneAuthorizationServiceImpl(accessTokenService, endpointGenerator, accessControlService, context.getParticipantId(), clock); | |
| 52 | + } | |
| 53 | + | |
| 54 | +} |
added extensions/data-plane/data-plane-iam/src/main/java/org/eclipse/edc/connector/dataplane/iam/service/DataPlaneAuthorizationServiceImpl.java +113 −0
| @@ -0,0 +1,113 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam.service; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.connector.dataplane.spi.Endpoint; | |
| 18 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 19 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 20 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService; | |
| 21 | +import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | |
| 22 | +import org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames; | |
| 23 | +import org.eclipse.edc.spi.iam.TokenParameters; | |
| 24 | +import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 25 | +import org.eclipse.edc.spi.result.Result; | |
| 26 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 27 | +import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; | |
| 28 | + | |
| 29 | +import java.time.Clock; | |
| 30 | +import java.util.HashMap; | |
| 31 | +import java.util.Map; | |
| 32 | +import java.util.UUID; | |
| 33 | + | |
| 34 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 35 | +import static org.eclipse.edc.spi.result.Result.success; | |
| 36 | + | |
| 37 | +public class DataPlaneAuthorizationServiceImpl implements DataPlaneAuthorizationService { | |
| 38 | + public static final String PROPERTY_AGREEMENT_ID = "agreement_id"; | |
| 39 | + public static final String PROPERTY_ASSET_ID = "asset_id"; | |
| 40 | + public static final String PROPERTY_PROCESS_ID = "process_id"; | |
| 41 | + public static final String PROPERTY_FLOW_TYPE = "flow_type"; | |
| 42 | + private static final String PROPERTY_PARTICIPANT_ID = "participant_id"; | |
| 43 | + private final DataPlaneAccessTokenService accessTokenService; | |
| 44 | + private final PublicEndpointGeneratorService endpointGenerator; | |
| 45 | + private final DataPlaneAccessControlService accessControlService; | |
| 46 | + private final String ownParticipantId; | |
| 47 | + private final Clock clock; | |
| 48 | + | |
| 49 | + public DataPlaneAuthorizationServiceImpl(DataPlaneAccessTokenService accessTokenService, | |
| 50 | + PublicEndpointGeneratorService endpointGenerator, | |
| 51 | + DataPlaneAccessControlService accessControlService, | |
| 52 | + String ownParticipantId, | |
| 53 | + Clock clock) { | |
| 54 | + this.accessTokenService = accessTokenService; | |
| 55 | + this.endpointGenerator = endpointGenerator; | |
| 56 | + this.accessControlService = accessControlService; | |
| 57 | + this.ownParticipantId = ownParticipantId; | |
| 58 | + this.clock = clock; | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public Result<DataAddress> createEndpointDataReference(DataFlowStartMessage message) { | |
| 63 | + return endpointGenerator.generateFor(message.getTransferType().destinationType(), message.getSourceDataAddress()) | |
| 64 | + .compose(endpoint -> { | |
| 65 | + var additionalProperties = new HashMap<String, Object>(message.getProperties()); | |
| 66 | + additionalProperties.put(PROPERTY_AGREEMENT_ID, message.getAgreementId()); | |
| 67 | + additionalProperties.put(PROPERTY_ASSET_ID, message.getAssetId()); | |
| 68 | + additionalProperties.put(PROPERTY_PROCESS_ID, message.getProcessId()); | |
| 69 | + additionalProperties.put(PROPERTY_FLOW_TYPE, message.getFlowType().toString()); | |
| 70 | + additionalProperties.put(PROPERTY_PARTICIPANT_ID, message.getParticipantId()); | |
| 71 | + | |
| 72 | + return accessTokenService.obtainToken(createTokenParams(message), message.getSourceDataAddress(), additionalProperties) | |
| 73 | + .compose(tokenRepresentation -> createDataAddress(tokenRepresentation, endpoint)); | |
| 74 | + } | |
| 75 | + ); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Override | |
| 79 | + public Result<DataAddress> authorize(String token, Map<String, Object> requestData) { | |
| 80 | + return accessTokenService.resolve(token) | |
| 81 | + .compose(atd -> accessControlService.checkAccess(atd.claimToken(), atd.dataAddress(), requestData, atd.additionalProperties()) | |
| 82 | + .map(u -> atd.dataAddress()) | |
| 83 | + ); | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public Result<Void> revokeEndpointDataReference(String transferProcessId, String reason) { | |
| 88 | + return accessTokenService.revoke(transferProcessId, reason); | |
| 89 | + } | |
| 90 | + | |
| 91 | + private Result<DataAddress> createDataAddress(TokenRepresentation tokenRepresentation, Endpoint publicEndpoint) { | |
| 92 | + var address = DataAddress.Builder.newInstance() | |
| 93 | + .type(publicEndpoint.endpointType()) | |
| 94 | + .property(EDC_NAMESPACE + "endpoint", publicEndpoint.endpoint()) | |
| 95 | + .property(EDC_NAMESPACE + "endpointType", publicEndpoint.endpointType()) //this is duplicated in the type() field, but will make serialization easier | |
| 96 | + .properties(tokenRepresentation.getAdditional()) // would contain the "authType = bearer" entry | |
| 97 | + .property(EDC_NAMESPACE + "authorization", tokenRepresentation.getToken()) | |
| 98 | + .build(); | |
| 99 | + | |
| 100 | + return success(address); | |
| 101 | + } | |
| 102 | + | |
| 103 | + private TokenParameters createTokenParams(DataFlowStartMessage message) { | |
| 104 | + return TokenParameters.Builder.newInstance() | |
| 105 | + .claims(JwtRegisteredClaimNames.JWT_ID, UUID.randomUUID().toString()) | |
| 106 | + .claims(JwtRegisteredClaimNames.AUDIENCE, message.getParticipantId()) | |
| 107 | + .claims(JwtRegisteredClaimNames.ISSUER, ownParticipantId) | |
| 108 | + .claims(JwtRegisteredClaimNames.SUBJECT, ownParticipantId) | |
| 109 | + .claims(JwtRegisteredClaimNames.ISSUED_AT, clock.instant().toEpochMilli()) // todo: milli or second? | |
| 110 | + .build(); | |
| 111 | + } | |
| 112 | + | |
| 113 | +} |
added extensions/data-plane/data-plane-iam/src/main/java/org/eclipse/edc/connector/dataplane/iam/service/DefaultDataPlaneAccessTokenServiceImpl.java +159 −0
| @@ -0,0 +1,159 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam.service; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.connector.dataplane.spi.AccessTokenData; | |
| 18 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 19 | +import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; | |
| 20 | +import org.eclipse.edc.keys.spi.PublicKeyResolver; | |
| 21 | +import org.eclipse.edc.spi.iam.ClaimToken; | |
| 22 | +import org.eclipse.edc.spi.iam.TokenParameters; | |
| 23 | +import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 24 | +import org.eclipse.edc.spi.monitor.Monitor; | |
| 25 | +import org.eclipse.edc.spi.query.Criterion; | |
| 26 | +import org.eclipse.edc.spi.query.QuerySpec; | |
| 27 | +import org.eclipse.edc.spi.result.Result; | |
| 28 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 29 | +import org.eclipse.edc.token.spi.KeyIdDecorator; | |
| 30 | +import org.eclipse.edc.token.spi.TokenDecorator; | |
| 31 | +import org.eclipse.edc.token.spi.TokenGenerationService; | |
| 32 | +import org.eclipse.edc.token.spi.TokenValidationRule; | |
| 33 | +import org.eclipse.edc.token.spi.TokenValidationService; | |
| 34 | + | |
| 35 | +import java.util.ArrayList; | |
| 36 | +import java.util.List; | |
| 37 | +import java.util.Map; | |
| 38 | +import java.util.Objects; | |
| 39 | +import java.util.UUID; | |
| 40 | +import java.util.function.Supplier; | |
| 41 | +import java.util.stream.Stream; | |
| 42 | + | |
| 43 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 44 | + | |
| 45 | +/** | |
| 46 | + * This implementation of the {@link DataPlaneAccessTokenService} uses a backing storage ({@link AccessTokenDataStore}) to keep a record of all | |
| 47 | + * tokens it has issued. Tokens are in JWT format. | |
| 48 | + */ | |
| 49 | +public class DefaultDataPlaneAccessTokenServiceImpl implements DataPlaneAccessTokenService { | |
| 50 | + public static final String TOKEN_ID = "jti"; | |
| 51 | + private static final List<TokenValidationRule> DATAPLANE_ACCESS_TOKEN_RULES = List.of( | |
| 52 | + (claimtoken, additional) -> Objects.equals(claimtoken.getStringClaim("sub"), claimtoken.getStringClaim("iss")) ? Result.success() : Result.failure("'sub' and 'iss' claim must be equal and non-null"), | |
| 53 | + (toVerify, additional) -> toVerify.getStringClaim(TOKEN_ID) != null ? Result.success() : Result.failure("%s claim must be present on token".formatted(TOKEN_ID)) | |
| 54 | + ); | |
| 55 | + private final TokenGenerationService tokenGenerationService; | |
| 56 | + private final AccessTokenDataStore accessTokenDataStore; | |
| 57 | + private final Monitor monitor; | |
| 58 | + private final Supplier<String> privateKeyIdSupplier; | |
| 59 | + private final Supplier<String> publicKeyIdSupplier; | |
| 60 | + private final TokenValidationService tokenValidationService; | |
| 61 | + private final PublicKeyResolver publicKeyResolver; | |
| 62 | + | |
| 63 | + public DefaultDataPlaneAccessTokenServiceImpl(TokenGenerationService tokenGenerationService, | |
| 64 | + AccessTokenDataStore accessTokenDataStore, | |
| 65 | + Monitor monitor, | |
| 66 | + Supplier<String> privateKeyIdSupplier, | |
| 67 | + Supplier<String> publicKeyIdSupplier, | |
| 68 | + TokenValidationService tokenValidationService, | |
| 69 | + PublicKeyResolver publicKeyResolver) { | |
| 70 | + this.tokenGenerationService = tokenGenerationService; | |
| 71 | + this.accessTokenDataStore = accessTokenDataStore; | |
| 72 | + this.monitor = monitor; | |
| 73 | + this.privateKeyIdSupplier = privateKeyIdSupplier; | |
| 74 | + this.publicKeyIdSupplier = publicKeyIdSupplier; | |
| 75 | + this.tokenValidationService = tokenValidationService; | |
| 76 | + this.publicKeyResolver = publicKeyResolver; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Generates JWT tokens based on the {@link TokenParameters}. A representation of the claims and the data address is stored for subsequent use, using the token ID ("jti") | |
| 81 | + * as correlation id. | |
| 82 | + * | |
| 83 | + * @param parameters Headers and claims that are to be included in the token. If the claims do <em>not</em> contain a "jti" claim, one is generated randomly and inserted into the claims. | |
| 84 | + * @param backendDataAddress Information about the data resource for which the token is to be generated. May contain additional information about the token, such as an {@code authType} | |
| 85 | + * @param additionalTokenData Additional data that further characterizes the token, but should not be included in the resulting {@link TokenRepresentation}. Will be persisted in the {@link AccessTokenDataStore}. | |
| 86 | + * @return A token representation in serialized JWT format (signed). The JWTs "kid" header contains the ID of the public key that can be used to verify the token. | |
| 87 | + */ | |
| 88 | + @Override | |
| 89 | + public Result<TokenRepresentation> obtainToken(TokenParameters parameters, DataAddress backendDataAddress, Map<String, Object> additionalTokenData) { | |
| 90 | + Objects.requireNonNull(parameters, "TokenParameters must be non-null."); | |
| 91 | + Objects.requireNonNull(backendDataAddress, "DataAddress must be non-null."); | |
| 92 | + var claimDecorators = parameters.getClaims().entrySet().stream().map(e -> (TokenDecorator) claimDecorator -> claimDecorator.claims(e.getKey(), e.getValue())); | |
| 93 | + var headerDecorators = parameters.getHeaders().entrySet().stream().map(e -> (TokenDecorator) headerDecorator -> headerDecorator.header(e.getKey(), e.getValue())); | |
| 94 | + | |
| 95 | + var id = parameters.getStringClaim(TOKEN_ID); | |
| 96 | + var allDecorators = new ArrayList<>(Stream.concat(claimDecorators, headerDecorators).toList()); | |
| 97 | + var keyIdDecorator = new KeyIdDecorator(publicKeyIdSupplier.get()); | |
| 98 | + allDecorators.add(keyIdDecorator); | |
| 99 | + | |
| 100 | + // if there is no "jti" header on the token params, we'll assign a random one, and add it back to the decorators | |
| 101 | + if (id == null) { | |
| 102 | + monitor.info("No '%s' claim found on TokenParameters. Will generate a random one.".formatted(TOKEN_ID)); | |
| 103 | + id = UUID.randomUUID().toString(); | |
| 104 | + var tokenIdDecorator = new TokenIdDecorator(id); | |
| 105 | + allDecorators.add(tokenIdDecorator); | |
| 106 | + } | |
| 107 | + | |
| 108 | + var tokenResult = tokenGenerationService.generate(privateKeyIdSupplier.get(), allDecorators.toArray(new TokenDecorator[0])); | |
| 109 | + if (tokenResult.failed()) { | |
| 110 | + return tokenResult.mapEmpty(); | |
| 111 | + } | |
| 112 | + | |
| 113 | + // store a record of the token for future reference. We'll need that when we resolve the AccessTokenData later. | |
| 114 | + var claimToken = ClaimToken.Builder.newInstance().claims(parameters.getClaims()).build(); | |
| 115 | + var accessTokenData = new AccessTokenData(id, claimToken, backendDataAddress, additionalTokenData); | |
| 116 | + | |
| 117 | + var storeResult = accessTokenDataStore.store(accessTokenData); | |
| 118 | + var content = tokenResult.getContent(); | |
| 119 | + content.getAdditional().put(EDC_NAMESPACE + "authType", "bearer"); | |
| 120 | + return storeResult.succeeded() ? Result.success(content) : Result.failure(storeResult.getFailureMessages()); | |
| 121 | + } | |
| 122 | + | |
| 123 | + | |
| 124 | + @Override | |
| 125 | + public Result<AccessTokenData> resolve(String token) { | |
| 126 | + return tokenValidationService.validate(token, publicKeyResolver, DATAPLANE_ACCESS_TOKEN_RULES) | |
| 127 | + .map(claimToken -> claimToken.getStringClaim(TOKEN_ID)) | |
| 128 | + .compose(tokenId -> { | |
| 129 | + var existingAccessToken = accessTokenDataStore.getById(tokenId); | |
| 130 | + | |
| 131 | + return existingAccessToken == null ? | |
| 132 | + Result.failure("AccessTokenData with ID '%s' does not exist.".formatted(tokenId)) : | |
| 133 | + Result.success(existingAccessToken); | |
| 134 | + }); | |
| 135 | + } | |
| 136 | + | |
| 137 | + @Override | |
| 138 | + public Result<Void> revoke(String transferProcessId, String reason) { | |
| 139 | + | |
| 140 | + var query = QuerySpec.Builder.newInstance() | |
| 141 | + .filter(new Criterion("additionalProperties.process_id", "=", transferProcessId)) | |
| 142 | + .build(); | |
| 143 | + | |
| 144 | + var tokens = accessTokenDataStore.query(query); | |
| 145 | + return tokens.stream().map(this::deleteTokenData) | |
| 146 | + .reduce(Result::merge) | |
| 147 | + .orElseGet(() -> Result.failure("AccessTokenData associated to the transfer with ID '%s' does not exist.".formatted(transferProcessId))); | |
| 148 | + | |
| 149 | + } | |
| 150 | + | |
| 151 | + private Result<Void> deleteTokenData(AccessTokenData tokenData) { | |
| 152 | + var result = accessTokenDataStore.deleteById(tokenData.id()); | |
| 153 | + if (result.failed()) { | |
| 154 | + return Result.failure(result.getFailureDetail()); | |
| 155 | + } else { | |
| 156 | + return Result.success(); | |
| 157 | + } | |
| 158 | + } | |
| 159 | +} |
added extensions/data-plane/data-plane-iam/src/main/java/org/eclipse/edc/connector/dataplane/iam/service/TokenIdDecorator.java +34 −0
| @@ -0,0 +1,34 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam.service; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.spi.iam.TokenParameters; | |
| 18 | +import org.eclipse.edc.token.spi.TokenDecorator; | |
| 19 | + | |
| 20 | +import static org.eclipse.edc.connector.dataplane.iam.service.DefaultDataPlaneAccessTokenServiceImpl.TOKEN_ID; | |
| 21 | + | |
| 22 | +public class TokenIdDecorator implements TokenDecorator { | |
| 23 | + private final String tokenId; | |
| 24 | + | |
| 25 | + public TokenIdDecorator(String tokenId) { | |
| 26 | + this.tokenId = tokenId; | |
| 27 | + } | |
| 28 | + | |
| 29 | + @Override | |
| 30 | + public TokenParameters.Builder decorate(TokenParameters.Builder tokenParameters) { | |
| 31 | + tokenParameters.claims(TOKEN_ID, tokenId); | |
| 32 | + return tokenParameters; | |
| 33 | + } | |
| 34 | +} |
added extensions/data-plane/data-plane-iam/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension +2 −0
| @@ -0,0 +1,2 @@ | ||
| 1 | +org.eclipse.edc.connector.dataplane.iam.DataPlaneIamExtension | |
| 2 | +org.eclipse.edc.connector.dataplane.iam.DataPlaneIamDefaultServicesExtension |
added extensions/data-plane/data-plane-iam/src/test/java/org/eclipse/edc/connector/dataplane/iam/DataPlaneAuthorizationServiceImplTest.java +199 −0
| @@ -0,0 +1,199 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.connector.dataplane.iam.service.DataPlaneAuthorizationServiceImpl; | |
| 18 | +import org.eclipse.edc.connector.dataplane.spi.AccessTokenData; | |
| 19 | +import org.eclipse.edc.connector.dataplane.spi.Endpoint; | |
| 20 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessControlService; | |
| 21 | +import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAccessTokenService; | |
| 22 | +import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; | |
| 23 | +import org.eclipse.edc.spi.iam.ClaimToken; | |
| 24 | +import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 25 | +import org.eclipse.edc.spi.result.Result; | |
| 26 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 27 | +import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; | |
| 28 | +import org.eclipse.edc.spi.types.domain.transfer.FlowType; | |
| 29 | +import org.eclipse.edc.spi.types.domain.transfer.TransferType; | |
| 30 | +import org.junit.jupiter.api.BeforeEach; | |
| 31 | +import org.junit.jupiter.api.Test; | |
| 32 | +import org.mockito.ArgumentMatchers; | |
| 33 | + | |
| 34 | +import java.time.Clock; | |
| 35 | +import java.util.Map; | |
| 36 | +import java.util.Set; | |
| 37 | + | |
| 38 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 39 | +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 40 | +import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.AUDIENCE; | |
| 41 | +import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.ISSUED_AT; | |
| 42 | +import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.ISSUER; | |
| 43 | +import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.JWT_ID; | |
| 44 | +import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.SUBJECT; | |
| 45 | +import static org.mockito.ArgumentMatchers.any; | |
| 46 | +import static org.mockito.ArgumentMatchers.anyMap; | |
| 47 | +import static org.mockito.ArgumentMatchers.argThat; | |
| 48 | +import static org.mockito.ArgumentMatchers.eq; | |
| 49 | +import static org.mockito.Mockito.mock; | |
| 50 | +import static org.mockito.Mockito.verify; | |
| 51 | +import static org.mockito.Mockito.verifyNoMoreInteractions; | |
| 52 | +import static org.mockito.Mockito.when; | |
| 53 | + | |
| 54 | +class DataPlaneAuthorizationServiceImplTest { | |
| 55 | + | |
| 56 | + public static final String OWN_PARTICIPANT_ID = "test-ownParticipantId"; | |
| 57 | + private final DataPlaneAccessTokenService accessTokenService = mock(); | |
| 58 | + private final PublicEndpointGeneratorService endpointGenerator = mock(); | |
| 59 | + private final DataPlaneAccessControlService accessControlService = mock(); | |
| 60 | + private final DataPlaneAuthorizationServiceImpl authorizationService = new DataPlaneAuthorizationServiceImpl(accessTokenService, endpointGenerator, accessControlService, OWN_PARTICIPANT_ID, Clock.systemUTC()); | |
| 61 | + | |
| 62 | + @BeforeEach | |
| 63 | + void setup() { | |
| 64 | + when(endpointGenerator.generateFor(any(), any())).thenReturn(Result.success(Endpoint.url("http://example.com"))); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Test | |
| 68 | + void createEndpointDataReference() { | |
| 69 | + when(accessTokenService.obtainToken(any(), any(), anyMap())).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("footoken").build())); | |
| 70 | + var startMsg = createStartMessage() | |
| 71 | + .transferType(new TransferType("DestinationType", FlowType.PULL)) | |
| 72 | + .build(); | |
| 73 | + | |
| 74 | + var result = authorizationService.createEndpointDataReference(startMsg); | |
| 75 | + assertThat(result).isSucceeded() | |
| 76 | + .satisfies(da -> { | |
| 77 | + assertThat(da.getType()).isEqualTo("https://w3id.org/idsa/v4.1/HTTP"); | |
| 78 | + assertThat(da.getStringProperty("endpoint")).isEqualTo("http://example.com"); | |
| 79 | + assertThat(da.getStringProperty("endpointType")).isEqualTo(da.getType()); | |
| 80 | + assertThat(da.getStringProperty("authorization")).isEqualTo("footoken"); | |
| 81 | + }); | |
| 82 | + | |
| 83 | + var requiredClaims = Set.of(JWT_ID, AUDIENCE, ISSUER, SUBJECT, ISSUED_AT); | |
| 84 | + verify(accessTokenService).obtainToken(ArgumentMatchers.assertArg(tp -> { | |
| 85 | + assertThat(tp.getClaims().keySet()).containsAll(requiredClaims); | |
| 86 | + assertThat(tp.getStringClaim(AUDIENCE)).isEqualTo(startMsg.getParticipantId()); | |
| 87 | + assertThat(tp.getStringClaim(ISSUER)).isEqualTo(OWN_PARTICIPANT_ID); | |
| 88 | + assertThat(tp.getStringClaim(SUBJECT)).isEqualTo(OWN_PARTICIPANT_ID); | |
| 89 | + assertThat(tp.getClaims().get(ISSUED_AT)).isNotNull(); | |
| 90 | + }), any(), argThat(m -> | |
| 91 | + m.containsKey("agreement_id") && | |
| 92 | + m.containsKey("participant_id") && | |
| 93 | + m.containsKey("asset_id") && | |
| 94 | + m.containsKey("process_id") && | |
| 95 | + m.containsKey("flow_type"))); | |
| 96 | + verify(endpointGenerator).generateFor("DestinationType", startMsg.getSourceDataAddress()); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + void createEndpointDataReference_withAuthType() { | |
| 101 | + when(accessTokenService.obtainToken(any(), any(), anyMap())).thenReturn(Result.success(TokenRepresentation.Builder.newInstance() | |
| 102 | + .token("footoken") | |
| 103 | + .additional(Map.of("authType", "bearer", "fizz", "buzz")) | |
| 104 | + .build())); | |
| 105 | + var startMsg = createStartMessage().build(); | |
| 106 | + | |
| 107 | + var result = authorizationService.createEndpointDataReference(startMsg); | |
| 108 | + assertThat(result).isSucceeded() | |
| 109 | + .satisfies(da -> { | |
| 110 | + assertThat(da.getType()).isEqualTo("https://w3id.org/idsa/v4.1/HTTP"); | |
| 111 | + assertThat(da.getStringProperty("endpoint")).isEqualTo("http://example.com"); | |
| 112 | + assertThat(da.getStringProperty("authorization")).isEqualTo("footoken"); | |
| 113 | + assertThat(da.getStringProperty("authType")).isEqualTo("bearer"); | |
| 114 | + assertThat(da.getStringProperty("fizz")).isEqualTo("buzz"); | |
| 115 | + }); | |
| 116 | + } | |
| 117 | + | |
| 118 | + @Test | |
| 119 | + void createEndpointDataReference_tokenServiceFails() { | |
| 120 | + when(accessTokenService.obtainToken(any(), any(), anyMap())).thenReturn(Result.failure("test-failure")); | |
| 121 | + var startMsg = createStartMessage().build(); | |
| 122 | + assertThat(authorizationService.createEndpointDataReference(startMsg)).isFailed() | |
| 123 | + .detail().isEqualTo("test-failure"); | |
| 124 | + } | |
| 125 | + | |
| 126 | + @Test | |
| 127 | + void authorize() { | |
| 128 | + var claimToken = ClaimToken.Builder.newInstance().build(); | |
| 129 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 130 | + when(accessTokenService.resolve(eq("foo-token"))).thenReturn(Result.success(new AccessTokenData("test-id", | |
| 131 | + claimToken, | |
| 132 | + address))); | |
| 133 | + when(accessControlService.checkAccess(eq(claimToken), eq(address), any(), anyMap())).thenReturn(Result.success()); | |
| 134 | + | |
| 135 | + assertThat(authorizationService.authorize("foo-token", Map.of())).isSucceeded(); | |
| 136 | + verify(accessTokenService).resolve(eq("foo-token")); | |
| 137 | + verify(accessControlService).checkAccess(eq(claimToken), eq(address), any(), anyMap()); | |
| 138 | + verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Test | |
| 142 | + void authorize_tokenNotFound() { | |
| 143 | + when(accessTokenService.resolve(eq("foo-token"))).thenReturn(Result.failure("not found")); | |
| 144 | + | |
| 145 | + assertThat(authorizationService.authorize("foo-token", Map.of())).isFailed() | |
| 146 | + .detail().isEqualTo("not found"); | |
| 147 | + verify(accessTokenService).resolve(eq("foo-token")); | |
| 148 | + verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 149 | + } | |
| 150 | + | |
| 151 | + @Test | |
| 152 | + void authorize_accessNotGranted() { | |
| 153 | + var claimToken = ClaimToken.Builder.newInstance().build(); | |
| 154 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 155 | + when(accessTokenService.resolve(eq("foo-token"))).thenReturn(Result.success(new AccessTokenData("test-id", | |
| 156 | + claimToken, | |
| 157 | + address))); | |
| 158 | + when(accessControlService.checkAccess(eq(claimToken), eq(address), any(), anyMap())).thenReturn(Result.failure("not granted")); | |
| 159 | + | |
| 160 | + assertThat(authorizationService.authorize("foo-token", Map.of())).isFailed() | |
| 161 | + .detail().isEqualTo("not granted"); | |
| 162 | + verify(accessTokenService).resolve(eq("foo-token")); | |
| 163 | + verify(accessControlService).checkAccess(eq(claimToken), eq(address), any(), anyMap()); | |
| 164 | + verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 165 | + } | |
| 166 | + | |
| 167 | + @Test | |
| 168 | + void revoke() { | |
| 169 | + when(accessTokenService.revoke(eq("id"), eq("reason"))).thenReturn(Result.success()); | |
| 170 | + | |
| 171 | + assertThat(authorizationService.revokeEndpointDataReference("id", "reason")).isSucceeded(); | |
| 172 | + | |
| 173 | + verify(accessTokenService).revoke(eq("id"), eq("reason")); | |
| 174 | + verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 175 | + } | |
| 176 | + | |
| 177 | + @Test | |
| 178 | + void revoke_error() { | |
| 179 | + when(accessTokenService.revoke(eq("id"), eq("reason"))).thenReturn(Result.failure("failure")); | |
| 180 | + | |
| 181 | + assertThat(authorizationService.revokeEndpointDataReference("id", "reason")).isFailed() | |
| 182 | + .detail().contains("failure"); | |
| 183 | + | |
| 184 | + verify(accessTokenService).revoke(eq("id"), eq("reason")); | |
| 185 | + verifyNoMoreInteractions(accessTokenService, accessControlService); | |
| 186 | + } | |
| 187 | + | |
| 188 | + private DataFlowStartMessage.Builder createStartMessage() { | |
| 189 | + return DataFlowStartMessage.Builder.newInstance() | |
| 190 | + .processId("test-processid") | |
| 191 | + .transferType(new TransferType("DestinationType", FlowType.PULL)) | |
| 192 | + .agreementId("test-agreementid") | |
| 193 | + .participantId("test-participantid") | |
| 194 | + .assetId("test-assetid") | |
| 195 | + .sourceDataAddress(DataAddress.Builder.newInstance().type("test-src").build()) | |
| 196 | + .destinationDataAddress(DataAddress.Builder.newInstance().type("test-dest").build()) | |
| 197 | + .properties(Map.of("foo", "bar", "fizz", "buzz")); | |
| 198 | + } | |
| 199 | +} |
added extensions/data-plane/data-plane-iam/src/test/java/org/eclipse/edc/connector/dataplane/iam/DefaultDataPlaneAccessTokenServiceImplTest.java +242 −0
| @@ -0,0 +1,242 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.iam; | |
| 16 | + | |
| 17 | +import org.assertj.core.api.Assertions; | |
| 18 | +import org.eclipse.edc.connector.dataplane.iam.service.DefaultDataPlaneAccessTokenServiceImpl; | |
| 19 | +import org.eclipse.edc.connector.dataplane.spi.AccessTokenData; | |
| 20 | +import org.eclipse.edc.connector.dataplane.spi.store.AccessTokenDataStore; | |
| 21 | +import org.eclipse.edc.spi.iam.ClaimToken; | |
| 22 | +import org.eclipse.edc.spi.iam.TokenParameters; | |
| 23 | +import org.eclipse.edc.spi.iam.TokenRepresentation; | |
| 24 | +import org.eclipse.edc.spi.query.Criterion; | |
| 25 | +import org.eclipse.edc.spi.query.QuerySpec; | |
| 26 | +import org.eclipse.edc.spi.result.Result; | |
| 27 | +import org.eclipse.edc.spi.result.StoreResult; | |
| 28 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 29 | +import org.eclipse.edc.token.spi.TokenDecorator; | |
| 30 | +import org.eclipse.edc.token.spi.TokenGenerationService; | |
| 31 | +import org.eclipse.edc.token.spi.TokenValidationService; | |
| 32 | +import org.junit.jupiter.api.Test; | |
| 33 | + | |
| 34 | +import java.util.List; | |
| 35 | +import java.util.Map; | |
| 36 | +import java.util.regex.Pattern; | |
| 37 | + | |
| 38 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; | |
| 39 | +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 40 | +import static org.mockito.ArgumentMatchers.any; | |
| 41 | +import static org.mockito.ArgumentMatchers.anyList; | |
| 42 | +import static org.mockito.ArgumentMatchers.anyString; | |
| 43 | +import static org.mockito.ArgumentMatchers.argThat; | |
| 44 | +import static org.mockito.ArgumentMatchers.eq; | |
| 45 | +import static org.mockito.Mockito.mock; | |
| 46 | +import static org.mockito.Mockito.never; | |
| 47 | +import static org.mockito.Mockito.verify; | |
| 48 | +import static org.mockito.Mockito.verifyNoInteractions; | |
| 49 | +import static org.mockito.Mockito.verifyNoMoreInteractions; | |
| 50 | +import static org.mockito.Mockito.when; | |
| 51 | + | |
| 52 | +class DefaultDataPlaneAccessTokenServiceImplTest { | |
| 53 | + | |
| 54 | + private static final Pattern UUID_PATTERN = Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); | |
| 55 | + private final AccessTokenDataStore store = mock(); | |
| 56 | + private final TokenGenerationService tokenGenService = mock(); | |
| 57 | + private final TokenValidationService tokenValidationService = mock(); | |
| 58 | + private final DefaultDataPlaneAccessTokenServiceImpl accessTokenService = new DefaultDataPlaneAccessTokenServiceImpl(tokenGenService, | |
| 59 | + store, mock(), mock(), mock(), tokenValidationService, mock()); | |
| 60 | + | |
| 61 | + @Test | |
| 62 | + void obtainToken() { | |
| 63 | + var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 64 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 65 | + | |
| 66 | + when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 67 | + when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.success()); | |
| 68 | + | |
| 69 | + var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 70 | + assertThat(result).isSucceeded().extracting(TokenRepresentation::getToken).isEqualTo("foo-token"); | |
| 71 | + | |
| 72 | + verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 73 | + verify(store).store(any(AccessTokenData.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + void obtainToken_withAdditionalProperties() { | |
| 78 | + var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 79 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 80 | + | |
| 81 | + when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 82 | + when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.success()); | |
| 83 | + | |
| 84 | + var result = accessTokenService.obtainToken(params, address, Map.of("foo", "bar")); | |
| 85 | + assertThat(result).isSucceeded().extracting(TokenRepresentation::getToken).isEqualTo("foo-token"); | |
| 86 | + | |
| 87 | + verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 88 | + verify(store).store(argThat(accessTokenData -> accessTokenData.additionalProperties().get("foo").equals("bar"))); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Test | |
| 92 | + void obtainToken_invalidParams() { | |
| 93 | + assertThatThrownBy(() -> accessTokenService.obtainToken(null, DataAddress.Builder.newInstance().type("foo").build(), Map.of())) | |
| 94 | + .isInstanceOf(NullPointerException.class); | |
| 95 | + assertThatThrownBy(() -> accessTokenService.obtainToken(TokenParameters.Builder.newInstance().build(), null, Map.of())) | |
| 96 | + .isInstanceOf(NullPointerException.class); | |
| 97 | + | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Test | |
| 101 | + void obtainToken_noTokenId() { | |
| 102 | + var params = TokenParameters.Builder.newInstance().claims("foo", "bar")/* missing: .claims("jti", "baz")*/.header("qux", "quz").build(); | |
| 103 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 104 | + | |
| 105 | + when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 106 | + when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.success()); | |
| 107 | + | |
| 108 | + var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 109 | + assertThat(result).isSucceeded().extracting(TokenRepresentation::getToken).isEqualTo("foo-token"); | |
| 110 | + | |
| 111 | + verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 112 | + verify(store).store(argThat(accessTokenData -> UUID_PATTERN.matcher(accessTokenData.id()).matches())); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @Test | |
| 116 | + void obtainToken_creationFails() { | |
| 117 | + var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 118 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 119 | + | |
| 120 | + when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.failure("test failure")); | |
| 121 | + | |
| 122 | + var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 123 | + assertThat(result).isFailed().detail().isEqualTo("test failure"); | |
| 124 | + | |
| 125 | + verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 126 | + verifyNoMoreInteractions(store); | |
| 127 | + } | |
| 128 | + | |
| 129 | + @Test | |
| 130 | + void obtainToken_storingFails() { | |
| 131 | + var params = TokenParameters.Builder.newInstance().claims("foo", "bar").claims("jti", "baz").header("qux", "quz").build(); | |
| 132 | + var address = DataAddress.Builder.newInstance().type("test-type").build(); | |
| 133 | + | |
| 134 | + when(tokenGenService.generate(any(), any(TokenDecorator[].class))).thenReturn(Result.success(TokenRepresentation.Builder.newInstance().token("foo-token").build())); | |
| 135 | + when(store.store(any(AccessTokenData.class))).thenReturn(StoreResult.alreadyExists("test failure")); | |
| 136 | + | |
| 137 | + var result = accessTokenService.obtainToken(params, address, Map.of()); | |
| 138 | + assertThat(result).isFailed().detail().isEqualTo("test failure"); | |
| 139 | + | |
| 140 | + verify(tokenGenService).generate(any(), any(TokenDecorator[].class)); | |
| 141 | + verify(store).store(any(AccessTokenData.class)); | |
| 142 | + } | |
| 143 | + | |
| 144 | + @Test | |
| 145 | + void resolve() { | |
| 146 | + var tokenId = "test-id"; | |
| 147 | + var claimToken = ClaimToken.Builder.newInstance().claim("jti", tokenId).build(); | |
| 148 | + when(tokenValidationService.validate(anyString(), any(), anyList())) | |
| 149 | + .thenReturn(Result.success(claimToken)); | |
| 150 | + when(store.getById(eq(tokenId))).thenReturn(new AccessTokenData(tokenId, ClaimToken.Builder.newInstance().build(), | |
| 151 | + DataAddress.Builder.newInstance().type("test-type").build())); | |
| 152 | + | |
| 153 | + var result = accessTokenService.resolve("some-jwt"); | |
| 154 | + assertThat(result).isSucceeded() | |
| 155 | + .satisfies(atd -> Assertions.assertThat(atd.id()).isEqualTo(tokenId)); | |
| 156 | + verify(tokenValidationService).validate(eq("some-jwt"), any(), anyList()); | |
| 157 | + verify(store).getById(eq(tokenId)); | |
| 158 | + } | |
| 159 | + | |
| 160 | + @Test | |
| 161 | + void resolve_whenValidationFails() { | |
| 162 | + var tokenId = "test-id"; | |
| 163 | + var claimToken = ClaimToken.Builder.newInstance().claim("jti", tokenId).build(); | |
| 164 | + when(tokenValidationService.validate(anyString(), any(), anyList())) | |
| 165 | + .thenReturn(Result.failure("test-failure")); | |
| 166 | + | |
| 167 | + var result = accessTokenService.resolve("some-jwt"); | |
| 168 | + assertThat(result).isFailed() | |
| 169 | + .detail().isEqualTo("test-failure"); | |
| 170 | + verify(tokenValidationService).validate(eq("some-jwt"), any(), anyList()); | |
| 171 | + verifyNoInteractions(store); | |
| 172 | + } | |
| 173 | + | |
| 174 | + @Test | |
| 175 | + void resolve_whenTokenIdNotFound() { | |
| 176 | + var tokenId = "test-id"; | |
| 177 | + var claimToken = ClaimToken.Builder.newInstance().claim("jti", tokenId).build(); | |
| 178 | + when(tokenValidationService.validate(anyString(), any(), anyList())) | |
| 179 | + .thenReturn(Result.success(claimToken)); | |
| 180 | + when(store.getById(eq(tokenId))).thenReturn(null); | |
| 181 | + | |
| 182 | + var result = accessTokenService.resolve("some-jwt"); | |
| 183 | + assertThat(result).isFailed() | |
| 184 | + .detail().isEqualTo("AccessTokenData with ID 'test-id' does not exist."); | |
| 185 | + verify(tokenValidationService).validate(eq("some-jwt"), any(), anyList()); | |
| 186 | + verify(store).getById(eq(tokenId)); | |
| 187 | + } | |
| 188 | + | |
| 189 | + | |
| 190 | + @Test | |
| 191 | + void revoke() { | |
| 192 | + var tokenId = "test-id"; | |
| 193 | + var processId = "tp-id"; | |
| 194 | + | |
| 195 | + var querySpec = QuerySpec.Builder.newInstance().filter(new Criterion("additionalProperties.process_id", "=", processId)).build(); | |
| 196 | + | |
| 197 | + var tokenData = new AccessTokenData(tokenId, ClaimToken.Builder.newInstance().build(), | |
| 198 | + DataAddress.Builder.newInstance().type("test-type").build()); | |
| 199 | + | |
| 200 | + when(store.query(querySpec)).thenReturn(List.of(tokenData)); | |
| 201 | + when(store.deleteById(tokenId)).thenReturn(StoreResult.success()); | |
| 202 | + | |
| 203 | + var result = accessTokenService.revoke("tp-id", "reason"); | |
| 204 | + assertThat(result).isSucceeded(); | |
| 205 | + | |
| 206 | + verify(store).deleteById(eq(tokenId)); | |
| 207 | + | |
| 208 | + } | |
| 209 | + | |
| 210 | + @Test | |
| 211 | + void revoke_storeError() { | |
| 212 | + var tokenId = "test-id"; | |
| 213 | + var processId = "tp-id"; | |
| 214 | + | |
| 215 | + var querySpec = QuerySpec.Builder.newInstance().filter(new Criterion("additionalProperties.process_id", "=", processId)).build(); | |
| 216 | + | |
| 217 | + var tokenData = new AccessTokenData(tokenId, ClaimToken.Builder.newInstance().build(), | |
| 218 | + DataAddress.Builder.newInstance().type("test-type").build()); | |
| 219 | + | |
| 220 | + when(store.query(querySpec)).thenReturn(List.of(tokenData)); | |
| 221 | + when(store.deleteById(tokenId)).thenReturn(StoreResult.generalError("storeError")); | |
| 222 | + | |
| 223 | + var result = accessTokenService.revoke("tp-id", "reason"); | |
| 224 | + assertThat(result).isFailed().detail().contains("storeError"); | |
| 225 | + | |
| 226 | + verify(store).deleteById(eq(tokenId)); | |
| 227 | + } | |
| 228 | + | |
| 229 | + @Test | |
| 230 | + void revoke_notTokensFound() { | |
| 231 | + var processId = "tp-id"; | |
| 232 | + var querySpec = QuerySpec.Builder.newInstance().filter(new Criterion("additionalProperties.process_id", "=", processId)).build(); | |
| 233 | + | |
| 234 | + when(store.query(querySpec)).thenReturn(List.of()); | |
| 235 | + | |
| 236 | + var result = accessTokenService.revoke("tp-id", "reason"); | |
| 237 | + assertThat(result).isFailed().detail().contains("AccessTokenData associated to the transfer with ID"); | |
| 238 | + | |
| 239 | + verify(store, never()).deleteById(any()); | |
| 240 | + | |
| 241 | + } | |
| 242 | +} |
modified extensions/data-plane/data-plane-integration-tests/src/test/java/org/eclipse/edc/connector/dataplane/http/DataPlaneHttpIntegrationTests.java +0 −2
| @@ -114,8 +114,6 @@ | ||
| 114 | 114 | "web.http.control.port", valueOf(CONTROL_API_PORT), |
| 115 | 115 | "web.http.control.path", CONTROL_PATH, |
| 116 | 116 | "edc.dataplane.token.validation.endpoint", VALIDATION_API_HOST, |
| 117 | - "edc.transfer.proxy.token.verifier.publickey.alias", "alias", | |
| 118 | - "edc.transfer.proxy.token.signer.privatekey.alias", "alias", | |
| 119 | 117 | "edc.core.retry.retries.max", "0" |
| 120 | 118 | ), |
| 121 | 119 | ":extensions:common:metrics:micrometer-core", |
modified gradle.properties +0 −3
| @@ -1,7 +1,4 @@ | ||
| 1 | 1 | group=org.eclipse.edc |
| 2 | 2 | version=0.8.2-SNAPSHOT |
| 3 | -# for now, we're using the same version for the autodoc plugin and the processor, but that could change in the future | |
| 4 | -annotationProcessorVersion=0.8.2-SNAPSHOT | |
| 5 | -edcGradlePluginsVersion=0.8.2-SNAPSHOT | |
| 6 | 3 | edcScmUrl=https://github.com/eclipse-edc/Connector.git |
| 7 | 4 | edcScmConnection=scm:git:git@github.com:eclipse-edc/Connector.git |
modified settings.gradle.kts +2 −0
| @@ -206,6 +206,7 @@ | ||
| 206 | 206 | include(":extensions:data-plane:data-plane-http") |
| 207 | 207 | include(":extensions:data-plane:data-plane-http-oauth2") |
| 208 | 208 | include(":extensions:data-plane:data-plane-http-oauth2-core") |
| 209 | +include(":extensions:data-plane:data-plane-iam") | |
| 209 | 210 | include(":extensions:data-plane:data-plane-integration-tests") |
| 210 | 211 | include(":extensions:data-plane:store:sql:data-plane-store-sql") |
| 211 | 212 | include(":extensions:data-plane:store:sql:accesstokendata-store-sql") |
| @@ -262,6 +263,7 @@ | ||
| 262 | 263 | |
| 263 | 264 | include(":spi:data-plane:data-plane-spi") |
| 264 | 265 | include(":spi:data-plane:data-plane-http-spi") |
| 266 | +include(":spi:data-plane:data-plane-iam-spi") | |
| 265 | 267 | |
| 266 | 268 | include(":spi:data-plane-selector:data-plane-selector-spi") |
| 267 | 269 | include(":spi:policy-monitor:policy-monitor-spi") |
added spi/data-plane/data-plane-spi/src/main/java/org/eclipse/edc/connector/dataplane/spi/iam/NoOpDataPlaneAuthorizationService.java +46 −0
| @@ -0,0 +1,46 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Contributors to the Eclipse Foundation | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Contributors to the Eclipse Foundation - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.dataplane.spi.iam; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.spi.result.Result; | |
| 18 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 19 | +import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; | |
| 20 | + | |
| 21 | +import java.util.Map; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * Placeholder class meant to permit a data-plane to run without a DataPlaneAuthorizationService if not needed, but that | |
| 25 | + * will always return failure. | |
| 26 | + */ | |
| 27 | +public class NoOpDataPlaneAuthorizationService implements DataPlaneAuthorizationService { | |
| 28 | + | |
| 29 | + private static final Result<DataAddress> FAILURE = Result | |
| 30 | + .failure("PULL transfers are not supported unless a proper DataPlaneAuthorizationService is registered"); | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Result<DataAddress> createEndpointDataReference(DataFlowStartMessage message) { | |
| 34 | + return FAILURE; | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public Result<DataAddress> authorize(String token, Map<String, Object> requestData) { | |
| 39 | + return FAILURE; | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public Result<Void> revokeEndpointDataReference(String transferProcessId, String reason) { | |
| 44 | + return FAILURE.mapEmpty(); | |
| 45 | + } | |
| 46 | +} |
modified system-tests/e2e-dataplane-tests/runtimes/data-plane/build.gradle.kts +3 −0
| @@ -16,10 +16,13 @@ | ||
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | dependencies { |
| 19 | + implementation(project(":core:common:connector-core")) | |
| 19 | 20 | implementation(project(":core:data-plane:data-plane-core")) |
| 20 | 21 | implementation(project(":extensions:common:api:control-api-configuration")) |
| 22 | + implementation(project(":extensions:common:http")) | |
| 21 | 23 | implementation(project(":extensions:control-plane:api:control-plane-api-client")) |
| 22 | 24 | implementation(project(":extensions:data-plane:data-plane-http")) |
| 25 | + implementation(project(":extensions:data-plane:data-plane-iam")) | |
| 23 | 26 | implementation(project(":extensions:data-plane:data-plane-control-api")) |
| 24 | 27 | implementation(project(":extensions:data-plane:data-plane-public-api-v2")) |
| 25 | 28 | implementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-api")) |
modified system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSelectorEndToEndTest.java +1 −5
| @@ -69,12 +69,8 @@ | ||
| 69 | 69 | private final RuntimeExtension dataPlane = new RuntimePerMethodExtension(new EmbeddedRuntime( |
| 70 | 70 | "data-plane", |
| 71 | 71 | Map.of( |
| 72 | - "web.http.port", String.valueOf(getFreePort()), | |
| 73 | - "web.http.path", "/api", | |
| 74 | 72 | "web.http.control.port", String.valueOf(dataPlaneControlPort), |
| 75 | - "web.http.control.path", "/control", | |
| 76 | - "edc.transfer.proxy.token.verifier.publickey.alias", "alias", | |
| 77 | - "edc.transfer.proxy.token.signer.privatekey.alias", "alias" | |
| 73 | + "web.http.control.path", "/control" | |
| 78 | 74 | ), |
| 79 | 75 | ":core:data-plane:data-plane-core", |
| 80 | 76 | ":extensions:data-plane:data-plane-http", |
modified system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataplaneSelectorControlApiEndToEndTest.java +5 −3
| @@ -51,7 +51,9 @@ | ||
| 51 | 51 | "data-plane-selector", |
| 52 | 52 | Map.of( |
| 53 | 53 | "web.http.control.port", String.valueOf(controlPort), |
| 54 | - "web.http.control.path", "/control" | |
| 54 | + "web.http.control.path", "/control", | |
| 55 | + "edc.transfer.proxy.token.verifier.publickey.alias", "public-key", | |
| 56 | + "edc.transfer.proxy.token.signer.privatekey.alias", "private-key" | |
| 55 | 57 | ), |
| 56 | 58 | ":core:common:connector-core", |
| 57 | 59 | ":core:data-plane-selector:data-plane-selector-core", |
| @@ -72,8 +74,8 @@ | ||
| 72 | 74 | "web.http.control.port", String.valueOf(getFreePort()), |
| 73 | 75 | "web.http.control.path", "/control", |
| 74 | 76 | "edc.dpf.selector.url", String.format("http://localhost:%d/control/v1/dataplanes", controlPort), |
| 75 | - "edc.transfer.proxy.token.verifier.publickey.alias", "alias", | |
| 76 | - "edc.transfer.proxy.token.signer.privatekey.alias", "alias" | |
| 77 | + "edc.transfer.proxy.token.verifier.publickey.alias", "public-key", | |
| 78 | + "edc.transfer.proxy.token.signer.privatekey.alias", "private-key" | |
| 77 | 79 | ), |
| 78 | 80 | ":system-tests:e2e-dataplane-tests:runtimes:data-plane", |
| 79 | 81 | ":extensions:data-plane:data-plane-self-registration", |
modified system-tests/e2e-transfer-test/data-plane/build.gradle.kts +2 −0
| @@ -19,8 +19,10 @@ | ||
| 19 | 19 | dependencies { |
| 20 | 20 | implementation(project(":core:data-plane:data-plane-core")) |
| 21 | 21 | implementation(project(":extensions:common:api:control-api-configuration")) |
| 22 | + implementation(project(":extensions:common:http")) | |
| 22 | 23 | implementation(project(":extensions:control-plane:api:control-plane-api-client")) |
| 23 | 24 | implementation(project(":extensions:data-plane:data-plane-self-registration")) |
| 25 | + implementation(project(":extensions:data-plane:data-plane-iam")) | |
| 24 | 26 | implementation(project(":extensions:data-plane:data-plane-http")) |
| 25 | 27 | implementation(project(":extensions:data-plane:data-plane-kafka")) |
| 26 | 28 | implementation(project(":extensions:data-plane:data-plane-http-oauth2")) |
deleted system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/sql/configuration/DataSourceNameTest.java +0 −63
| @@ -1,63 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 3 | - * | |
| 4 | - * This program and the accompanying materials are made available under the | |
| 5 | - * terms of the Apache License, Version 2.0 which is available at | |
| 6 | - * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | - * | |
| 8 | - * SPDX-License-Identifier: Apache-2.0 | |
| 9 | - * | |
| 10 | - * Contributors: | |
| 11 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.sql.configuration; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.spi.monitor.Monitor; | |
| 18 | -import org.eclipse.edc.spi.system.configuration.ConfigFactory; | |
| 19 | -import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; | |
| 20 | -import org.junit.jupiter.api.Test; | |
| 21 | - | |
| 22 | -import java.util.Map; | |
| 23 | - | |
| 24 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 25 | -import static org.mockito.ArgumentMatchers.anyString; | |
| 26 | -import static org.mockito.Mockito.mock; | |
| 27 | -import static org.mockito.Mockito.verify; | |
| 28 | -import static org.mockito.Mockito.verifyNoInteractions; | |
| 29 | - | |
| 30 | -class DataSourceNameTest { | |
| 31 | - | |
| 32 | - private final Monitor monitor = mock(); | |
| 33 | - | |
| 34 | - @Test | |
| 35 | - void shouldReturnDefaultDatasource_whenNoConfiguration() { | |
| 36 | - var config = ConfigFactory.empty(); | |
| 37 | - | |
| 38 | - var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 39 | - | |
| 40 | - assertThat(datasourceName).isEqualTo(DataSourceRegistry.DEFAULT_DATASOURCE); | |
| 41 | - verifyNoInteractions(monitor); | |
| 42 | - } | |
| 43 | - | |
| 44 | - @Test | |
| 45 | - void shouldReturnDatasource_whenIsInConfiguration() { | |
| 46 | - var config = ConfigFactory.fromMap(Map.of("key", "value")); | |
| 47 | - | |
| 48 | - var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 49 | - | |
| 50 | - assertThat(datasourceName).isEqualTo("value"); | |
| 51 | - verifyNoInteractions(monitor); | |
| 52 | - } | |
| 53 | - | |
| 54 | - @Test | |
| 55 | - void shouldLogWarning_whenDeprecatedKeyIsUsed() { | |
| 56 | - var config = ConfigFactory.fromMap(Map.of("deprecatedKey", "value")); | |
| 57 | - | |
| 58 | - var datasourceName = DataSourceName.getDataSourceName("key", "deprecatedKey", config, monitor); | |
| 59 | - | |
| 60 | - assertThat(datasourceName).isEqualTo("value"); | |
| 61 | - verify(monitor).warning(anyString()); | |
| 62 | - } | |
| 63 | -} |