Skip to content
Permalink
Browse files
GROOVY-10586: Revert "GROOVY-10393: Prepare for deprecation of securi…
…ty manager (JEP-411)"

This reverts commit d6e5e54.
  • Loading branch information
paulk-asert committed Apr 18, 2022
1 parent e6b1637 commit 5f51060cec8c7132e0509d70f579d30a31e16bb1
Showing 42 changed files with 158 additions and 127 deletions.
@@ -18,10 +18,9 @@
*/
package groovy.grape;

import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.List;
@@ -158,7 +157,7 @@ public static void grab(Map<String, Object> dependency) {

public static void grab(final Map<String, Object> args, final Map... dependencies) {
if (enableGrapes) {
VMPluginFactory.getPlugin().doPrivileged(new PrivilegedAction<Void>() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
GrapeEngine instance = getInstance();
@@ -49,7 +49,6 @@
import org.codehaus.groovy.runtime.memoize.StampedCommonCache;
import org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache;
import org.codehaus.groovy.util.URLStreams;
import org.codehaus.groovy.vmplugin.VMPluginFactory;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
@@ -67,6 +66,7 @@
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.NoSuchAlgorithmException;
import java.security.Permission;
@@ -111,7 +111,7 @@ public class GroovyClassLoader extends URLClassLoader {
private GroovyResourceLoader resourceLoader = new GroovyResourceLoader() {
@Override
public URL loadGroovySource(final String filename) throws MalformedURLException {
return VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<URL>) () -> {
return AccessController.doPrivileged((PrivilegedAction<URL>) () -> {
for (String extension : config.getScriptExtensions()) {
try {
URL ret = getSourceFile(filename, extension);
@@ -253,7 +253,7 @@ public Class parseClass(File file) throws CompilationFailedException, IOExceptio
* @return the main class defined in the given script
*/
public Class parseClass(final String text, final String fileName) throws CompilationFailedException {
GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(text, fileName, "/groovy/script"));
GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(text, fileName, "/groovy/script"));
gcs.setCachable(false);
return parseClass(gcs);
}
@@ -278,7 +278,7 @@ public synchronized String generateScriptName() {
}

public Class parseClass(final Reader reader, final String fileName) throws CompilationFailedException {
GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> {
GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> {
try {
String scriptText = IOGroovyMethods.getText(reader);
return new GroovyCodeSource(scriptText, fileName, "/groovy/script");
@@ -425,7 +425,7 @@ protected PermissionCollection getPermissions(CodeSource codeSource) {
perms = new Permissions();
}

ProtectionDomain myDomain = VMPluginFactory.getPlugin().doPrivileged(new PrivilegedAction<ProtectionDomain>() {
ProtectionDomain myDomain = AccessController.doPrivileged(new PrivilegedAction<ProtectionDomain>() {
@Override
public ProtectionDomain run() {
return getClass().getProtectionDomain();
@@ -643,7 +643,7 @@ protected CompilationUnit createCompilationUnit(CompilerConfiguration config, Co
* @return the ClassCollector
*/
protected ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
InnerLoader loader = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<InnerLoader>) () -> new InnerLoader(GroovyClassLoader.this));
InnerLoader loader = AccessController.doPrivileged((PrivilegedAction<InnerLoader>) () -> new InnerLoader(GroovyClassLoader.this));
return new ClassCollector(loader, unit, su);
}

@@ -1083,7 +1083,7 @@ protected boolean isSourceNewer(URL source, Class cls) throws IOException {
* @see #addURL(URL)
*/
public void addClasspath(final String path) {
VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<Void>) () -> {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {

URI newURI;
try {
@@ -22,7 +22,6 @@
import groovy.util.CharsetToolkit;
import org.codehaus.groovy.runtime.IOGroovyMethods;
import org.codehaus.groovy.runtime.ResourceGroovyMethods;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.io.File;
import java.io.FileNotFoundException;
@@ -32,6 +31,7 @@
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -123,7 +123,7 @@ public GroovyCodeSource(final File infile, final String encoding) throws IOExcep
//The calls below require access to user.dir - allow here since getName() and getCodeSource() are
//package private and used only by the GroovyClassLoader.
try {
Object[] info = VMPluginFactory.getPlugin().doPrivileged((PrivilegedExceptionAction<Object[]>) () -> {
Object[] info = AccessController.doPrivileged((PrivilegedExceptionAction<Object[]>) () -> {
// retrieve the content of the file using the provided encoding
if (encoding != null) {
scriptText = ResourceGroovyMethods.getText(infile, encoding);
@@ -26,14 +26,14 @@
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.InvokerInvocationException;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -100,7 +100,7 @@ public GroovyShell(ClassLoader parent, Binding binding, final CompilerConfigurat
&& ((GroovyClassLoader) parentLoader).hasCompatibleConfiguration(config)) {
this.loader = (GroovyClassLoader) parentLoader;
} else {
this.loader = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parentLoader,config));
this.loader = AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parentLoader,config));
}
this.context = binding;
this.config = config;
@@ -203,13 +203,13 @@ public Object run() {
}
}

VMPluginFactory.getPlugin().doPrivileged(new DoSetContext(loader));
AccessController.doPrivileged(new DoSetContext(loader));

// Parse the script, generate the class, and invoke the main method. This is a little looser than
// if you are compiling the script because the JVM isn't executing the main method.
Class scriptClass;
try {
scriptClass = VMPluginFactory.getPlugin().doPrivileged((PrivilegedExceptionAction<Class>) () -> loader.parseClass(scriptFile));
scriptClass = AccessController.doPrivileged((PrivilegedExceptionAction<Class>) () -> loader.parseClass(scriptFile));
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof CompilationFailedException) {
@@ -340,7 +340,7 @@ private static Object runRunnable(Class scriptClass, String[] args) {
* @param args the command line arguments to pass in
*/
public Object run(final String scriptText, final String fileName, String[] args) throws CompilationFailedException {
GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE));
GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE));
return run(gcs, args);
}

@@ -404,7 +404,7 @@ public Object run(final Reader in, final String fileName, List<String> list) thr
* @param args the command line arguments to pass in
*/
public Object run(final Reader in, final String fileName, String[] args) throws CompilationFailedException {
GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(in, fileName, DEFAULT_CODE_BASE));
GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(in, fileName, DEFAULT_CODE_BASE));
Class scriptClass = parseClass(gcs);
return runScriptOrMainOrTestOrRunnable(scriptClass, args);
}
@@ -462,7 +462,7 @@ public Object evaluate(final String scriptText, final String fileName, final Str
sm.checkPermission(new GroovyCodeSourcePermission(codeBase));
}

GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, codeBase));
GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, codeBase));

return evaluate(gcs);
}
@@ -607,7 +607,7 @@ public Script parse(String scriptText) throws CompilationFailedException {
}

public Script parse(final String scriptText, final String fileName, Binding binding) throws CompilationFailedException {
GroovyCodeSource gcs = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE));
GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE));
return parse(gcs, binding);
}

@@ -98,6 +98,7 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -3495,9 +3496,9 @@ private void addProperties() {
// introspect
try {
if (isBeanDerivative(theClass)) {
info = (BeanInfo) VMPluginFactory.getPlugin().doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO));
info = (BeanInfo) AccessController.doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO));
} else {
info = (BeanInfo) VMPluginFactory.getPlugin().doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass));
info = (BeanInfo) AccessController.doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass));
}
} catch (PrivilegedActionException pae) {
throw new GroovyRuntimeException("exception during bean introspection", pae.getException());
@@ -33,7 +33,6 @@
import org.codehaus.groovy.runtime.ResourceGroovyMethods;
import org.codehaus.groovy.runtime.StackTraceUtils;
import org.codehaus.groovy.runtime.StringGroovyMethods;
import org.codehaus.groovy.vmplugin.VMPluginFactory;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.IVersionProvider;
@@ -55,6 +54,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -527,7 +527,7 @@ public Object run() {
}
}

VMPluginFactory.getPlugin().doPrivileged(new DoSetContext(shell.getClassLoader()));
AccessController.doPrivileged(new DoSetContext(shell.getClassLoader()));
}

/**
@@ -37,7 +37,6 @@
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.tools.gse.DependencyTracker;
import org.codehaus.groovy.tools.gse.StringSetMap;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.io.BufferedReader;
import java.io.File;
@@ -48,6 +47,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.util.HashMap;
@@ -61,7 +61,7 @@
* with dependent scripts.
*/
public class GroovyScriptEngine implements ResourceConnector {
private static final ClassLoader CL_STUB = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<ClassLoader>) () -> new ClassLoader() {});
private static final ClassLoader CL_STUB = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> new ClassLoader() {});

private static final URL[] EMPTY_URL_ARRAY = new URL[0];

@@ -339,7 +339,7 @@ public static void main(String[] urls) throws Exception {
*/
private GroovyClassLoader initGroovyLoader() {
GroovyClassLoader groovyClassLoader =
VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<ScriptClassLoader>) () -> {
AccessController.doPrivileged((PrivilegedAction<ScriptClassLoader>) () -> {
if (parentLoader instanceof GroovyClassLoader) {
return new ScriptClassLoader((GroovyClassLoader) parentLoader);
} else {
@@ -21,13 +21,13 @@

import org.apache.groovy.lang.annotation.Incubating;
import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.SwitchPoint;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

@@ -41,7 +41,7 @@
static {
try {
//TODO Jochen: move the findSpecial to a central place together with others to easy security configuration
FALLBACK_HANDLE = VMPluginFactory.getPlugin().doPrivileged((PrivilegedExceptionAction<MethodHandle>) () -> MethodHandles.lookup().findSpecial(
FALLBACK_HANDLE = AccessController.doPrivileged((PrivilegedExceptionAction<MethodHandle>) () -> MethodHandles.lookup().findSpecial(
ReevaluatingReference.class, "replacePayLoad",
MethodType.methodType(Object.class),
ReevaluatingReference.class));
@@ -19,8 +19,8 @@
package org.codehaus.groovy.control;

import groovy.lang.GroovyClassLoader;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.security.AccessController;
import java.security.PrivilegedAction;

import static java.util.Objects.requireNonNull;
@@ -100,7 +100,7 @@ public GroovyClassLoader getClassLoader() {
public void setClassLoader(final GroovyClassLoader loader) {
// ClassLoaders should only be created inside a doPrivileged block in case
// this method is invoked by code that does not have security permissions.
this.classLoader = loader != null ? loader : VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> {
this.classLoader = loader != null ? loader : AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
if (parent == null) parent = ProcessingUnit.class.getClassLoader();
return new GroovyClassLoader(parent, getConfiguration());
@@ -32,12 +32,12 @@
import org.codehaus.groovy.syntax.Reduction;
import org.codehaus.groovy.syntax.SyntaxException;
import org.codehaus.groovy.tools.Utilities;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
@@ -237,7 +237,7 @@ public void convert() throws CompilationFailedException {

buildAST();

if ("xml".equals(VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<String>) () -> System.getProperty("groovy.ast")))) {
if ("xml".equals(AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("groovy.ast")))) {
XStreamUtils.serialize(name, ast);
}
}
@@ -30,8 +30,8 @@
import org.codehaus.groovy.util.FastArray;
import org.codehaus.groovy.util.LazyReference;
import org.codehaus.groovy.util.ReferenceBundle;
import org.codehaus.groovy.vmplugin.VMPluginFactory;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
@@ -57,7 +57,7 @@ public CachedField[] initValue() {
PrivilegedAction<CachedField[]> action = () -> Arrays.stream(getTheClass().getDeclaredFields())
.filter(f -> ReflectionUtils.checkCanSetAccessible(f, CachedClass.class))
.map(CachedField::new).toArray(CachedField[]::new);
return VMPluginFactory.getPlugin().doPrivileged(action);
return AccessController.doPrivileged(action);
}
};

@@ -71,7 +71,7 @@ public CachedConstructor[] initValue() {
.filter(c -> ReflectionUtils.checkCanSetAccessible(c, CachedClass.class))
.map(c -> new CachedConstructor(CachedClass.this, c))
.toArray(CachedConstructor[]::new);
return VMPluginFactory.getPlugin().doPrivileged(action);
return AccessController.doPrivileged(action);
}
};

@@ -91,7 +91,7 @@ public CachedMethod[] initValue() {
return CachedMethod.EMPTY_ARRAY;
}
};
CachedMethod[] declaredMethods = VMPluginFactory.getPlugin().doPrivileged(action);
CachedMethod[] declaredMethods = AccessController.doPrivileged(action);

List<CachedMethod> methods = new ArrayList<>(declaredMethods.length);
List<CachedMethod> mopMethods = new ArrayList<>(declaredMethods.length);
@@ -139,7 +139,7 @@ public CachedClass initValue() {

@Override
public CallSiteClassLoader initValue() {
return VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<CallSiteClassLoader>) () -> new CallSiteClassLoader(CachedClass.this.cachedClass));
return AccessController.doPrivileged((PrivilegedAction<CallSiteClassLoader>) () -> new CallSiteClassLoader(CachedClass.this.cachedClass));
}
};

0 comments on commit 5f51060

Please sign in to comment.