geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r573966 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ gshell-core/src/main/java/org/apache/geronimo/...
Date Sun, 09 Sep 2007 09:13:50 GMT
Author: jdillon
Date: Sun Sep  9 02:13:50 2007
New Revision: 573966

URL: http://svn.apache.org/viewvc?rev=573966&view=rev
Log:
(GSHELL-26) Install custom security manager to forbid calls to System.exit()
Added a temporary command to test stuff out

Added:
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/TestCommand.java
      - copied, changed from r573943, geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java
      - copied, changed from r573943, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CommandLine.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=573966&r1=573965&r2=573966&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
Sun Sep  9 02:13:50 2007
@@ -29,6 +29,7 @@
 import org.apache.geronimo.gshell.ErrorNotification;
 import org.apache.geronimo.gshell.ExitNotification;
 import org.apache.geronimo.gshell.Shell;
+import org.apache.geronimo.gshell.ShellSecurityManager;
 import org.apache.geronimo.gshell.ansi.ANSI;
 import org.apache.geronimo.gshell.ansi.Renderer;
 import org.apache.geronimo.gshell.clp.Argument;
@@ -470,25 +471,34 @@
             System.exit(0);
         }
 
-        final AtomicReference<Integer> codeRef = new AtomicReference<Integer>();
+        final SecurityManager sm = System.getSecurityManager();
+        System.setSecurityManager(new ShellSecurityManager());
 
-        Runtime.getRuntime().addShutdownHook(new Thread("GShell Shutdown Hook") {
-            public void run() {
-                if (codeRef.get() == null) {
-                    // Give the user a warning when the JVM shutdown abnormally, normal shutdown
-                    // will set an exit code through the proper channels
+        final AtomicReference<Integer> codeRef = new AtomicReference<Integer>();
+        int code;
 
-                    io.err.println();
-                    io.err.println("@|red WARNING:| Abnormal JVM shutdown detected");
-                }
+        try {
+            Runtime.getRuntime().addShutdownHook(new Thread("GShell Shutdown Hook") {
+                public void run() {
+                    if (codeRef.get() == null) {
+                        // Give the user a warning when the JVM shutdown abnormally, normal
shutdown
+                        // will set an exit code through the proper channels
 
-                io.flush();
-            }
-        });
+                        io.err.println();
+                        io.err.println("@|red WARNING:| Abnormal JVM shutdown detected");
+                    }
 
-        int code = execute(this.args.toArray(new String[this.args.size()]));
-        codeRef.set(code);
+                    io.flush();
+                }
+            });
 
+            code = execute(this.args.toArray(new String[this.args.size()]));
+            codeRef.set(code);
+        }
+        finally {
+            System.setSecurityManager(sm);
+        }
+        
         System.exit(code);
     }
     

Copied: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/TestCommand.java
(from r573943, geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/TestCommand.java?p2=geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/TestCommand.java&p1=geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java&r1=573943&r2=573966&rev=573966&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ExitCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/TestCommand.java
Sun Sep  9 02:13:50 2007
@@ -19,30 +19,21 @@
 
 package org.apache.geronimo.gshell.commands.builtins;
 
-import org.apache.geronimo.gshell.ExitNotification;
-import org.apache.geronimo.gshell.clp.Argument;
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 
 /**
- * Exit the current shell.
+ * Testing muck...
  *
  * @version $Rev$ $Date$
  */
-@CommandComponent(id="exit", description="Exit the shell")
-public class ExitCommand
+@CommandComponent(id="test", description="Testing muck...")
+public class TestCommand
     extends CommandSupport
 {
-    @Argument(description="System exit code")
-    private int exitCode = 0;
-
     protected Object doExecute() throws Exception {
-        log.info("Exiting w/code: {}", exitCode);
-        
-        //
-        // DO NOT Call System.exit() !!!
-        //
+        System.exit(0);
 
-        throw new ExitNotification(exitCode);
+        return null;
     }
-}
+}
\ No newline at end of file

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java
(from r573943, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CommandLine.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CommandLine.java&r1=573943&r2=573966&rev=573966&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/CommandLine.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java
Sun Sep  9 02:13:50 2007
@@ -19,22 +19,47 @@
 
 package org.apache.geronimo.gshell;
 
+import java.security.Permission;
+
 /**
- * A abstraction of an executable command-line.
- *
- * <p>
- * Could be a simple command or a complex command pipe-line.
+ * ???
  *
  * @version $Rev$ $Date$
  */
-public interface CommandLine
+public class ShellSecurityManager
+    extends SecurityManager
 {
-    /**
-     * Execute the command-line.
-     *
-     * @return  The final result of the command-line.
-     *
-     * @throws Exception    Failed to execute command-line.
-     */
-    Object execute() throws Exception;
-}
+    private final SecurityManager parent;
+
+    public ShellSecurityManager(final SecurityManager parent) {
+        assert parent != null;
+
+        this.parent = parent;
+    }
+
+    public ShellSecurityManager() {
+        this(System.getSecurityManager());
+    }
+
+    public void checkPermission(final Permission perm) {
+        if (parent != null) {
+            parent.checkPermission(perm);
+        }
+    }
+
+    public void checkExit(final int code) {
+        super.checkExit(code);
+
+        throw new SecurityException("Use of System.exit() if forbidden!");
+    }
+
+    /*
+    public void checkPermission(final Permission perm) {
+        assert perm != null;
+        
+        if (perm.getName().equals("exitVM")) {
+            System.out.println("exitVM");
+        }
+    }
+    */
+}
\ No newline at end of file



Mime
View raw message