From 13e6bdeb70350693585e3ccec4686e00ed2d8ea2 Mon Sep 17 00:00:00 2001 From: Paul Latzelsperger <43503240+paullatzelsperger@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:17:37 +0100 Subject: [PATCH] feat: implement ParticipantContextEventCoordinator (#265) * renamed event listener impls to *EventPublisher * feat: implement ParticipantContextEventCoordinator * run ci * DEPENDENCIES --- .../did/DidDocumentServiceImpl.java | 11 +- .../identityhub/did/DidServicesExtension.java | 4 +- ...erImpl.java => KeyPairEventPublisher.java} | 4 +- .../keypairs/KeyPairServiceExtension.java | 8 +- .../keypairs/KeyPairServiceImpl.java | 9 +- .../ParticipantContextEventCoordinator.java | 73 +++++++++ ... => ParticipantContextEventPublisher.java} | 4 +- .../ParticipantContextExtension.java | 15 +- ...articipantContextEventCoordinatorTest.java | 152 ++++++++++++++++++ .../ParticipantContextApiEndToEndTest.java | 2 +- .../ParticipantContextCreated.java | 3 + .../participant/ParticipantContextEvent.java | 4 +- 12 files changed, 263 insertions(+), 26 deletions(-) rename core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/{KeyPairEventListenerImpl.java => KeyPairEventPublisher.java} (93%) create mode 100644 core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinator.java rename core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/{ParticipantContextListenerImpl.java => ParticipantContextEventPublisher.java} (93%) create mode 100644 core/identity-hub-participants/src/test/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinatorTest.java diff --git a/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidDocumentServiceImpl.java b/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidDocumentServiceImpl.java index 65a38e299..e07482b93 100644 --- a/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidDocumentServiceImpl.java +++ b/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidDocumentServiceImpl.java @@ -213,9 +213,8 @@ public ServiceResult removeService(String did, String serviceId) { @Override public void on(EventEnvelope eventEnvelope) { var payload = eventEnvelope.getPayload(); - if (payload instanceof ParticipantContextCreated event) { - created(event); - } else if (payload instanceof ParticipantContextUpdated event) { + monitor.debug("Received a [%s] event".formatted(payload.getClass().getSimpleName())); + if (payload instanceof ParticipantContextUpdated event) { updated(event); } else if (payload instanceof ParticipantContextDeleted event) { deleted(event); @@ -224,7 +223,7 @@ public void on(EventEnvelope eventEnvelope) { } else if (payload instanceof KeyPairRevoked event) { keypairRevoked(event); } else { - monitor.warning("KeyPairServiceImpl Received an event with unexpected payload type: %s".formatted(payload.getClass())); + monitor.warning("Received event with unexpected payload type: %s".formatted(payload.getClass())); } } @@ -246,6 +245,10 @@ private void keypairRevoked(KeyPairRevoked event) { private void keypairAdded(KeyPairAdded event) { var didResources = findByParticipantId(event.getParticipantId()); + if (didResources.isEmpty()) { + monitor.warning("No DidResources were found for participant '%s'. No updated will be performed.".formatted(event.getParticipantId())); + return; + } var serialized = event.getPublicKeySerialized(); var publicKey = keyParserRegistry.parse(serialized); diff --git a/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidServicesExtension.java b/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidServicesExtension.java index cedcb5bb4..f4d17639e 100644 --- a/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidServicesExtension.java +++ b/core/identity-hub-did/src/main/java/org/eclipse/edc/identityhub/did/DidServicesExtension.java @@ -19,7 +19,6 @@ import org.eclipse.edc.identithub.did.spi.store.DidResourceStore; import org.eclipse.edc.identityhub.spi.events.keypair.KeyPairAdded; import org.eclipse.edc.identityhub.spi.events.keypair.KeyPairRevoked; -import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextCreated; import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextDeleted; import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextUpdated; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -64,8 +63,7 @@ public DidDocumentPublisherRegistry getDidPublisherRegistry() { @Provider public DidDocumentService createDidDocumentService(ServiceExtensionContext context) { - var service = new DidDocumentServiceImpl(transactionContext, didResourceStore, getDidPublisherRegistry(), context.getMonitor(), keyParserRegistry); - eventRouter.registerSync(ParticipantContextCreated.class, service); + var service = new DidDocumentServiceImpl(transactionContext, didResourceStore, getDidPublisherRegistry(), context.getMonitor().withPrefix("DidDocumentService"), keyParserRegistry); eventRouter.registerSync(ParticipantContextUpdated.class, service); eventRouter.registerSync(ParticipantContextDeleted.class, service); eventRouter.registerSync(KeyPairAdded.class, service); diff --git a/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairEventListenerImpl.java b/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairEventPublisher.java similarity index 93% rename from core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairEventListenerImpl.java rename to core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairEventPublisher.java index 2edf947c0..ab3486250 100644 --- a/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairEventListenerImpl.java +++ b/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairEventPublisher.java @@ -25,11 +25,11 @@ import java.time.Clock; -public class KeyPairEventListenerImpl implements KeyPairEventListener { +public class KeyPairEventPublisher implements KeyPairEventListener { private final Clock clock; private final EventRouter eventRouter; - public KeyPairEventListenerImpl(Clock clock, EventRouter eventRouter) { + public KeyPairEventPublisher(Clock clock, EventRouter eventRouter) { this.clock = clock; this.eventRouter = eventRouter; } diff --git a/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceExtension.java b/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceExtension.java index 482bc894e..07c170fff 100644 --- a/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceExtension.java +++ b/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceExtension.java @@ -15,9 +15,7 @@ package org.eclipse.edc.identityhub.keypairs; import org.eclipse.edc.identityhub.spi.KeyPairService; -import org.eclipse.edc.identityhub.spi.events.diddocument.DidDocumentPublished; import org.eclipse.edc.identityhub.spi.events.keypair.KeyPairObservable; -import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextCreated; import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextDeleted; import org.eclipse.edc.identityhub.spi.store.KeyPairResourceStore; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -54,10 +52,8 @@ public String name() { @Provider public KeyPairService createParticipantService(ServiceExtensionContext context) { - var service = new KeyPairServiceImpl(keyPairResourceStore, vault, context.getMonitor(), keyPairObservable()); - eventRouter.registerSync(ParticipantContextCreated.class, service); + var service = new KeyPairServiceImpl(keyPairResourceStore, vault, context.getMonitor().withPrefix("KeyPairService"), keyPairObservable()); eventRouter.registerSync(ParticipantContextDeleted.class, service); - eventRouter.registerSync(DidDocumentPublished.class, service); return service; } @@ -65,7 +61,7 @@ public KeyPairService createParticipantService(ServiceExtensionContext context) public KeyPairObservable keyPairObservable() { if (observable == null) { observable = new KeyPairObservableImpl(); - observable.registerListener(new KeyPairEventListenerImpl(clock, eventRouter)); + observable.registerListener(new KeyPairEventPublisher(clock, eventRouter)); } return observable; } diff --git a/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceImpl.java b/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceImpl.java index 0c57d044e..21295dab6 100644 --- a/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceImpl.java +++ b/core/identity-hub-keypairs/src/main/java/org/eclipse/edc/identityhub/keypairs/KeyPairServiceImpl.java @@ -134,12 +134,11 @@ public ServiceResult> query(QuerySpec querySpec) { @Override public void on(EventEnvelope eventEnvelope) { var payload = eventEnvelope.getPayload(); - if (payload instanceof ParticipantContextCreated created) { - created(created); - } else if (payload instanceof ParticipantContextDeleted deleted) { + monitor.debug("Received a [%s] event".formatted(payload.getClass().getSimpleName())); + if (payload instanceof ParticipantContextDeleted deleted) { deleted(deleted); } else { - monitor.warning("KeyPairServiceImpl Received event with unexpected payload type: %s".formatted(payload.getClass())); + monitor.warning("Received event with unexpected payload type: %s".formatted(payload.getClass())); } } @@ -180,7 +179,7 @@ private Result generateOrGetKey(KeyDescriptor keyDescriptor) { if (keyPair.failed()) { return keyPair.mapTo(); } - var privateJwk = CryptoConverter.createJwk(keyPair.getContent()); + var privateJwk = CryptoConverter.createJwk(keyPair.getContent(), keyDescriptor.getKeyId()); publicKeySerialized = privateJwk.toPublicJWK().toJSONString(); vault.storeSecret(keyDescriptor.getPrivateKeyAlias(), privateJwk.toJSONString()); } else { diff --git a/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinator.java b/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinator.java new file mode 100644 index 000000000..6ce284aa1 --- /dev/null +++ b/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinator.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.edc.identityhub.participantcontext; + +import org.eclipse.edc.iam.did.spi.document.DidDocument; +import org.eclipse.edc.identithub.did.spi.DidDocumentService; +import org.eclipse.edc.identityhub.spi.KeyPairService; +import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextCreated; +import org.eclipse.edc.spi.event.Event; +import org.eclipse.edc.spi.event.EventEnvelope; +import org.eclipse.edc.spi.event.EventSubscriber; +import org.eclipse.edc.spi.monitor.Monitor; + +import static org.eclipse.edc.spi.result.ServiceResult.success; + +/** + * Coordinates {@link ParticipantContextCreated} events. More specifically, it coordinates the sequence, in which the following actions are performed: + *
    + *
  • Create DID Document
  • + *
  • Optional: publish DID document
  • + *
  • Add a KeyPair
  • + *
+ * To that end, the {@link ParticipantContextEventCoordinator} directly collaborates with the {@link KeyPairService} and the {@link DidDocumentService}. + *

+ * Please note that once this initial sequence is executed, every collaborator service emits their events as per their event contract. + * For example, once a KeyPair is added, the {@link KeyPairService} will emit a {@link org.eclipse.edc.identityhub.spi.events.keypair.KeyPairAdded} event. The {@link DidDocumentService} + * can then react to this event by updating the DID Document. + */ +public class ParticipantContextEventCoordinator implements EventSubscriber { + private final Monitor monitor; + private final DidDocumentService didDocumentService; + private final KeyPairService keyPairService; + + public ParticipantContextEventCoordinator(Monitor monitor, DidDocumentService didDocumentService, KeyPairService keyPairService) { + this.monitor = monitor; + this.didDocumentService = didDocumentService; + this.keyPairService = keyPairService; + } + + @Override + public void on(EventEnvelope event) { + var payload = event.getPayload(); + if (payload instanceof ParticipantContextCreated createdEvent) { + var manifest = createdEvent.getManifest(); + var doc = DidDocument.Builder.newInstance() + .id(manifest.getDid()) + .service(manifest.getServiceEndpoints().stream().toList()) + // updating and adding a verification method happens as a result of the KeyPairAddedEvent + .build(); + + didDocumentService.store(doc, manifest.getParticipantId()) + .compose(u -> manifest.isActive() ? didDocumentService.publish(doc.getId()) : success()) + // adding the keypair event will cause the DidDocumentService to update the DID. + .compose(u -> keyPairService.addKeyPair(createdEvent.getParticipantId(), createdEvent.getManifest().getKey(), true)) + .onFailure(f -> monitor.warning("%s".formatted(f.getFailureDetail()))); + + } else { + monitor.warning("Received event with unexpected payload type: %s".formatted(payload.getClass())); + } + } +} diff --git a/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextListenerImpl.java b/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventPublisher.java similarity index 93% rename from core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextListenerImpl.java rename to core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventPublisher.java index c003c145d..d4320b628 100644 --- a/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextListenerImpl.java +++ b/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventPublisher.java @@ -26,11 +26,11 @@ import java.time.Clock; -public class ParticipantContextListenerImpl implements ParticipantContextListener { +public class ParticipantContextEventPublisher implements ParticipantContextListener { private final Clock clock; private final EventRouter eventRouter; - public ParticipantContextListenerImpl(Clock clock, EventRouter eventRouter) { + public ParticipantContextEventPublisher(Clock clock, EventRouter eventRouter) { this.clock = clock; this.eventRouter = eventRouter; } diff --git a/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextExtension.java b/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextExtension.java index f1fd34dc1..05d90c2f2 100644 --- a/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextExtension.java +++ b/core/identity-hub-participants/src/main/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextExtension.java @@ -15,7 +15,9 @@ package org.eclipse.edc.identityhub.participantcontext; import org.eclipse.edc.identithub.did.spi.DidDocumentService; +import org.eclipse.edc.identityhub.spi.KeyPairService; import org.eclipse.edc.identityhub.spi.ParticipantContextService; +import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextCreated; import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextObservable; import org.eclipse.edc.identityhub.spi.store.ParticipantContextStore; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -25,6 +27,7 @@ import org.eclipse.edc.spi.security.KeyParserRegistry; import org.eclipse.edc.spi.security.Vault; import org.eclipse.edc.spi.system.ServiceExtension; +import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.transaction.spi.TransactionContext; import java.time.Clock; @@ -46,6 +49,8 @@ public class ParticipantContextExtension implements ServiceExtension { @Inject private DidDocumentService didDocumentService; @Inject + private KeyPairService keyPairService; + @Inject private Clock clock; @Inject private EventRouter eventRouter; @@ -57,6 +62,14 @@ public String name() { return NAME; } + @Override + public void initialize(ServiceExtensionContext context) { + var coordinator = new ParticipantContextEventCoordinator(context.getMonitor().withPrefix("ParticipantContextEventCoordinator"), + didDocumentService, keyPairService); + + eventRouter.registerSync(ParticipantContextCreated.class, coordinator); + } + @Provider public ParticipantContextService createParticipantService() { return new ParticipantContextServiceImpl(participantContextStore, vault, transactionContext, participantContextObservable()); @@ -66,7 +79,7 @@ public ParticipantContextService createParticipantService() { public ParticipantContextObservable participantContextObservable() { if (participantContextObservable == null) { participantContextObservable = new ParticipantContextObservableImpl(); - participantContextObservable.registerListener(new ParticipantContextListenerImpl(clock, eventRouter)); + participantContextObservable.registerListener(new ParticipantContextEventPublisher(clock, eventRouter)); } return participantContextObservable; } diff --git a/core/identity-hub-participants/src/test/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinatorTest.java b/core/identity-hub-participants/src/test/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinatorTest.java new file mode 100644 index 000000000..92d9aa197 --- /dev/null +++ b/core/identity-hub-participants/src/test/java/org/eclipse/edc/identityhub/participantcontext/ParticipantContextEventCoordinatorTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2024 Metaform Systems, Inc. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Metaform Systems, Inc. - initial API and implementation + * + */ + +package org.eclipse.edc.identityhub.participantcontext; + +import org.eclipse.edc.identithub.did.spi.DidDocumentService; +import org.eclipse.edc.identityhub.spi.KeyPairService; +import org.eclipse.edc.identityhub.spi.events.participant.ParticipantContextCreated; +import org.eclipse.edc.identityhub.spi.model.participant.KeyDescriptor; +import org.eclipse.edc.identityhub.spi.model.participant.ParticipantManifest; +import org.eclipse.edc.spi.event.Event; +import org.eclipse.edc.spi.event.EventEnvelope; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.spi.result.ServiceResult; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; + +import java.time.Instant; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +class ParticipantContextEventCoordinatorTest { + private final Monitor monitor = mock(); + private final DidDocumentService didDocumentService = mock(); + private final KeyPairService keyPairService = mock(); + private final ParticipantContextEventCoordinator coordinator = new ParticipantContextEventCoordinator(monitor, didDocumentService, keyPairService); + + @Test + void onParticipantCreated() { + var participantId = "test-id"; + when(didDocumentService.store(any(), eq(participantId))).thenReturn(ServiceResult.success()); + when(didDocumentService.publish(anyString())).thenReturn(ServiceResult.success()); + when(keyPairService.addKeyPair(eq(participantId), any(), anyBoolean())).thenReturn(ServiceResult.success()); + + coordinator.on(envelope(ParticipantContextCreated.Builder.newInstance() + .participantId(participantId) + .manifest(createManifest().build()) + .build())); + + verify(didDocumentService).store(any(), eq(participantId)); + verify(didDocumentService).publish(eq("did:web:" + participantId)); + verify(keyPairService).addKeyPair(eq(participantId), any(), eq(true)); + verifyNoMoreInteractions(keyPairService, didDocumentService, monitor); + } + + @Test + void onParticipantCreated_didDocumentServiceStoreFailure() { + var participantId = "test-id"; + when(didDocumentService.store(any(), eq(participantId))).thenReturn(ServiceResult.badRequest("foobar")); + + coordinator.on(envelope(ParticipantContextCreated.Builder.newInstance() + .participantId(participantId) + .manifest(createManifest().build()) + .build())); + + verify(didDocumentService).store(any(), eq(participantId)); + verify(monitor).warning("foobar"); + verifyNoMoreInteractions(keyPairService, didDocumentService); + } + + @Test + void onParticipantCreated_didDocumentServicePublishFailure() { + var participantId = "test-id"; + when(didDocumentService.store(any(), eq(participantId))).thenReturn(ServiceResult.success()); + when(didDocumentService.publish(anyString())).thenReturn(ServiceResult.badRequest("foobar")); + + coordinator.on(envelope(ParticipantContextCreated.Builder.newInstance() + .participantId(participantId) + .manifest(createManifest().build()) + .build())); + + verify(didDocumentService).store(any(), eq(participantId)); + verify(didDocumentService).publish(anyString()); + verify(monitor).warning("foobar"); + verifyNoMoreInteractions(keyPairService, didDocumentService); + } + + @Test + void onParticipantCreated_keyPairServiceFailure() { + var participantId = "test-id"; + when(didDocumentService.store(any(), eq(participantId))).thenReturn(ServiceResult.success()); + when(didDocumentService.publish(anyString())).thenReturn(ServiceResult.success()); + when(keyPairService.addKeyPair(eq(participantId), any(), anyBoolean())).thenReturn(ServiceResult.notFound("foobar")); + + coordinator.on(envelope(ParticipantContextCreated.Builder.newInstance() + .participantId(participantId) + .manifest(createManifest().build()) + .build())); + + verify(didDocumentService).store(any(), eq(participantId)); + verify(didDocumentService).publish(eq("did:web:" + participantId)); + verify(keyPairService).addKeyPair(eq(participantId), any(), eq(true)); + verify(monitor).warning("foobar"); + verifyNoMoreInteractions(keyPairService, didDocumentService); + } + + @Test + void onOtherEvent_expectWarning() { + coordinator.on(envelope(new Event() { + @Override + public String name() { + return "another.event"; + } + })); + + verify(monitor).warning(startsWith("Received event with unexpected payload type:")); + verifyNoMoreInteractions(monitor, didDocumentService, keyPairService); + } + + @SuppressWarnings("unchecked") + private EventEnvelope envelope(Event event) { + return EventEnvelope.Builder.newInstance() + .at(Instant.now().toEpochMilli()) + .payload(event) + .build(); + } + + private ParticipantManifest.Builder createManifest() { + return ParticipantManifest.Builder.newInstance() + .key(createKey().build()) + .active(true) + .did("did:web:test-id") + .participantId("test-id"); + } + + @NotNull + private KeyDescriptor.Builder createKey() { + return KeyDescriptor.Builder.newInstance().keyId("test-kie") + .privateKeyAlias("private-alias") + .keyGeneratorParams(Map.of("algorithm", "EC")); + } +} \ No newline at end of file diff --git a/e2e-tests/api-tests/src/test/java/org/eclipse/edc/identityhub/tests/ParticipantContextApiEndToEndTest.java b/e2e-tests/api-tests/src/test/java/org/eclipse/edc/identityhub/tests/ParticipantContextApiEndToEndTest.java index 2b18c688c..d50426e53 100644 --- a/e2e-tests/api-tests/src/test/java/org/eclipse/edc/identityhub/tests/ParticipantContextApiEndToEndTest.java +++ b/e2e-tests/api-tests/src/test/java/org/eclipse/edc/identityhub/tests/ParticipantContextApiEndToEndTest.java @@ -112,7 +112,7 @@ void createNewUser_principalIsSuperser() { @Test - void createNewUser_principalIsNotSuperser_expect403() { + void createNewUser_principalIsNotSuperuser_expect403() { var subscriber = mock(EventSubscriber.class); getService(EventRouter.class).registerSync(ParticipantContextCreated.class, subscriber); diff --git a/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextCreated.java b/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextCreated.java index e1de53e59..84b4f94b5 100644 --- a/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextCreated.java +++ b/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextCreated.java @@ -26,6 +26,9 @@ public class ParticipantContextCreated extends ParticipantContextEvent { private ParticipantManifest manifest; + private ParticipantContextCreated() { + } + @Override public String name() { return "participantcontext.created"; diff --git a/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextEvent.java b/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextEvent.java index bdcb0c303..97cc43d5d 100644 --- a/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextEvent.java +++ b/spi/identity-hub-spi/src/main/java/org/eclipse/edc/identityhub/spi/events/participant/ParticipantContextEvent.java @@ -38,8 +38,8 @@ protected Builder(T event) { public abstract B self(); - public B participantId(String assetId) { - event.participantId = assetId; + public B participantId(String participantId) { + event.participantId = participantId; return self(); }