Skip to content

Commit

Permalink
feat: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Mar 21, 2022
1 parent c7c630b commit 610d83a
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public class HugeSecurityManager extends SecurityManager {
ImmutableSet.of("newSecurityException")
);

private static final Set<String> ignoreCheck = new CopyOnWriteArraySet<>();
private static final Set<String> 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
Expand Down Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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<String> classes) {
Expand Down

0 comments on commit 610d83a

Please sign in to comment.