Skip to content

Commit

Permalink
fix: add missing mapping of VerificationMethod type
Browse files Browse the repository at this point in the history
  • Loading branch information
bscholtes1A committed Feb 9, 2024
1 parent 13e6bde commit 7942d99
Show file tree
Hide file tree
Showing 25 changed files with 214 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ private void keypairAdded(KeyPairAdded event) {
.id(event.getKeyId())
.publicKeyJwk(jwk.toJSONObject())
.controller(dd.getDocument().getId())
.type(event.getType())
.build()))
.map(didResourceStore::update)
.filter(StoreResult::failed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public KeyPairEventPublisher(Clock clock, EventRouter eventRouter) {
}

@Override
public void added(KeyPairResource keyPair) {
public void added(KeyPairResource keyPair, String type) {
var event = KeyPairAdded.Builder.newInstance()
.participantId(keyPair.getParticipantId())
.keyId(keyPair.getId())
.publicKey(keyPair.getSerializedPublicKey())
.publicKey(keyPair.getSerializedPublicKey(), type)
.build();
publish(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public ServiceResult<Void> addKeyPair(String participantId, KeyDescriptor keyDes
.participantId(participantId)
.build();

return ServiceResult.from(keyPairResourceStore.create(newResource)).onSuccess(v -> observable.invokeForEach(l -> l.added(newResource)));
return ServiceResult.from(keyPairResourceStore.create(newResource))
.onSuccess(v -> observable.invokeForEach(l -> l.added(newResource, keyDescriptor.getType())));
}

@Override
Expand Down
1 change: 1 addition & 0 deletions extensions/api/did-mgmt-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
api(project(":spi:identity-hub-spi"))
api(project(":spi:identity-hub-did-spi"))
implementation(project(":extensions:api:identityhub-management-api-configuration"))
implementation(project(":extensions:api:identityhub-management-api-validators"))
implementation(libs.edc.spi.validator)
implementation(libs.edc.spi.web)
implementation(libs.edc.core.jerseyproviders)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`java-library`
`maven-publish`
}

dependencies {
api(libs.edc.spi.core)
api(project(":spi:identity-hub-spi"))
api(project(":spi:identity-hub-did-spi"))
implementation(libs.edc.util)

testImplementation(libs.edc.junit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
*
*/

package org.eclipse.edc.identityhub.api.participantcontext.v1.validation;
package org.eclipse.edc.identityhub.api.v1.validation;

import org.eclipse.edc.iam.did.spi.document.DidConstants;
import org.eclipse.edc.identityhub.spi.model.participant.KeyDescriptor;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.util.string.StringUtils;
import org.eclipse.edc.validator.spi.ValidationResult;
import org.eclipse.edc.validator.spi.Validator;
Expand All @@ -31,12 +33,20 @@
* <ul>
* <li>the {@code keyId} must not be null</li>
* <li>the {@code privateKeyAlias} must not be null</li>
* <li>if {@code type} is null or empty, then JsonWebKey2020 is used by default</li>
* <li>not all of {@code publicKeyPem}, {@code publicKeyJwk} and {@code keyGeneratorParams} must be null</li>
* <li>not both {@code publicKeyPem} and {@code publicKeyJwk} must be specified</li>
* <li>if {@code keyGeneratorParams} are specified, {@code publicKeyPem} and {@code publicKeyJwk} must be null</li>
* </ul>
*/
public class KeyDescriptorValidator implements Validator<KeyDescriptor> {

private final Monitor monitor;

public KeyDescriptorValidator(Monitor monitor) {
this.monitor = monitor;
}

@Override
public ValidationResult validate(KeyDescriptor input) {
if (input == null) {
Expand All @@ -47,6 +57,10 @@ public ValidationResult validate(KeyDescriptor input) {
return failure(violation("keyId cannot be null.", "keyId"));
}

if (!DidConstants.ALLOWED_VERIFICATION_TYPES.contains(input.getType())) {
monitor.warning("Provided type %s is not supported.");
}

if (StringUtils.isNullOrBlank(input.getPrivateKeyAlias())) {
return failure(violation("privateKeyAlias cannot be null.", "privateKeyAlias"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
*/

package org.eclipse.edc.identityhub.api.participantcontext.v1.validation;
package org.eclipse.edc.identityhub.api.v1.validation;

import org.eclipse.edc.identityhub.spi.model.participant.ParticipantManifest;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.util.string.StringUtils;
import org.eclipse.edc.validator.spi.ValidationResult;
import org.eclipse.edc.validator.spi.Validator;
Expand All @@ -24,7 +25,11 @@
import static org.eclipse.edc.validator.spi.Violation.violation;

public class ParticipantManifestValidator implements Validator<ParticipantManifest> {
private final KeyDescriptorValidator keyDescriptorValidator = new KeyDescriptorValidator();
private final KeyDescriptorValidator keyDescriptorValidator;

public ParticipantManifestValidator(Monitor monitor) {
this.keyDescriptorValidator = new KeyDescriptorValidator(monitor);
}

@Override
public ValidationResult validate(ParticipantManifest input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
*/

package org.eclipse.edc.identityhub.api.participantcontext.v1.validation;
package org.eclipse.edc.identityhub.api.v1.validation;

import org.eclipse.edc.identityhub.spi.model.participant.KeyDescriptor;
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.junit.jupiter.api.Test;

import java.util.Map;
Expand All @@ -23,7 +24,7 @@

class KeyDescriptorValidatorTest {

private final KeyDescriptorValidator validator = new KeyDescriptorValidator();
private final KeyDescriptorValidator validator = new KeyDescriptorValidator(new ConsoleMonitor());

@Test
void validate_success() {
Expand Down Expand Up @@ -110,6 +111,5 @@ void validate_publicKeyPemAndGeneratorParams() {
assertThat(validator.validate(descriptor)).isFailed()
.detail().isEqualTo("Either the public key is specified (PEM or JWK), or the generator params are provided, not both.");
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
*
*/

package org.eclipse.edc.identityhub.api.participantcontext.v1.validation;
package org.eclipse.edc.identityhub.api.v1.validation;

import org.eclipse.edc.iam.did.spi.document.Service;
import org.eclipse.edc.identityhub.spi.model.participant.KeyDescriptor;
import org.eclipse.edc.identityhub.spi.model.participant.ParticipantManifest;
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -29,7 +30,25 @@

class ParticipantManifestValidatorTest {

private final ParticipantManifestValidator validator = new ParticipantManifestValidator();
private final ParticipantManifestValidator validator = new ParticipantManifestValidator(new ConsoleMonitor());

@NotNull
private static ParticipantManifest.Builder createManifest() {
return ParticipantManifest.Builder.newInstance()
.serviceEndpoint(new Service("id", "type", "foobar"))
.active(true)
.did("did:web:test-did")
.participantId("test-id")
.key(createKeyDescriptor().build());
}

@NotNull
private static KeyDescriptor.Builder createKeyDescriptor() {
return KeyDescriptor.Builder.newInstance()
.keyId("key-id")
.privateKeyAlias("alias")
.publicKeyJwk(Map.of("foo", "bar"));
}

@Test
void validate_success() {
Expand Down Expand Up @@ -75,22 +94,4 @@ void validate_participantIdNull(String participantId) {
assertThat(validator.validate(manifest)).isFailed()
.detail().isEqualTo("participantId cannot be null or empty.");
}

@NotNull
private static ParticipantManifest.Builder createManifest() {
return ParticipantManifest.Builder.newInstance()
.serviceEndpoint(new Service("id", "type", "foobar"))
.active(true)
.did("did:web:test-did")
.participantId("test-id")
.key(createKeyDescriptor().build());
}

@NotNull
private static KeyDescriptor.Builder createKeyDescriptor() {
return KeyDescriptor.Builder.newInstance()
.keyId("key-id")
.privateKeyAlias("alias")
.publicKeyJwk(Map.of("foo", "bar"));
}
}
1 change: 1 addition & 0 deletions extensions/api/keypair-mgmt-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
api(project(":spi:identity-hub-spi"))
api(project(":spi:identity-hub-store-spi"))
implementation(project(":extensions:api:identityhub-management-api-configuration"))
implementation(project(":extensions:api:identityhub-management-api-validators"))
implementation(libs.edc.spi.web)
implementation(libs.edc.util)
implementation(libs.jakarta.rsApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
*
*/

package org.eclipse.edc.identityhub.api.verifiablecredentials;
package org.eclipse.edc.identityhub.api.keypair;

import org.eclipse.edc.identityhub.api.verifiablecredentials.v1.KeyPairResourceApiController;
import org.eclipse.edc.identityhub.api.keypair.v1.KeyPairResourceApiController;
import org.eclipse.edc.identityhub.api.v1.validation.KeyDescriptorValidator;
import org.eclipse.edc.identityhub.spi.AuthorizationService;
import org.eclipse.edc.identityhub.spi.KeyPairService;
import org.eclipse.edc.identityhub.spi.ManagementApiConfiguration;
Expand All @@ -23,13 +24,14 @@
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.query.Criterion;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.web.spi.WebService;

import static org.eclipse.edc.identityhub.api.verifiablecredentials.KeyPairResourceManagementApiExtension.NAME;
import static org.eclipse.edc.identityhub.api.keypair.KeyPairResourceManagementApiExtension.NAME;

@Extension(NAME)
public class KeyPairResourceManagementApiExtension implements ServiceExtension {
Expand All @@ -43,6 +45,8 @@ public class KeyPairResourceManagementApiExtension implements ServiceExtension {
private KeyPairService keyPairService;
@Inject
private AuthorizationService authorizationService;
@Inject
private Monitor monitor;

@Override
public String name() {
Expand All @@ -52,7 +56,7 @@ public String name() {
@Override
public void initialize(ServiceExtensionContext context) {
authorizationService.addLookupFunction(KeyPairResource.class, this::findById);
var controller = new KeyPairResourceApiController(authorizationService, keyPairService);
var controller = new KeyPairResourceApiController(authorizationService, keyPairService, new KeyDescriptorValidator(monitor));
webService.registerResource(managementApiConfiguration.getContextAlias(), controller);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package org.eclipse.edc.identityhub.api.verifiablecredentials.v1;
package org.eclipse.edc.identityhub.api.keypair.v1;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
Loading

0 comments on commit 7942d99

Please sign in to comment.