From 5a478effc82d777ca65c1dc4b72d0777e90a2b74 Mon Sep 17 00:00:00 2001 From: guoygang <16954452+guoygang@users.noreply.github.com> Date: Mon, 6 Sep 2021 11:32:07 +0800 Subject: [PATCH] upgrade auth api (#13) * modify graph flag name to satisfied with unauth graph Co-authored-by: zhangyi51 Co-authored-by: janbox70 <88643344+janbox70@users.noreply.github.com> Co-authored-by: guoyonggang --- .../api/filter/AuthenticationFilter.java | 7 +- .../hugegraph/api/profile/GraphsAPI.java | 96 +++++++++---------- .../assembly/static/bin/start-hugegraph.sh | 2 + 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java index be3e4d379c..6a1aeecde2 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/filter/AuthenticationFilter.java @@ -31,7 +31,11 @@ import javax.ws.rs.Priorities; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.core.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; import javax.ws.rs.ext.Provider; import javax.xml.bind.DatatypeConverter; @@ -54,7 +58,6 @@ import com.google.common.collect.ImmutableList; @Provider -/* @PreMatching */ @Priority(Priorities.AUTHENTICATION) public class AuthenticationFilter implements ContainerRequestFilter { diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java index f55d64e478..03d61336a5 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/profile/GraphsAPI.java @@ -89,27 +89,27 @@ public Object list(@Context GraphManager manager, @GET @Timed - @Path("{name}") + @Path("{graph}") @Produces(APPLICATION_JSON_WITH_CHARSET) - @RolesAllowed({"admin", "$owner=$name"}) + @RolesAllowed({"admin", "$owner=$graph"}) public Object get(@Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Get graph by name '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Get graph by name '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); return ImmutableMap.of("name", g.name(), "backend", g.backend()); } @GET @Timed - @Path("{name}/conf") + @Path("{graph}/conf") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") public File getConf(@Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Get graph configuration by name '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Get graph configuration by name '{}'", graph); - HugeGraph g = graph4admin(manager, name); + HugeGraph g = graph4admin(manager, graph); HugeConfig config = (HugeConfig) g.configuration(); File file = config.getFile(); @@ -122,15 +122,15 @@ public File getConf(@Context GraphManager manager, @DELETE @Timed - @Path("{name}/clear") + @Path("{graph}/clear") @Consumes(APPLICATION_JSON) @RolesAllowed("admin") public void clear(@Context GraphManager manager, - @PathParam("name") String name, + @PathParam("graph") String graph, @QueryParam("confirm_message") String message) { - LOG.debug("Clear graph by name '{}'", name); + LOG.debug("Clear graph by name '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); if (!CONFIRM_CLEAR.equals(message)) { throw new IllegalArgumentException(String.format( @@ -141,109 +141,109 @@ public void clear(@Context GraphManager manager, @PUT @Timed - @Path("{name}/snapshot_create") + @Path("{graph}/snapshot_create") @Produces(APPLICATION_JSON_WITH_CHARSET) - @RolesAllowed({"admin", "$owner=$name"}) + @RolesAllowed({"admin", "$owner=$graph"}) public Object createSnapshot(@Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Create snapshot for graph '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Create snapshot for graph '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); g.createSnapshot(); - return ImmutableMap.of(name, "snapshot_created"); + return ImmutableMap.of(graph, "snapshot_created"); } @PUT @Timed - @Path("{name}/snapshot_resume") + @Path("{graph}/snapshot_resume") @Produces(APPLICATION_JSON_WITH_CHARSET) - @RolesAllowed({"admin", "$owner=$name"}) + @RolesAllowed({"admin", "$owner=$graph"}) public Object resumeSnapshot(@Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Resume snapshot for graph '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Resume snapshot for graph '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); g.resumeSnapshot(); - return ImmutableMap.of(name, "snapshot_resumed"); + return ImmutableMap.of(graph, "snapshot_resumed"); } @PUT @Timed - @Path("{name}/compact") + @Path("{graph}/compact") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin"}) public String compact(@Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Manually compact graph '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Manually compact graph '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); return JsonUtil.toJson(g.metadata(null, "compact")); } @PUT @Timed - @Path("{name}/mode") + @Path("{graph}/mode") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RolesAllowed({"admin", "$owner=$name"}) + @RolesAllowed({"admin", "$owner=$graph"}) public Map mode(@Context GraphManager manager, - @PathParam("name") String name, + @PathParam("graph") String graph, GraphMode mode) { - LOG.debug("Set mode to: '{}' of graph '{}'", mode, name); + LOG.debug("Set mode to: '{}' of graph '{}'", mode, graph); E.checkArgument(mode != null, "Graph mode can't be null"); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); g.mode(mode); return ImmutableMap.of("mode", mode); } @GET @Timed - @Path("{name}/mode") + @Path("{graph}/mode") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RolesAllowed({"admin", "$owner=$name"}) + @RolesAllowed({"admin", "$owner=$graph"}) public Map mode(@Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Get mode of graph '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Get mode of graph '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); return ImmutableMap.of("mode", g.mode()); } @PUT @Timed - @Path("{name}/graph_read_mode") + @Path("{graph}/graph_read_mode") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed("admin") public Map graphReadMode( @Context GraphManager manager, - @PathParam("name") String name, + @PathParam("graph") String graph, GraphReadMode readMode) { LOG.debug("Set graph-read-mode to: '{}' of graph '{}'", - readMode, name); + readMode, graph); E.checkArgument(readMode != null, "Graph-read-mode can't be null"); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); g.readMode(readMode); return ImmutableMap.of("graph_read_mode", readMode); } @GET @Timed - @Path("{name}/graph_read_mode") + @Path("{graph}/graph_read_mode") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON_WITH_CHARSET) - @RolesAllowed({"admin", "$owner=$name"}) + @RolesAllowed({"admin", "$owner=$graph"}) public Map graphReadMode( @Context GraphManager manager, - @PathParam("name") String name) { - LOG.debug("Get graph-read-mode of graph '{}'", name); + @PathParam("graph") String graph) { + LOG.debug("Get graph-read-mode of graph '{}'", graph); - HugeGraph g = graph(manager, name); + HugeGraph g = graph(manager, graph); return ImmutableMap.of("graph_read_mode", g.readMode()); } } diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index 46023b5e3f..543f52af7c 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -59,6 +59,8 @@ if [ ! -d "$LOGS" ]; then mkdir -p "$LOGS" fi +"$BIN"/init-store.sh + echo "Starting HugeGraphServer..." "$BIN"/hugegraph-server.sh "$CONF"/gremlin-server.yaml "$CONF"/rest-server.properties \