From 0f801bce3911148069868542136d8b9f377cdb0b Mon Sep 17 00:00:00 2001 From: Keegan Witt Date: Tue, 23 May 2023 12:58:57 -0400 Subject: [PATCH] Remove SecurityManager --- .../gmavenplus/mojo/AbstractToolsMojo.java | 9 --- .../codehaus/gmavenplus/mojo/ConsoleMojo.java | 10 --- .../codehaus/gmavenplus/mojo/ExecuteMojo.java | 10 --- .../codehaus/gmavenplus/mojo/ShellMojo.java | 10 --- .../util/NoExitSecurityManager.java | 71 ------------------- 5 files changed, 110 deletions(-) delete mode 100644 src/main/java/org/codehaus/gmavenplus/util/NoExitSecurityManager.java diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractToolsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractToolsMojo.java index 8eaa0cfb5..525f80b55 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractToolsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractToolsMojo.java @@ -70,15 +70,6 @@ public abstract class AbstractToolsMojo extends AbstractGroovyMojo { @Parameter protected Properties properties = new Properties(); - /** - * Whether to allow System.exit() to be used. Should not be set to false when using parallel - * execution, as it isn't thread-safe. - * - * @since 1.2 - */ - @Parameter(defaultValue = "true") - protected boolean allowSystemExits; - /** * Whether to bind each property to a separate variable (otherwise binds properties to a single 'properties' variable). * diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java index 49da7cf05..94751d06e 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java @@ -22,7 +22,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.codehaus.gmavenplus.util.NoExitSecurityManager; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -86,12 +85,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { } if (groovyVersionSupportsAction()) { - final SecurityManager sm = System.getSecurityManager(); try { - if (!allowSystemExits) { - System.setSecurityManager(new NoExitSecurityManager()); - } - // get classes we need with reflection Class consoleClass; try { @@ -127,10 +121,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); } catch (InstantiationException e) { throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } finally { - if (!allowSystemExits) { - System.setSecurityManager(sm); - } } } else { getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support running a console. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping console startup."); diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java index 976b26184..12b4bd11e 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java @@ -23,7 +23,6 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.codehaus.gmavenplus.model.internal.Version; import org.codehaus.gmavenplus.util.FileUtils; -import org.codehaus.gmavenplus.util.NoExitSecurityManager; import java.io.BufferedReader; import java.io.File; @@ -137,12 +136,7 @@ protected synchronized void doExecute() throws MojoExecutionException { } if (groovyVersionSupportsAction()) { - final SecurityManager sm = System.getSecurityManager(); try { - if (!allowSystemExits) { - System.setSecurityManager(new NoExitSecurityManager()); - } - // get classes we need with reflection Class groovyShellClass = classWrangler.getClass("groovy.lang.GroovyShell"); @@ -159,10 +153,6 @@ protected synchronized void doExecute() throws MojoExecutionException { throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); } catch (IllegalAccessException e) { throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); - } finally { - if (!allowSystemExits) { - System.setSecurityManager(sm); - } } } else { getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support script execution. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping script execution."); diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java index 112bf639b..6f168c8b6 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java @@ -22,7 +22,6 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.codehaus.gmavenplus.model.internal.Version; -import org.codehaus.gmavenplus.util.NoExitSecurityManager; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -91,12 +90,7 @@ public void execute() throws MojoExecutionException { } if (groovyVersionSupportsAction()) { - final SecurityManager sm = System.getSecurityManager(); try { - if (!allowSystemExits) { - System.setSecurityManager(new NoExitSecurityManager()); - } - // get classes we need with reflection Class shellClass = classWrangler.getClass(groovyAtLeast(GROOVY_4_0_0_ALPHA1) ? "org.apache.groovy.groovysh.Groovysh" : "org.codehaus.groovy.tools.shell.Groovysh"); Class bindingClass = classWrangler.getClass("groovy.lang.Binding"); @@ -121,10 +115,6 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); } catch (InstantiationException e) { throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } finally { - if (!allowSystemExits) { - System.setSecurityManager(sm); - } } } else { getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support running a shell. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping shell startup."); diff --git a/src/main/java/org/codehaus/gmavenplus/util/NoExitSecurityManager.java b/src/main/java/org/codehaus/gmavenplus/util/NoExitSecurityManager.java deleted file mode 100644 index a84d4bc0a..000000000 --- a/src/main/java/org/codehaus/gmavenplus/util/NoExitSecurityManager.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.codehaus.gmavenplus.util; - -import java.security.Permission; - - -/** - * Custom security manager to {@link System#exit} (and related) from being used. - * - * @author Jason Dillon - * @since 1.2 - */ -public class NoExitSecurityManager extends SecurityManager { - - /** - * The parent SecurityManager. - */ - private final SecurityManager parent; - - /** - * Construct a new NoExitSecurityManager from the parent. - * - * @param newParent the parent to set - */ - public NoExitSecurityManager(final SecurityManager newParent) { - parent = newParent; - } - - /** - * Construct a new NoExitSecurityManager, using the System SecurityManager as the parent. - */ - public NoExitSecurityManager() { - this(System.getSecurityManager()); - } - - /** - * Check the given Permission. - * - * @param permission the Permission to check - */ - public void checkPermission(final Permission permission) { - if (parent != null) { - parent.checkPermission(permission); - } - } - - /** - * Always throws {@link SecurityException}. - * - * @param code the exit code that is completely ignored - */ - public void checkExit(final int code) { - throw new SecurityException("Use of System.exit() is forbidden!"); - } - -}