use of eu.esdihumboldt.util.groovy.sandbox.internal.RestrictiveGroovyInterceptor.AllowedPrefix in project hale by halestudio.
the class GroovySandboxTest method setUp.
/**
* Sets up the Groovy shell and interceptor.
*/
@Before
public void setUp() {
CompilerConfiguration cc = new CompilerConfiguration();
// enable invoke dynamic support (simiar to in when scripts are created)
cc.getOptimizationOptions().put(CompilerConfiguration.INVOKEDYNAMIC, true);
cc.addCompilationCustomizers(new SandboxTransformer());
shell = new GroovyShell(cc);
interceptor = new RestrictiveGroovyInterceptor(Collections.<Class<?>>emptySet(), Collections.<Class<?>>emptySet(), Collections.<AllowedPrefix>emptyList());
}
use of eu.esdihumboldt.util.groovy.sandbox.internal.RestrictiveGroovyInterceptor.AllowedPrefix in project hale by halestudio.
the class DefaultGroovyService method createInterceptorFromExtensions.
/**
* @return the Groovy interceptor configured with the allowed classes from
* the extension point.
*/
public static RestrictiveGroovyInterceptor createInterceptorFromExtensions() {
Set<Class<?>> additionalAllowedClasses = new HashSet<>();
Set<Class<?>> additionalAllAllowedClasses = new HashSet<>();
List<AllowedPrefix> additionalAllowedPackages = new ArrayList<>();
for (IConfigurationElement conf : Platform.getExtensionRegistry().getConfigurationElementsFor(ID)) {
if (conf.getName().equals("allow")) {
boolean allowAll = Boolean.parseBoolean(conf.getAttribute("allowAll"));
Class<?> allowedClass = ExtensionUtil.loadClass(conf, "class");
if (allowAll)
additionalAllAllowedClasses.add(allowedClass);
else
additionalAllowedClasses.add(allowedClass);
}
if (conf.getName().equals("allowPackage")) {
boolean allowChildren = Boolean.parseBoolean(conf.getAttribute("allowChildren"));
String packageName = conf.getAttribute("name");
additionalAllowedPackages.add(new AllowedPrefix(packageName, allowChildren));
}
}
return new RestrictiveGroovyInterceptor(additionalAllowedClasses, additionalAllAllowedClasses, additionalAllowedPackages);
}
Aggregations