From 0c014758433cd757e07bd0f3a54533d572548faa Mon Sep 17 00:00:00 2001 From: SunnyBoy-WYH <48077841+SunnyBoy-WYH@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:01:54 +0800 Subject: [PATCH] feat(server):swagger support auth for standardAuth mode (#2360) * feat(server):swagger support auth for standardAuth mode and try to fix arthas odd test * chore(api): update api version & swagger token auth mode --- .../api/filter/AuthenticationFilter.java | 3 ++- .../hugegraph/server/ApplicationConfig.java | 16 +++++++++++++++- .../org/apache/hugegraph/version/ApiVersion.java | 4 +++- .../org/apache/hugegraph/api/ArthasApiTest.java | 7 +------ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java index 464e695fef..d3da3af6d0 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java @@ -72,7 +72,8 @@ public class AuthenticationFilter implements ContainerRequestFilter { private static final List WHITE_API_LIST = ImmutableList.of( "auth/login", - "versions" + "versions", + "openapi.json" ); private static String whiteIpStatus; diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java index d70e6e0b29..a60510178c 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/server/ApplicationConfig.java @@ -44,8 +44,21 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.info.Contact; import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.security.SecurityScheme; import jakarta.ws.rs.ApplicationPath; +@SecurityScheme( + name = "basic", + type = SecuritySchemeType.HTTP, + scheme = "basic" +) +@SecurityScheme( + name = "bearer", + type = SecuritySchemeType.HTTP, + scheme = "bearer" +) @ApplicationPath("/") @OpenAPIDefinition( info = @Info( @@ -53,7 +66,8 @@ version = CoreVersion.DEFAULT_VERSION, description = "All management API for HugeGraph", contact = @Contact(url = "https://github.com/apache/hugegraph", name = "HugeGraph") - ) + ), + security = {@SecurityRequirement(name = "basic"), @SecurityRequirement(name = "bearer")} ) public class ApplicationConfig extends ResourceConfig { diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java index 969e9a3d6a..8170827631 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/version/ApiVersion.java @@ -114,12 +114,14 @@ public final class ApiVersion { * [0.67] Issue-1065: Support dynamically add/remove graph * [0.68] Issue-1763: Support adamic-adar & resource-allocation API * [0.69] Issue-1748: Support Cypher query RESTful API + * [0.70] Issue-2242: Optimising adjacency edge queries + * [0.71] PR-2286: Support Arthas API & Metric API prometheus format */ /** * The second parameter of Version.of() is for IDE running without JAR */ - public static final Version VERSION = Version.of(ApiVersion.class, "0.69"); + public static final Version VERSION = Version.of(ApiVersion.class, "0.71"); public static void check() { // Check version of hugegraph-core. Firstly do check from version 0.3 diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java index c73276b38d..52d0d7405c 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java @@ -40,10 +40,7 @@ public void testArthasStart() { public void testArthasApi() { String body = "{\n" + " \"action\": \"exec\",\n" + - " \"requestId\": \"req112\",\n" + - " \"consumerId\": \"955dbd1325334a84972b0f3ac19de4f7_2\",\n" + - " \"command\": \"version\",\n" + - " \"execTimeout\": \"10000\"\n" + + " \"command\": \"version\"\n" + "}"; RestClient arthasApiClient = new RestClient(ARTHAS_API_BASE_URL, false); // If the request header contains basic auth, @@ -52,8 +49,6 @@ public void testArthasApi() { Response r = arthasApiClient.post(ARTHAS_API_PATH, body); String result = assertResponseStatus(200, r); assertJsonContains(result, "state"); - assertJsonContains(result, "requestId"); - assertJsonContains(result, "sessionId"); assertJsonContains(result, "body"); RestClient arthasApiClientWithAuth = new RestClient(ARTHAS_API_BASE_URL);