Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server):swagger support auth for standardAuth mode #2360

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public class AuthenticationFilter implements ContainerRequestFilter {

private static final List<String> WHITE_API_LIST = ImmutableList.of(
"auth/login",
"versions"
"versions",
"openapi.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we add swagger file to white_list by default to allow normal users to check the api & not locked by auth

);

private static String whiteIpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@
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"
)
SunnyBoy-WYH marked this conversation as resolved.
Show resolved Hide resolved
@ApplicationPath("/")
@OpenAPIDefinition(
info = @Info(
title = "HugeGraph RESTful API",
version = CoreVersion.DEFAULT_VERSION,
description = "All management API for HugeGraph",
contact = @Contact(url = "https://github.com/apache/hugegraph", name = "HugeGraph")
)
),
security = {@SecurityRequirement(name = "basic")}
)
public class ApplicationConfig extends ResourceConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
Loading