Skip to content

Commit

Permalink
feat: allow customization of the STS Account's secret_alias (#469)
Browse files Browse the repository at this point in the history
* feat: allow customization of the STS Account's secret_alias

* DEPENDENCIES

* update api version
  • Loading branch information
paullatzelsperger authored Oct 2, 2024
1 parent 46eaf00 commit 634deb0
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 19 deletions.
38 changes: 23 additions & 15 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,31 @@ maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.14.0, Apache
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.14.1, Apache-2.0, approved, #5303
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.16.2, Apache-2.0, approved, #11606
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.17.1, Apache-2.0, approved, #13672
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.17.2, Apache-2.0, approved, #13672
maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.18.0, Apache-2.0, approved, #16364
maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.14.1, Apache-2.0 AND MIT, approved, #4303
maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.16.2, Apache-2.0 AND MIT, approved, #11602
maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.17.2, , approved, #13665
maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.18.0, Apache-2.0 AND MIT, approved, #16371
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.11.0, Apache-2.0, approved, CQ23093
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.14.0, Apache-2.0, approved, #4105
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.14.1, Apache-2.0, approved, #15232
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.16.2, Apache-2.0, approved, #11605
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.17.1, Apache-2.0, approved, #13671
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.17.2, Apache-2.0, approved, #13671
maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.18.0, Apache-2.0, approved, #16372
maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.14.0, Apache-2.0, approved, #5933
maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.16.2, Apache-2.0, approved, #11855
maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.17.2, Apache-2.0, approved, #13669
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jakarta-jsonp/2.17.2, Apache-2.0, approved, #14161
maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.18.0, Apache-2.0, approved, #16370
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jakarta-jsonp/2.18.0, Apache-2.0, restricted, clearlydefined
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.14.0, Apache-2.0, approved, #4699
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.16.2, Apache-2.0, approved, #11853
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.17.2, Apache-2.0, approved, #14160
maven/mavencentral/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-base/2.17.2, Apache-2.0, approved, #14194
maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.18.0, , restricted, clearlydefined
maven/mavencentral/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-base/2.18.0, , restricted, clearlydefined
maven/mavencentral/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-json-provider/2.16.2, Apache-2.0, approved, #11858
maven/mavencentral/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-json-provider/2.17.2, Apache-2.0, approved, #14195
maven/mavencentral/com.fasterxml.jackson.jakarta.rs/jackson-jakarta-rs-json-provider/2.18.0, , restricted, clearlydefined
maven/mavencentral/com.fasterxml.jackson.module/jackson-module-jakarta-xmlbind-annotations/2.17.1, Apache-2.0, approved, #13668
maven/mavencentral/com.fasterxml.jackson.module/jackson-module-jakarta-xmlbind-annotations/2.17.2, Apache-2.0, approved, #13668
maven/mavencentral/com.fasterxml.jackson.module/jackson-module-jakarta-xmlbind-annotations/2.18.0, Apache-2.0, approved, #16368
maven/mavencentral/com.fasterxml.jackson/jackson-bom/2.16.2, Apache-2.0, approved, #11852
maven/mavencentral/com.fasterxml.jackson/jackson-bom/2.17.2, Apache-2.0, approved, #14162
maven/mavencentral/com.fasterxml.jackson/jackson-bom/2.18.0, , restricted, clearlydefined
maven/mavencentral/com.fasterxml.uuid/java-uuid-generator/4.1.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.github.cliftonlabs/json-simple/3.0.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.github.docker-java/docker-java-api/3.4.0, Apache-2.0, approved, clearlydefined
Expand All @@ -61,9 +62,10 @@ maven/mavencentral/com.google.guava/guava/28.1-android, Apache-2.0, approved, cl
maven/mavencentral/com.google.guava/guava/28.2-android, Apache-2.0 AND LicenseRef-Public-Domain, approved, CQ22437
maven/mavencentral/com.google.guava/guava/31.0.1-android, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.guava/guava/31.1-jre, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.google.guava/guava/33.3.0-jre, Apache-2.0 AND CC0-1.0 AND (Apache-2.0 AND CC-PDDC) AND (Apache-2.0 AND CC0-1.0), approved, #15952
maven/mavencentral/com.google.guava/guava/33.3.1-jre, Apache-2.0 AND CC0-1.0 AND (Apache-2.0 AND CC-PDDC) AND (Apache-2.0 AND CC0-1.0), approved, #15952
maven/mavencentral/com.google.guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava, Apache-2.0, approved, CQ22657
maven/mavencentral/com.google.j2objc/j2objc-annotations/1.3, Apache-2.0, approved, CQ21195
maven/mavencentral/com.google.j2objc/j2objc-annotations/3.0.0, Apache-2.0, approved, #13676
maven/mavencentral/com.google.protobuf/protobuf-java/3.25.3, BSD-3-Clause, approved, clearlydefined
maven/mavencentral/com.googlecode.libphonenumber/libphonenumber/8.11.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.jayway.jsonpath/json-path/2.7.0, Apache-2.0, approved, clearlydefined
Expand All @@ -72,7 +74,8 @@ maven/mavencentral/com.lmax/disruptor/3.4.4, Apache-2.0, approved, clearlydefine
maven/mavencentral/com.networknt/json-schema-validator/1.0.76, Apache-2.0, approved, CQ22638
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.28, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.41.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.18.1, LGPL-2.1-or-later AND (Apache-2.0 AND LGPL-2.1-or-later) AND Apache-2.0, approved, #16060
maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.41.2, , restricted, clearlydefined
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.18.2, LGPL-2.1-or-later AND (Apache-2.0 AND LGPL-2.1-or-later) AND Apache-2.0, approved, #16060
maven/mavencentral/com.samskivert/jmustache/1.15, BSD-2-Clause AND BSD-3-Clause, approved, clearlydefined
maven/mavencentral/com.squareup.okhttp3/okhttp-dnsoverhttps/4.12.0, Apache-2.0, approved, #11159
maven/mavencentral/com.squareup.okhttp3/okhttp/4.12.0, Apache-2.0, approved, #15227
Expand Down Expand Up @@ -173,10 +176,10 @@ maven/mavencentral/javax.ws.rs/javax.ws.rs-api/2.1, (CDDL-1.1 OR GPL-2.0 WITH Cl
maven/mavencentral/joda-time/joda-time/2.10.5, Apache-2.0, approved, clearlydefined
maven/mavencentral/junit/junit/4.13.2, EPL-2.0, approved, CQ23636
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.14.1, Apache-2.0, approved, #7164
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.15.0, Apache-2.0, approved, #16009
maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.15.2, Apache-2.0, approved, #16009
maven/mavencentral/net.bytebuddy/byte-buddy/1.14.1, Apache-2.0 AND BSD-3-Clause, approved, #7163
maven/mavencentral/net.bytebuddy/byte-buddy/1.14.18, Apache-2.0 AND BSD-3-Clause, approved, #7163
maven/mavencentral/net.bytebuddy/byte-buddy/1.15.0, Apache-2.0 AND BSD-3-Clause, approved, #16008
maven/mavencentral/net.bytebuddy/byte-buddy/1.15.2, Apache-2.0 AND BSD-3-Clause, approved, #16008
maven/mavencentral/net.java.dev.jna/jna/5.13.0, Apache-2.0 AND LGPL-2.1-or-later, approved, #15196
maven/mavencentral/net.javacrumbs.json-unit/json-unit-core/2.36.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/net.minidev/accessors-smart/2.4.7, Apache-2.0, approved, #7515
Expand Down Expand Up @@ -227,7 +230,7 @@ maven/mavencentral/org.bouncycastle/bcutil-jdk18on/1.78.1, MIT, approved, #14435
maven/mavencentral/org.ccil.cowan.tagsoup/tagsoup/1.2.1, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.checkerframework/checker-qual/3.12.0, MIT, approved, clearlydefined
maven/mavencentral/org.checkerframework/checker-qual/3.42.0, MIT, approved, clearlydefined
maven/mavencentral/org.checkerframework/checker-qual/3.46.0, MIT, approved, clearlydefined
maven/mavencentral/org.checkerframework/checker-qual/3.47.0, MIT, approved, clearlydefined
maven/mavencentral/org.codehaus.plexus/plexus-classworlds/2.6.0, Apache-2.0 AND Plexus, approved, CQ22821
maven/mavencentral/org.codehaus.plexus/plexus-component-annotations/2.1.0, Apache-2.0, approved, #809
maven/mavencentral/org.codehaus.plexus/plexus-container-default/2.1.0, Apache-2.0, approved, clearlydefined
Expand Down Expand Up @@ -371,7 +374,7 @@ maven/mavencentral/org.jvnet.mimepull/mimepull/1.9.15, CDDL-1.1 OR GPL-2.0-only
maven/mavencentral/org.mock-server/mockserver-client-java/5.15.0, Apache-2.0 AND LGPL-3.0-only, approved, #9324
maven/mavencentral/org.mock-server/mockserver-core/5.15.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.mock-server/mockserver-netty/5.15.0, Apache-2.0, approved, #9276
maven/mavencentral/org.mockito/mockito-core/5.13.0, MIT, approved, clearlydefined
maven/mavencentral/org.mockito/mockito-core/5.14.0, MIT AND (Apache-2.0 AND MIT) AND Apache-2.0, approved, #16375
maven/mavencentral/org.mockito/mockito-core/5.2.0, MIT AND (Apache-2.0 AND MIT) AND Apache-2.0, approved, #7401
maven/mavencentral/org.mozilla/rhino/1.7.7.2, MPL-2.0 AND BSD-3-Clause AND ISC, approved, CQ16320
maven/mavencentral/org.objenesis/objenesis/3.3, Apache-2.0, approved, clearlydefined
Expand All @@ -392,10 +395,15 @@ maven/mavencentral/org.slf4j/slf4j-api/1.7.36, MIT, approved, CQ13368
maven/mavencentral/org.slf4j/slf4j-api/2.0.6, MIT, approved, #5915
maven/mavencentral/org.slf4j/slf4j-api/2.0.9, MIT, approved, #5915
maven/mavencentral/org.testcontainers/database-commons/1.20.1, MIT, approved, clearlydefined
maven/mavencentral/org.testcontainers/database-commons/1.20.2, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/jdbc/1.20.1, MIT, approved, clearlydefined
maven/mavencentral/org.testcontainers/jdbc/1.20.2, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/junit-jupiter/1.20.1, MIT, approved, clearlydefined
maven/mavencentral/org.testcontainers/junit-jupiter/1.20.2, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/postgresql/1.20.1, MIT, approved, clearlydefined
maven/mavencentral/org.testcontainers/postgresql/1.20.2, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/testcontainers/1.20.1, MIT, approved, #15747
maven/mavencentral/org.testcontainers/testcontainers/1.20.2, MIT, approved, #15747
maven/mavencentral/org.xmlresolver/xmlresolver/5.2.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.xmlunit/xmlunit-core/2.9.1, Apache-2.0, approved, #6272
maven/mavencentral/org.xmlunit/xmlunit-placeholders/2.9.1, Apache-2.0, approved, clearlydefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import static io.restassured.http.ContentType.JSON;
import static java.util.stream.IntStream.range;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.identityhub.spi.participantcontext.AccountProvisioner.CLIENT_SECRET_PROPERTY;
import static org.eclipse.edc.identityhub.tests.fixtures.IdentityHubEndToEndTestContext.SUPER_USER;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -197,6 +198,32 @@ void createNewUser_whenKeyPairActive(IdentityHubEndToEndTestContext context, Eve

}

@Test
void createNewUser_withCustomSecretAlias(IdentityHubEndToEndTestContext context, Vault vault) {
var apikey = context.createSuperUser();

var participantId = UUID.randomUUID().toString();
var manifest = context.createNewParticipant()
.participantId(participantId)
.active(true)
.did("did:web:" + participantId)
.key(context.createKeyDescriptor().active(true).build())
.property(CLIENT_SECRET_PROPERTY, "test-alias")
.build();

context.getIdentityApiEndpoint().baseRequest()
.header(new Header("x-api-key", apikey))
.contentType(ContentType.JSON)
.body(manifest)
.post("/v1alpha/participants/")
.then()
.log().ifError()
.statusCode(anyOf(equalTo(200), equalTo(204)))
.body(notNullValue());

assertThat(vault.resolveSecret("test-alias")).isNotNull();
}

@Test
void createNewUser_whenKeyPairNotActive(IdentityHubEndToEndTestContext context, EventRouter router) {
var subscriber = mock(EventSubscriber.class);
Expand Down Expand Up @@ -304,7 +331,6 @@ void createNewUser_whenDidAlreadyExists_expect409(IdentityHubEndToEndTestContext
verify(subscriber, never()).on(argThat(env -> ((ParticipantContextCreated) env.getPayload()).getParticipantId().equals(manifest.getParticipantId())));
}


@Test
void createNewUser_andNotActive_shouldNotPublishDid(IdentityHubEndToEndTestContext context, DidResourceStore didResourceStore, DidDocumentPublisherRegistry publisherRegistry) {
var apikey = context.createSuperUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"version": "1.0.0-alpha",
"urlPath": "/v1alpha",
"lastUpdated": "2024-09-11T08:00:00Z",
"lastUpdated": "2024-10-02T12:00:00Z",
"maturity": null
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import java.util.Objects;

import static java.util.Optional.ofNullable;

/**
* AccountProvisioner, that synchronizes the {@link org.eclipse.edc.identityhub.spi.participantcontext.model.ParticipantContext} object
* to {@link StsAccount} entries. That means, when a participant is created, this provisioner takes care of creating a corresponding
Expand Down Expand Up @@ -81,7 +83,9 @@ public <E extends Event> void on(EventEnvelope<E> event) {
@Override
public ServiceResult<AccountInfo> create(ParticipantManifest manifest) {
return transactionContext.execute(() -> {
var secretAlias = manifest.getParticipantId() + "-sts-client-secret";
var secretAlias = ofNullable(manifest.getProperty(CLIENT_SECRET_PROPERTY))
.map(Object::toString)
.orElseGet(() -> manifest.getParticipantId() + "-sts-client-secret");

var client = StsAccount.Builder.newInstance()
.id(manifest.getParticipantId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.edc.identityhub.spi.keypair.events.KeyPairRevoked;
import org.eclipse.edc.identityhub.spi.keypair.events.KeyPairRotated;
import org.eclipse.edc.identityhub.spi.keypair.model.KeyPairResource;
import org.eclipse.edc.identityhub.spi.participantcontext.AccountProvisioner;
import org.eclipse.edc.identityhub.spi.participantcontext.events.ParticipantContextDeleted;
import org.eclipse.edc.identityhub.spi.participantcontext.model.KeyDescriptor;
import org.eclipse.edc.identityhub.spi.participantcontext.model.ParticipantManifest;
Expand All @@ -40,6 +41,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -68,10 +70,28 @@ void create() {
assertThat(accountProvisioner.create(createManifest().build())).isSucceeded();

verify(stsAccountStore).create(any());
verify(vault).storeSecret(anyString(), argThat(secret -> UUID.fromString(secret) != null));
verify(vault).storeSecret(anyString(), argThat(secret -> {
UUID.fromString(secret);
return true;
}));
verifyNoInteractions(keyPairService, didDocumentService);
}

@Test
void create_withCustomSecretAlias() {
when(stsAccountStore.create(any())).thenReturn(StoreResult.success(createStsClient().build()));
when(vault.storeSecret(anyString(), anyString())).thenReturn(Result.success());

assertThat(accountProvisioner.create(createManifest()
.property(AccountProvisioner.CLIENT_SECRET_PROPERTY, "test-alias")
.build())).isSucceeded();

verify(stsAccountStore).create(any());
verify(vault).storeSecret(eq("test-alias"), anyString());
verifyNoInteractions(keyPairService, didDocumentService);
verifyNoMoreInteractions(vault);
}

@Test
void create_whenClientAlreadyExists() {
when(stsAccountStore.create(any())).thenReturn(StoreResult.alreadyExists("foo"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
import org.eclipse.edc.spi.result.ServiceResult;

public interface AccountProvisioner {
String CLIENT_SECRET_PROPERTY = "clientSecret";

ServiceResult<AccountInfo> create(ParticipantManifest manifest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
import org.eclipse.edc.iam.did.spi.document.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Manifest (=recipe) for creating the {@link ParticipantContext}.
*/
@JsonDeserialize(builder = ParticipantManifest.Builder.class)
public class ParticipantManifest {
private Map<String, Object> additionalProperties = new HashMap<>();
private List<String> roles = new ArrayList<>();
private Set<Service> serviceEndpoints = new HashSet<>();
private boolean isActive;
Expand All @@ -39,6 +42,10 @@ public class ParticipantManifest {
private ParticipantManifest() {
}

public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}

/**
* An optional list of service endpoints that should get published in the DID document, e.g. resolution endpoints, storage endpoints, etc.
*/
Expand Down Expand Up @@ -80,6 +87,10 @@ public List<String> getRoles() {
return roles;
}

public Object getProperty(String key) {
return additionalProperties.get(key);
}

@JsonPOJOBuilder(withPrefix = "")
public static final class Builder {

Expand Down Expand Up @@ -129,6 +140,16 @@ public Builder did(String did) {
return this;
}

public Builder property(String key, Object value) {
manifest.additionalProperties.put(key, value);
return this;
}

public Builder additionalProperties(Map<String, Object> properties) {
manifest.additionalProperties = properties;
return this;
}

public ParticipantManifest build() {
return manifest;
}
Expand Down

0 comments on commit 634deb0

Please sign in to comment.