Skip to content

Commit

Permalink
feat: skeleton for jwks extension
Browse files Browse the repository at this point in the history
  • Loading branch information
efiege committed Nov 29, 2023
1 parent 6f595cc commit 5bbc05d
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
64 changes: 64 additions & 0 deletions extensions/jwks/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
val edcVersion: String by project
val edcGroup: String by project
val restAssured: String by project
val mockitoVersion: String by project
val lombokVersion: String by project
val jettyVersion: String by project
val jettyGroup: String by project

plugins {
`java-library`
`maven-publish`
}

dependencies {
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
compileOnly("org.projectlombok:lombok:${lombokVersion}")

api("${edcGroup}:core-spi:${edcVersion}")
api("${edcGroup}:control-plane-spi:${edcVersion}")
implementation("${edcGroup}:api-core:${edcVersion}")
implementation("${edcGroup}:management-api-configuration:${edcVersion}")

implementation("jakarta.ws.rs:jakarta.ws.rs-api:3.1.0")
implementation("jakarta.validation:jakarta.validation-api:3.0.2")

testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")

testImplementation("${edcGroup}:control-plane-core:${edcVersion}")
testImplementation("${edcGroup}:junit:${edcVersion}")
testImplementation("${edcGroup}:http:${edcVersion}") {
exclude(group = "org.eclipse.jetty", module = "jetty-client")
exclude(group = "org.eclipse.jetty", module = "jetty-http")
exclude(group = "org.eclipse.jetty", module = "jetty-io")
exclude(group = "org.eclipse.jetty", module = "jetty-server")
exclude(group = "org.eclipse.jetty", module = "jetty-util")
exclude(group = "org.eclipse.jetty", module = "jetty-webapp")
}

// Updated jetty versions for e.g. CVE-2023-26048
testImplementation("${jettyGroup}:jetty-client:${jettyVersion}")
testImplementation("${jettyGroup}:jetty-http:${jettyVersion}")
testImplementation("${jettyGroup}:jetty-io:${jettyVersion}")
testImplementation("${jettyGroup}:jetty-server:${jettyVersion}")
testImplementation("${jettyGroup}:jetty-util:${jettyVersion}")
testImplementation("${jettyGroup}:jetty-webapp:${jettyVersion}")

testImplementation("io.rest-assured:rest-assured:${restAssured}")
testImplementation("${edcGroup}:data-plane-selector-core:${edcVersion}")
testImplementation("org.mockito:mockito-core:${mockitoVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

val sovityEdcExtensionGroup: String by project
group = sovityEdcExtensionGroup

publishing {
publications {
create<MavenPublication>(project.name) {
from(components["java"])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 sovity GmbH
*
* 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:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.extension.jwks;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Produces({MediaType.APPLICATION_JSON})
@Path(JwksController.JWKS_PATH)
public class JwksController {

public static final String JWKS_PATH = "/jwks";


@GET
@Produces(MediaType.APPLICATION_JSON)
public String getLastCommitInfo() {
return "Hello World";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 sovity GmbH
*
* 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:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.extension.jwks;

import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.web.spi.WebService;

public class JwksExtension implements ServiceExtension {

public static final String EXTENSION_NAME = "JwksExtension";
@Inject
private WebService webService;

@Override
public String name() {
return EXTENSION_NAME;
}

@Override
public void initialize(ServiceExtensionContext context) {
var controller = new JwksController();
webService.registerResource(controller);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2023 sovity GmbH
*
* 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:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.extension.jwks;


import io.restassured.http.ContentType;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.eclipse.edc.spi.protocol.ProtocolWebhook;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Map;
import java.util.UUID;

import static io.restassured.RestAssured.given;
import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort;
import static org.mockito.Mockito.mock;

@ExtendWith(EdcExtension.class)
public class JwksTest {

private static final String AUTH_KEY = UUID.randomUUID().toString();
private static final int WEB_HTTP_PORT = getFreePort();
private static final String WEB_HTTP_PATH = "/api";

@BeforeEach
void setUp(EdcExtension extension) {
extension.registerServiceMock(ProtocolWebhook.class, mock(ProtocolWebhook.class));
extension.registerServiceMock(JsonLd.class, mock(JsonLd.class));
extension.registerServiceMock(
DataPlaneInstanceStore.class,
mock(DataPlaneInstanceStore.class));
extension.setConfiguration(Map.of(
"web.http.port", String.valueOf(WEB_HTTP_PORT),
"web.http.path", WEB_HTTP_PATH,
"web.http.management.port", String.valueOf(getFreePort()),
"web.http.management.path", "/api/v1/data",
"edc.api.auth.key", AUTH_KEY,
"edc.last.commit.info", "test env commit message",
"edc.build.date", "2023-05-08T15:30:00Z"));
}

@Test
void jwksSuccessfullyExposed() {
var request = given()
.baseUri("http://localhost:" + WEB_HTTP_PORT)
.basePath(WEB_HTTP_PATH)
.when()
.contentType(ContentType.JSON)
.get(JwksController.JWKS_PATH)
.then()
.statusCode(200)
.contentType(ContentType.JSON);

// request.assertThat()..body("envLastCommitInfo", equalTo("test env commit message"))
// .body("envBuildDate", equalTo("2023-05-08T15:30:00Z"))
// .body("jarLastCommitInfo", equalTo("test jar commit message"))
// .body("jarBuildDate", equalTo("2023-05-09T15:30:00Z"));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
de.sovity.edc.extension.jwks.JwksExtension
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rootProject.name = "edc-extensions"

include(":extensions:edc-ui-config")
include(":extensions:jwks")
include(":extensions:last-commit-info")
include(":extensions:policy-always-true")
include(":extensions:policy-referring-connector")
Expand All @@ -26,3 +27,4 @@ include(":launchers:connectors:test-backend")
include(":utils:catalog-parser")
include(":utils:json-and-jsonld-utils")
include(":utils:test-connector-remote")
include("extensions:jwks")

0 comments on commit 5bbc05d

Please sign in to comment.