diff --git a/core/pom.xml b/core/pom.xml
index 7a67dc27dc..47a3ab14e7 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -150,11 +150,6 @@
org.apache.commons
commons-lang3
-
- org.python
- jython
- 2.7.0
-
org.testng
@@ -200,6 +195,12 @@
jcommander
test
+
+ org.python
+ jython
+ 2.7.0
+ test
+
org.apache.httpcomponents
httpclient
diff --git a/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptClassLoader.java b/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptClassLoader.java
new file mode 100644
index 0000000000..090bd160e7
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptClassLoader.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.brooklyn.core.effector.script;
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+/**
+ * Blocks access to any {@code org.apache.brooklyn} classes
+ * with an entitlements check.
+ */
+public class ScriptClassLoader extends ClassLoader {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ScriptClassLoader.class);
+
+ private List blacklist = ImmutableList.of();
+
+ public ScriptClassLoader(ClassLoader parent, String...blacklist) {
+ super(parent);
+ this.blacklist = compileBlacklist(blacklist);
+ }
+
+ private List compileBlacklist(String...blacklist) {
+ List patterns = Lists.newArrayList();
+ for (String entry : blacklist) {
+ patterns.add(Pattern.compile(entry));
+ }
+ return ImmutableList.copyOf(patterns);
+ }
+
+ @Override
+ protected Class> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ LOG.info("Script class loader: {}", name);
+ for (Pattern pattern : blacklist) {
+ if (pattern.matcher(name).matches()) {
+ throw new ClassNotFoundException(String.format("Class %s is blacklisted: %s", name, pattern.pattern()));
+ }
+ }
+ return super.loadClass(name, resolve);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("ScriptClassLoader %s", Iterables.toString(blacklist));
+ }
+}
diff --git a/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptEffector.java b/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptEffector.java
index aca88d3a93..d48a77c667 100644
--- a/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptEffector.java
+++ b/core/src/main/java/org/apache/brooklyn/core/effector/script/ScriptEffector.java
@@ -18,17 +18,25 @@
*/
package org.apache.brooklyn.core.effector.script;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
import java.util.Map;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
-import org.python.core.Options;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import org.apache.brooklyn.api.effector.Effector;
@@ -45,15 +53,12 @@
import org.apache.brooklyn.util.core.flags.TypeCoercions;
import org.apache.brooklyn.util.core.task.Tasks;
import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.javalang.Reflections;
import org.apache.brooklyn.util.text.Strings;
-import sun.org.mozilla.javascript.internal.NativeJavaObject;
-
public final class ScriptEffector extends AddEffector {
- static {
- Options.importSite = false; // Workaround for Jython
- }
+ private static final Logger LOG = LoggerFactory.getLogger(ScriptEffector.class);
@SetFromFlag("lang")
public static final ConfigKey EFFECTOR_SCRIPT_LANGUAGE = ConfigKeys.newStringConfigKey(
@@ -96,8 +101,6 @@ protected static class Body extends EffectorBody