-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extensible trusted-issuer-registry (#3540)
* feat: add trusted issuer registry * introduce Issuer object * support issuer as ID or Object with id * Add trusted-issuer-registry to iatp-service * add test * added transformer tests * removed impossible test * fix tests
- Loading branch information
1 parent
4c7aa61
commit 9fbad3c
Showing
20 changed files
with
418 additions
and
68 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...re/src/main/java/org/eclipse/edc/iam/identitytrust/core/DefaultTrustedIssuerRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.iam.identitytrust.core; | ||
|
||
import org.eclipse.edc.identitytrust.TrustedIssuerRegistry; | ||
import org.eclipse.edc.identitytrust.model.Issuer; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Simple, memory-based implementation of a {@link TrustedIssuerRegistry} | ||
*/ | ||
public class DefaultTrustedIssuerRegistry implements TrustedIssuerRegistry { | ||
private final Map<String, Issuer> store = new HashMap<>(); | ||
|
||
@Override | ||
public void addIssuer(Issuer issuer) { | ||
store.put(issuer.id(), issuer); | ||
} | ||
|
||
@Override | ||
public Issuer getById(String id) { | ||
return store.get(id); | ||
} | ||
|
||
@Override | ||
public Collection<Issuer> getTrustedIssuers() { | ||
return store.values(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...rc/test/java/org/eclipse/edc/iam/identitytrust/core/DefaultTrustedIssuerRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.iam.identitytrust.core; | ||
|
||
import org.eclipse.edc.identitytrust.model.Issuer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DefaultTrustedIssuerRegistryTest { | ||
|
||
private final DefaultTrustedIssuerRegistry registry = new DefaultTrustedIssuerRegistry(); | ||
|
||
@Test | ||
void addIssuer() { | ||
var issuer = new Issuer("test-id", Map.of()); | ||
registry.addIssuer(issuer); | ||
assertThat(registry.getTrustedIssuers()).containsExactly(issuer); | ||
} | ||
|
||
@Test | ||
void addIssuer_exists_shouldReplace() { | ||
var issuer = new Issuer("test-id", Map.of()); | ||
var issuer2 = new Issuer("test-id", Map.of("new-key", "new-val")); | ||
registry.addIssuer(issuer); | ||
registry.addIssuer(issuer2); | ||
assertThat(registry.getTrustedIssuers()).containsExactly(issuer2); | ||
} | ||
|
||
@Test | ||
void getById() { | ||
var issuer = new Issuer("test-id", Map.of()); | ||
registry.addIssuer(issuer); | ||
assertThat(registry.getById("test-id")).isEqualTo(issuer); | ||
} | ||
|
||
@Test | ||
void getById_notFound() { | ||
assertThat(registry.getById("nonexistent-id")).isNull(); | ||
} | ||
|
||
@Test | ||
void getTrustedIssuers() { | ||
var issuer = new Issuer("test-id", Map.of()); | ||
var issuer2 = new Issuer("test-id2", Map.of("new-key", "new-val")); | ||
registry.addIssuer(issuer); | ||
registry.addIssuer(issuer2); | ||
|
||
assertThat(registry.getTrustedIssuers()).containsExactlyInAnyOrder(issuer2, issuer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.