Skip to content

Commit

Permalink
upgrade auth api (apache#13)
Browse files Browse the repository at this point in the history
* modify graph flag name to satisfied with unauth graph

Co-authored-by: zhangyi51 <[email protected]>
Co-authored-by: janbox70 <[email protected]>
Co-authored-by: guoyonggang <[email protected]>
  • Loading branch information
4 people authored Sep 6, 2021
1 parent a3b6b9d commit 5a478ef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -54,7 +58,6 @@
import com.google.common.collect.ImmutableList;

@Provider
/* @PreMatching */
@Priority(Priorities.AUTHENTICATION)
public class AuthenticationFilter implements ContainerRequestFilter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand All @@ -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<String, GraphMode> 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<String, GraphMode> 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<String, GraphReadMode> 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<String, GraphReadMode> 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());
}
}
2 changes: 2 additions & 0 deletions hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 5a478ef

Please sign in to comment.