imbajin commented on code in PR #3331:
URL: https://github.com/apache/hugegraph/pull/3331#discussion_r4275857219


##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/profile/GraphsAPI.java:
##########
@@ -693,6 +701,60 @@ public Map<String, GraphMode> mode(@Context GraphManager 
manager,
         return ImmutableMap.of("mode", g.mode());
     }
 
+    @GET
+    @Timed
+    @Path("{name}/mode/owners")
+    @Produces(APPLICATION_JSON_WITH_CHARSET)
+    @RolesAllowed({"space", "$owner=$name"})
+    public Map<String, Object> loadingMode(@Context GraphManager manager,
+                                          @PathParam("graphspace") String 
graphSpace,
+                                          @PathParam("name") String name) {
+        return graph(manager, graphSpace, name).loadingMode();
+    }
+
+    @PUT
+    @Timed
+    @Path("{name}/mode/owners")
+    @Consumes(APPLICATION_JSON)
+    @Produces(APPLICATION_JSON_WITH_CHARSET)
+    @RolesAllowed({"space", "$owner=$name"})
+    public Map<String, Object> loadingMode(@Context GraphManager manager,
+                                          @PathParam("graphspace") String 
graphSpace,
+                                          @PathParam("name") String name,
+                                          JsonLoadingOwner owner,
+                                          @Context SecurityContext 
securityContext) {
+        E.checkArgument(owner != null && owner.epoch != null, "Loading owner 
body and epoch are required");
+        if ("recover".equals(owner.action)) {
+            if (securityContext == null || 
!securityContext.isUserInRole("admin")) {

Review Comment:
   Fixed in this PR and the paired [source PR 
#304](https://github.com/hugegraph/hugegraph/pull/304). Recovery now applies 
`RolePermission.isAdmin` to the authenticated `Authorizer.role()`, obtained 
from `ContainerRequestContext.getSecurityContext()`. This avoids the 
auth-disabled graph-space role shortcut and handles Jersey's injected 
SecurityContext wrapper correctly.
   
   The regression uses a real Authorizer, Jersey request and unproxied memory 
graph. With Server authentication enabled and graph-space auth disabled, the 
restricted role passes the former check and recovery executes before the fix; 
after the fix it receives HTTP 403 with the loading tuple and mode unchanged. 
Global administrator recovery and the existing trusted anonymous administrator 
behavior when Server authentication is disabled both pass. Focused 
API/core/auth tests, formatting and JDK 17 full-repository compilation also 
pass.
   
   This verifies the production API and request objects directly. Full HTTP 
authentication-matrix acceptance remains outside this regression.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to