Skip to content

Commit 41ad3b4

Browse files
committed
Allow null configurations. Add verify endpoint.
1 parent 73ea306 commit 41ad3b4

14 files changed

Lines changed: 145 additions & 58 deletions

File tree

federated-catalog/resources/configuration/fc-configuration.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,3 @@ edc.dataplane.api.public.baseurl=http://localhost:39291/public
3838
# Configuración de la base de datos MongoDB
3939
org.eclipse.edc.heleade.federated.catalog.extension.store.mongodb.uri = mongodb://localhost:27017/
4040
org.eclipse.edc.heleade.federated.catalog.extension.store.mongodb.db = federatedcatalogdb
41-
edc.participant.claims=deployment/assets/consumer/creds.json
42-
edc.participant.private.key=deployment/assets/consumer/ed25519_private.pem

federated-catalog/resources/configuration/fc-docker-configuration.properties

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ edc.catalog.cache.execution.delay.seconds=10
3434
edc.catalog.cache.execution.period.seconds=10
3535
edc.catalog.cache.partition.num.crawlers=1
3636

37-
# Configuración de la base de datos MongoDB
37+
# Configuraci�n de la base de datos MongoDB
3838
org.eclipse.edc.heleade.federated.catalog.extension.store.mongodb.uri = mongodb://fc-mongodb:27017/
3939
org.eclipse.edc.heleade.federated.catalog.extension.store.mongodb.db = federatedcatalogdb
4040

41-
#claims
42-
edc.participant.claims=identity/creds.json
43-
edc.participant.private.key=identity/ed25519_private.pem

iam-identity/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ plugins {
1919
dependencies {
2020
api(libs.edc.data.plane.spi)
2121
api(libs.edc.json.ld.spi)
22+
implementation(libs.jakarta.rsApi)
2223
implementation(libs.edc.control.plane.core)
24+
implementation(libs.edc.http)
2325

2426
}

iam-identity/src/main/java/org/eclipse/edc/identity/extension/IamIdentityExtension.java renamed to iam-identity/src/main/java/org/eclipse/edc/identity/IamIdentityExtension.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
*
1313
*/
1414

15-
package org.eclipse.edc.identity.extension;
15+
package org.eclipse.edc.identity;
1616

17+
import org.eclipse.edc.identity.api.IamIdentityApiController;
18+
import org.eclipse.edc.identity.load.FileParticipantIdentityLoader;
19+
import org.eclipse.edc.identity.load.ParticipantIdentityLoader;
1720
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
1821
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
1922
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
@@ -24,10 +27,12 @@
2427
import org.eclipse.edc.spi.system.ServiceExtension;
2528
import org.eclipse.edc.spi.system.ServiceExtensionContext;
2629
import org.eclipse.edc.spi.types.TypeManager;
30+
import org.eclipse.edc.web.spi.WebService;
2731

2832
import java.security.PrivateKey;
2933
import java.security.PublicKey;
3034
import java.util.Base64;
35+
import java.util.Map;
3136

3237
/**
3338
* The {@code IamIdentityExtension} class is a service extension that integrates an IAM-based
@@ -71,31 +76,39 @@ public void initialize(ServiceExtensionContext context) {
7176
var monitor = context.getMonitor();
7277
monitor.info("Initializing iam-identity extension");
7378

74-
var claimsPath = context.getConfig().getString("edc.participant.claims");
75-
var participantPrivateKeyPath = context.getConfig().getString("edc.participant.private.key");
76-
var participantPublicKeyPath = context.getConfig().getString("edc.participant.public.key");
77-
var participantRegistryUrl = context.getConfig().getString("edc.participant.registry.url");
78-
var participantId = context.getParticipantId();
79-
80-
ParticipantIdentityLoader loader = new FileParticipantIdentityLoader(monitor, typeManager.getMapper());
81-
var claims = loader.loadClaims(claimsPath);
8279

80+
var claimsPath = context.getConfig().getString("edc.participant.claims", null);
81+
var participantPrivateKeyPath = context.getConfig().getString("edc.participant.private.key", null);
82+
var participantPublicKeyPath = context.getConfig().getString("edc.participant.public.key", null);
83+
var participantRegistryUrl = context.getConfig().getString("edc.participant.registry.url", null);
84+
var participantId = context.getParticipantId();
8385

84-
PrivateKey participantPrivateKey = loader.loadPrivateKey(participantPrivateKeyPath);
85-
PublicKey participantPublicKey = loader.loadPublicKey(participantPublicKeyPath);
86-
String base64PublicKey = Base64.getEncoder().encodeToString(participantPublicKey.getEncoded());
87-
String signedClaims = loader.signClaims(claims, participantPrivateKey, monitor);
88-
boolean publicKeyMatchesPrivateKey = loader.publicKeyMatchesPrivateKey(participantPublicKey, participantPrivateKey);
8986

90-
if (publicKeyMatchesPrivateKey) {
91-
monitor.info("Private && Public keys has been successfully validated!");
92-
monitor.info("Claims has been successfully signed: " + signedClaims);
93-
monitor.info("Claims: " + claims);
94-
monitor.info("Public key: " + base64PublicKey);
95-
monitor.info("Participant registry url: " + participantRegistryUrl);
87+
ParticipantIdentityLoader loader = new FileParticipantIdentityLoader(monitor, typeManager.getMapper());
88+
boolean checkConfiguration = loader.checkConfigurations(claimsPath, participantRegistryUrl, participantPrivateKeyPath, participantPublicKeyPath);
89+
90+
Map<String, Object> claims = Map.of();
91+
String signedClaims = null;
92+
if (checkConfiguration) {
93+
claims = loader.loadClaims(claimsPath);
94+
PrivateKey participantPrivateKey = loader.loadPrivateKey(participantPrivateKeyPath);
95+
PublicKey participantPublicKey = loader.loadPublicKey(participantPublicKeyPath);
96+
String base64PublicKey = Base64.getEncoder().encodeToString(participantPublicKey.getEncoded());
97+
signedClaims = loader.signClaims(claims, participantPrivateKey, monitor);
98+
boolean publicKeyMatchesPrivateKey = loader.publicKeyMatchesPrivateKey(participantPublicKey, participantPrivateKey);
99+
100+
if (publicKeyMatchesPrivateKey) {
101+
monitor.info("Private && Public keys has been successfully validated!");
102+
monitor.info("Claims has been successfully signed: " + signedClaims);
103+
monitor.info("Claims: " + claims);
104+
monitor.info("Public key: " + base64PublicKey);
105+
monitor.info("Participant registry url: " + participantRegistryUrl);
106+
}
96107
}
97108

98109

110+
webService.registerResource(new IamIdentityApiController(context.getMonitor()));
111+
99112
context.registerService(
100113
IdentityService.class,
101114
new IamIdentityService(typeManager, claims, participantId, signedClaims));
@@ -110,4 +123,9 @@ public void initialize(ServiceExtensionContext context) {
110123
public AudienceResolver audienceResolver() {
111124
return (msg) -> Result.success(msg.getCounterPartyAddress());
112125
}
126+
127+
@Inject
128+
WebService webService;
129+
130+
113131
}

iam-identity/src/main/java/org/eclipse/edc/identity/extension/IamIdentityService.java renamed to iam-identity/src/main/java/org/eclipse/edc/identity/IamIdentityService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*/
1414

15-
package org.eclipse.edc.identity.extension;
15+
package org.eclipse.edc.identity;
1616
import org.eclipse.edc.spi.iam.ClaimToken;
1717
import org.eclipse.edc.spi.iam.IdentityService;
1818
import org.eclipse.edc.spi.iam.TokenParameters;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2025 Universidad de Alicante
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+
* MO - Universidad de Alicante - initial implementation
12+
*
13+
*/
14+
15+
package org.eclipse.edc.identity.api;
16+
17+
import jakarta.ws.rs.Consumes;
18+
import jakarta.ws.rs.GET;
19+
import jakarta.ws.rs.Path;
20+
import jakarta.ws.rs.Produces;
21+
import jakarta.ws.rs.core.MediaType;
22+
import org.eclipse.edc.spi.monitor.Monitor;
23+
24+
/**
25+
* Endpoint to validate the participant identity
26+
*/
27+
@Consumes({MediaType.APPLICATION_JSON})
28+
@Produces({MediaType.APPLICATION_JSON})
29+
@Path("/")
30+
public class IamIdentityApiController {
31+
32+
private final Monitor monitor;
33+
34+
/**
35+
* Instantiates the controller for the verify identity endpoint
36+
*
37+
* @param monitor logger object
38+
*/
39+
public IamIdentityApiController(Monitor monitor) {
40+
this.monitor = monitor;
41+
}
42+
43+
44+
/**
45+
* Defines the verify identity endpoint
46+
*
47+
* @return JSON response
48+
*/
49+
@GET
50+
@Path("/verify-identity")
51+
public String verify() {
52+
monitor.info("Verify received a health request");
53+
return "{\"response\":\"IdentityProvider: I'm alive!\"}";
54+
}
55+
}

iam-identity/src/main/java/org/eclipse/edc/identity/extension/FileParticipantIdentityLoader.java renamed to iam-identity/src/main/java/org/eclipse/edc/identity/load/FileParticipantIdentityLoader.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*/
1414

15-
package org.eclipse.edc.identity.extension;
15+
package org.eclipse.edc.identity.load;
1616

1717
import com.fasterxml.jackson.core.type.TypeReference;
1818
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -39,7 +39,7 @@
3939
* This implementation primarily works with JSON-encoded claims files and PEM-encoded
4040
* private keys in PKCS #8 format. It also provides logging for diagnostics and error handling.
4141
*/
42-
public class FileParticipantIdentityLoader implements ParticipantIdentityLoader {
42+
public class FileParticipantIdentityLoader implements ParticipantIdentityLoader {
4343
/**
4444
* An instance of {@link ObjectMapper} used for serializing and deserializing JSON data.
4545
* It is a core dependency for converting objects to JSON and vice versa during
@@ -82,7 +82,8 @@ public Map<String, Object> loadClaims(String path) {
8282
var file = new File(path);
8383
try {
8484
monitor.debug("Loading claims from: " + file.getAbsolutePath());
85-
return mapper.readValue(file, new TypeReference<Map<String, Object>>() {});
85+
return mapper.readValue(file, new TypeReference<Map<String, Object>>() {
86+
});
8687
} catch (Exception e) {
8788
monitor.severe("Error reading claims from file: " + file.getAbsolutePath(), e);
8889
return Map.of();
@@ -192,8 +193,32 @@ public boolean publicKeyMatchesPrivateKey(PublicKey publicKey, PrivateKey privat
192193
}
193194

194195

196+
public boolean checkConfigurations(String claimsPath, String participantRegistryUrl, String privateKeyPath, String publicKeyPath) {
195197

198+
boolean configurationOk = true;
196199

200+
if (claimsPath == null) {
201+
monitor.warning("edc.participant.claims is null");
202+
configurationOk = false;
203+
}
204+
205+
if (privateKeyPath == null) {
206+
monitor.warning("edc.participant.private.key is null");
207+
configurationOk = false;
208+
}
209+
210+
if (publicKeyPath == null) {
211+
monitor.warning("edc.participant.public.key is null");
212+
configurationOk = false;
213+
}
214+
215+
if (participantRegistryUrl == null) {
216+
monitor.warning("edc.participant.registry.url is null");
217+
configurationOk = false;
218+
}
219+
220+
return configurationOk;
221+
}
197222

198223

199224
}

iam-identity/src/main/java/org/eclipse/edc/identity/extension/ParticipantIdentityLoader.java renamed to iam-identity/src/main/java/org/eclipse/edc/identity/load/ParticipantIdentityLoader.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*/
1414

15-
package org.eclipse.edc.identity.extension;
15+
package org.eclipse.edc.identity.load;
1616

1717
import org.eclipse.edc.spi.monitor.Monitor;
1818

@@ -73,6 +73,16 @@ public interface ParticipantIdentityLoader {
7373
*/
7474
String signClaims(Map<String, Object> claims, PrivateKey privateKey, Monitor monitor);
7575

76-
76+
/**
77+
* Validates the configuration parameters required for participant identity loading and processing.
78+
* This method checks whether the given paths and URLs are valid and correctly specified.
79+
*
80+
* @param claimsPath the file path to the claims file
81+
* @param participantRegistryUrl the URL of the participant registry
82+
* @param privateKeyPath the file path to the private key file
83+
* @param publicKeyPath the file path to the public key file
84+
* @return true if the provided configurations are valid, false otherwise
85+
*/
86+
boolean checkConfigurations(String claimsPath, String participantRegistryUrl, String privateKeyPath, String publicKeyPath);
7787

7888
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
org.eclipse.edc.identity.extension.IamIdentityExtension
1+
org.eclipse.edc.identity.IamIdentityExtension

providers/policy/policy-evaluation/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ dependencies {
2323

2424
implementation(libs.edc.control.plane.core)
2525
implementation(project(":providers:policy:claims-checker"));
26-
26+
implementation(project(":iam-identity"));
2727

2828
}

0 commit comments

Comments
 (0)