|
17 | 17 |
|
18 | 18 | package org.apache.hugegraph.auth; |
19 | 19 |
|
20 | | -import java.time.Duration; |
21 | | -import java.util.ArrayList; |
22 | | -import java.util.Collection; |
23 | | -import java.util.Collections; |
24 | | -import java.util.Date; |
25 | | -import java.util.Iterator; |
26 | | -import java.util.List; |
27 | | -import java.util.Objects; |
28 | | -import java.util.Optional; |
29 | | -import java.util.Set; |
30 | | -import java.util.concurrent.Callable; |
31 | | -import java.util.concurrent.Future; |
32 | | -import java.util.concurrent.LinkedBlockingQueue; |
33 | | -import java.util.concurrent.ThreadFactory; |
34 | | -import java.util.concurrent.ThreadPoolExecutor; |
35 | | -import java.util.concurrent.TimeUnit; |
36 | | -import java.util.concurrent.TimeoutException; |
37 | | -import java.util.function.Supplier; |
38 | | - |
39 | | -import javax.security.sasl.AuthenticationException; |
40 | | - |
| 20 | +import com.alipay.remoting.rpc.RpcServer; |
| 21 | +import jakarta.ws.rs.ForbiddenException; |
| 22 | +import jakarta.ws.rs.NotAuthorizedException; |
41 | 23 | import org.apache.commons.configuration2.Configuration; |
42 | 24 | import org.apache.hugegraph.HugeGraph; |
43 | 25 | import org.apache.hugegraph.auth.HugeAuthenticator.RolePerm; |
|
63 | 45 | import org.apache.hugegraph.masterelection.RoleElectionStateMachine; |
64 | 46 | import org.apache.hugegraph.rpc.RpcServiceConfig4Client; |
65 | 47 | import org.apache.hugegraph.rpc.RpcServiceConfig4Server; |
66 | | -import org.apache.hugegraph.schema.EdgeLabel; |
67 | | -import org.apache.hugegraph.schema.IndexLabel; |
68 | | -import org.apache.hugegraph.schema.PropertyKey; |
69 | | -import org.apache.hugegraph.schema.SchemaElement; |
70 | | -import org.apache.hugegraph.schema.SchemaLabel; |
71 | | -import org.apache.hugegraph.schema.SchemaManager; |
72 | | -import org.apache.hugegraph.schema.VertexLabel; |
| 48 | +import org.apache.hugegraph.schema.*; |
73 | 49 | import org.apache.hugegraph.structure.HugeEdge; |
74 | 50 | import org.apache.hugegraph.structure.HugeElement; |
75 | 51 | import org.apache.hugegraph.structure.HugeFeatures; |
76 | 52 | import org.apache.hugegraph.structure.HugeVertex; |
77 | | -import org.apache.hugegraph.task.HugeTask; |
78 | | -import org.apache.hugegraph.task.ServerInfoManager; |
79 | | -import org.apache.hugegraph.task.TaskManager; |
80 | | -import org.apache.hugegraph.task.TaskScheduler; |
81 | | -import org.apache.hugegraph.task.TaskStatus; |
| 53 | +import org.apache.hugegraph.task.*; |
82 | 54 | import org.apache.hugegraph.traversal.optimize.HugeScriptTraversal; |
83 | 55 | import org.apache.hugegraph.type.HugeType; |
84 | 56 | import org.apache.hugegraph.type.Nameable; |
|
88 | 60 | import org.apache.hugegraph.util.Log; |
89 | 61 | import org.apache.hugegraph.util.RateLimiter; |
90 | 62 | import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; |
91 | | -import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; |
| 63 | +import org.apache.tinkerpop.gremlin.process.traversal.*; |
92 | 64 | import org.apache.tinkerpop.gremlin.process.traversal.Bytecode.Instruction; |
93 | | -import org.apache.tinkerpop.gremlin.process.traversal.Script; |
94 | | -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; |
95 | | -import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies; |
96 | | -import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; |
97 | 65 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; |
98 | 66 | import org.apache.tinkerpop.gremlin.process.traversal.translator.GroovyTranslator; |
99 | | -import org.apache.tinkerpop.gremlin.structure.Edge; |
100 | | -import org.apache.tinkerpop.gremlin.structure.Element; |
101 | | -import org.apache.tinkerpop.gremlin.structure.Graph; |
102 | | -import org.apache.tinkerpop.gremlin.structure.Property; |
103 | | -import org.apache.tinkerpop.gremlin.structure.Transaction; |
104 | | -import org.apache.tinkerpop.gremlin.structure.Vertex; |
105 | | -import org.apache.tinkerpop.gremlin.structure.VertexProperty; |
| 67 | +import org.apache.tinkerpop.gremlin.structure.*; |
106 | 68 | import org.apache.tinkerpop.gremlin.structure.io.Io; |
107 | 69 | import org.slf4j.Logger; |
108 | 70 |
|
109 | | -import com.alipay.remoting.rpc.RpcServer; |
110 | | - |
111 | | -import jakarta.ws.rs.ForbiddenException; |
112 | | -import jakarta.ws.rs.NotAuthorizedException; |
| 71 | +import javax.security.sasl.AuthenticationException; |
| 72 | +import java.time.Duration; |
| 73 | +import java.util.*; |
| 74 | +import java.util.concurrent.*; |
| 75 | +import java.util.function.Supplier; |
113 | 76 |
|
114 | 77 | public final class HugeGraphAuthProxy implements HugeGraph { |
115 | 78 |
|
@@ -186,6 +149,11 @@ public static Context setAdmin() { |
186 | 149 | public static Context getContext() { |
187 | 150 | // Return task context first |
188 | 151 | String taskContext = TaskManager.getContext(); |
| 152 | + |
| 153 | + if (taskContext == null) { |
| 154 | + return null; |
| 155 | + } |
| 156 | + |
189 | 157 | User user = User.fromJson(taskContext); |
190 | 158 | if (user != null) { |
191 | 159 | return new Context(user); |
@@ -953,6 +921,14 @@ public void updateTime(Date updateTime) { |
953 | 921 | this.hugegraph.updateTime(updateTime); |
954 | 922 | } |
955 | 923 |
|
| 924 | + public static String username() { |
| 925 | + Context context = HugeGraphAuthProxy.getContext(); |
| 926 | + if (context == null) { |
| 927 | + return "anonymous"; |
| 928 | + } |
| 929 | + return context.user.username(); |
| 930 | + } |
| 931 | + |
956 | 932 | private <V> Cache<Id, V> cache(String prefix, long capacity, |
957 | 933 | long expiredTime) { |
958 | 934 | String name = prefix + "-" + this.hugegraph.spaceGraphName(); |
|
0 commit comments