From 610d83a7c656961aedea6a898dea31f110214081 Mon Sep 17 00:00:00 2001 From: zyxxoo <1318247699@qq.com> Date: Mon, 21 Mar 2022 10:20:13 +0800 Subject: [PATCH] feat: improve code --- .../hugegraph/security/HugeSecurityManager.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java index 86e67dc35e..5767cba554 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/security/HugeSecurityManager.java @@ -127,15 +127,15 @@ public class HugeSecurityManager extends SecurityManager { ImmutableSet.of("newSecurityException") ); - private static final Set ignoreCheck = new CopyOnWriteArraySet<>(); + private static final Set ignoreCheckedClasses = new CopyOnWriteArraySet<>(); - public static void addIgnoreCheck(String clazz) { + public static void ignoreCheckedClass(String clazz) { if (callFromGremlin()) { throw newSecurityException( "Not allowed to add ignore check via Gremlin"); } - ignoreCheck.add(clazz); + ignoreCheckedClasses.add(clazz); } @Override @@ -179,7 +179,7 @@ public void checkAccess(Thread thread) { if (callFromGremlin() && !callFromCaffeine() && !callFromAsyncTasks() && !callFromEventHubNotify() && !callFromBackendThread() && !callFromBackendHbase() && - !callFromRaft() && !callFromSofaRpc() && !callFromIgnore()) { + !callFromRaft() && !callFromSofaRpc() && !callFromIgnoreCheckedClass()) { throw newSecurityException( "Not allowed to access thread via Gremlin"); } @@ -191,7 +191,8 @@ public void checkAccess(ThreadGroup threadGroup) { if (callFromGremlin() && !callFromCaffeine() && !callFromAsyncTasks() && !callFromEventHubNotify() && !callFromBackendThread() && !callFromBackendHbase() && - !callFromRaft() && !callFromSofaRpc() && !callFromIgnore()) { + !callFromRaft() && !callFromSofaRpc() && + !callFromIgnoreCheckedClass()) { throw newSecurityException( "Not allowed to access thread group via Gremlin"); } @@ -487,8 +488,8 @@ private static boolean callFromNewSecurityException() { return callFromMethods(NEW_SECURITY_EXCEPTION); } - private static boolean callFromIgnore() { - return callFromWorkerWithClass(ignoreCheck); + private static boolean callFromIgnoreCheckedClass() { + return callFromWorkerWithClass(ignoreCheckedClasses); } private static boolean callFromWorkerWithClass(Set classes) {