1414
1515package org .eclipse .edc .virtualized .dataplane .cert ;
1616
17- import org .eclipse .edc .connector .dataplane .iam .service .DataPlaneAuthorizationServiceImpl ;
18- import org .eclipse .edc .connector .dataplane .spi .Endpoint ;
19- import org .eclipse .edc .connector .dataplane .spi .edr .EndpointDataReferenceServiceRegistry ;
20- import org .eclipse .edc .connector .dataplane .spi .iam .DataPlaneAuthorizationService ;
21- import org .eclipse .edc .connector .dataplane .spi .iam .PublicEndpointGeneratorService ;
17+ import org .eclipse .edc .api .authentication .JwksResolver ;
18+ import org .eclipse .edc .api .authentication .filter .JwtValidatorFilter ;
19+ import org .eclipse .edc .keys .spi .KeyParserRegistry ;
2220import org .eclipse .edc .runtime .metamodel .annotation .Configuration ;
2321import org .eclipse .edc .runtime .metamodel .annotation .Extension ;
2422import org .eclipse .edc .runtime .metamodel .annotation .Inject ;
2523import org .eclipse .edc .runtime .metamodel .annotation .Setting ;
2624import org .eclipse .edc .runtime .metamodel .annotation .Settings ;
25+ import org .eclipse .edc .spi .EdcException ;
2726import org .eclipse .edc .spi .system .Hostname ;
2827import org .eclipse .edc .spi .system .ServiceExtension ;
2928import org .eclipse .edc .spi .system .ServiceExtensionContext ;
29+ import org .eclipse .edc .token .rules .ExpirationIssuedAtValidationRule ;
30+ import org .eclipse .edc .token .rules .IssuerEqualsValidationRule ;
31+ import org .eclipse .edc .token .rules .NotBeforeValidationRule ;
32+ import org .eclipse .edc .token .spi .TokenValidationRule ;
33+ import org .eclipse .edc .token .spi .TokenValidationService ;
3034import org .eclipse .edc .transaction .spi .TransactionContext ;
3135import org .eclipse .edc .virtualized .dataplane .cert .api .CertExchangePublicController ;
3236import org .eclipse .edc .virtualized .dataplane .cert .api .CertInternalExchangeController ;
3539import org .eclipse .edc .web .spi .configuration .PortMapping ;
3640import org .eclipse .edc .web .spi .configuration .PortMappingRegistry ;
3741
42+ import java .net .MalformedURLException ;
43+ import java .net .URL ;
44+ import java .time .Clock ;
45+ import java .util .List ;
46+
3847import static org .eclipse .edc .virtualized .dataplane .cert .CertExchangeExtension .NAME ;
3948
4049@ Extension (NAME )
@@ -43,12 +52,7 @@ public class CertExchangeExtension implements ServiceExtension {
4352 public static final String API_CONTEXT = "certs" ;
4453 private static final int DEFAULT_CERTS_PORT = 8186 ;
4554 private static final String DEFAULT_CERTS_PATH = "/api/data" ;
46-
47-
48- @ Setting (description = "Base url of the public public API endpoint without the trailing slash. This should point to the public certs endpoint configured." ,
49- required = false ,
50- key = "edc.dataplane.api.certs.baseurl" , warnOnMissingConfig = true )
51- private String publicBaseUrl ;
55+ private static final long FIVE_MINUTES = 1000 * 60 * 5 ;
5256
5357 @ Configuration
5458 private CertApiConfiguration apiConfiguration ;
@@ -60,41 +64,54 @@ public class CertExchangeExtension implements ServiceExtension {
6064 private PortMappingRegistry portMappingRegistry ;
6165
6266 @ Inject
63- private DataPlaneAuthorizationService authorizationService ;
67+ private WebService webService ;
68+
6469 @ Inject
65- private PublicEndpointGeneratorService generatorService ;
70+ private CertStore certStore ;
6671
6772 @ Inject
68- private EndpointDataReferenceServiceRegistry endpointDataReferenceServiceRegistry ;
73+ private TransactionContext transactionContext ;
6974
7075 @ Inject
71- private WebService webService ;
76+ private TokenValidationService tokenValidationService ;
77+
78+ @ Configuration
79+ private SigletConfig sigletConfig ;
7280
7381 @ Inject
74- private CertStore certStore ;
82+ private KeyParserRegistry keyParserRegistry ;
7583
7684 @ Inject
77- private TransactionContext transactionContext ;
85+ private Clock clock ;
7886
7987 @ Override
8088 public void initialize (ServiceExtensionContext context ) {
8189 var portMapping = new PortMapping (API_CONTEXT , apiConfiguration .port (), apiConfiguration .path ());
8290 portMappingRegistry .register (portMapping );
8391
84- if (publicBaseUrl == null ) {
85- publicBaseUrl = "http://%s:%d%s" .formatted (hostname .get (), portMapping .port (), portMapping .path ());
86- context .getMonitor ().warning ("The public API endpoint was not explicitly configured, the default '%s' will be used." .formatted (publicBaseUrl ));
92+ URL url ;
93+ try {
94+ url = new URL (sigletConfig .jwksUrl ());
95+ } catch (MalformedURLException e ) {
96+ throw new EdcException (e );
8797 }
88- var endpoint = Endpoint .url (publicBaseUrl );
89- generatorService .addGeneratorFunction ("HttpCertData" , dataAddress -> endpoint );
90- webService .registerResource (API_CONTEXT , new CertExchangePublicController (authorizationService , certStore , transactionContext ));
98+
99+ webService .registerResource (API_CONTEXT , new CertExchangePublicController (certStore , transactionContext ));
100+ webService .registerResource (API_CONTEXT , new JwtValidatorFilter (tokenValidationService , new JwksResolver (url , keyParserRegistry , sigletConfig .cacheValidityInMillis ), getRules ()));
101+
91102 webService .registerResource ("control" , new CertInternalExchangeController (certStore , transactionContext ));
92103
93- if (authorizationService instanceof DataPlaneAuthorizationServiceImpl dpAuthService ) {
94- endpointDataReferenceServiceRegistry .register ("HttpCertData" , dpAuthService );
95- }
96104 }
97105
106+ private List <TokenValidationRule > getRules () {
107+ return List .of (
108+ new IssuerEqualsValidationRule (sigletConfig .expectedIssuer ),
109+ new NotBeforeValidationRule (clock , 0 , true ),
110+ new ExpirationIssuedAtValidationRule (clock , 0 , false )
111+ );
112+ }
113+
114+
98115 @ Settings
99116 record CertApiConfiguration (
100117 @ Setting (key = "web.http." + API_CONTEXT + ".port" , description = "Port for " + API_CONTEXT + " api context" , defaultValue = DEFAULT_CERTS_PORT + "" )
@@ -104,4 +121,16 @@ record CertApiConfiguration(
104121 ) {
105122
106123 }
124+
125+ @ Settings
126+ record SigletConfig (
127+ @ Setting (key = "edc.iam.siglet.issuer" , description = "Issuer of the Siglet server" , required = false )
128+ String expectedIssuer ,
129+ @ Setting (key = "edc.iam.siglet.jwks.url" , description = "Absolute URL where the JWKS of the Siglet server is hosted" )
130+ String jwksUrl ,
131+ @ Setting (key = "edc.iam.siglet.jwks.cache.validity" , description = "Time (in ms) that cached JWKS are cached" , defaultValue = "" + FIVE_MINUTES )
132+ long cacheValidityInMillis
133+ ) {
134+
135+ }
107136}
0 commit comments