File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
src/main/java/org/togetherjava/discord/server/sandbox Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 33import java .security .Permission ;
44import java .util .Arrays ;
55
6+ /**
7+ * The {@link SecurityManager} used to limit JShell's permissions.
8+ */
69public class JshellSecurityManager extends SecurityManager {
710
811 @ Override
912 public void checkPermission (Permission perm ) {
10- if (! comesFromBotCode ()) {
13+ if (comesFromMe ()) {
1114 return ;
1215 }
1316
@@ -27,10 +30,13 @@ private boolean comesFromJshell() {
2730 .anyMatch (aClass -> aClass .getName ().contains ("REPL" ));
2831 }
2932
30- private boolean comesFromBotCode () {
33+ private boolean comesFromMe () {
3134 return Arrays .stream (getClassContext ())
35+ // one frame for this method, one frame for the call to checkPermission
3236 .skip (2 )
33- .anyMatch (aClass -> aClass == getClassContext ()[0 ]);
37+ // see if the security manager appears anywhere else in the context. If so, we initiated
38+ // the call
39+ .anyMatch (aClass -> aClass == getClass ());
3440 }
3541
3642 private boolean containsClass (String name ) {
You can’t perform that action at this time.
0 commit comments