本文整理汇总了Java中org.mozilla.javascript.ClassShutter类的典型用法代码示例。如果您正苦于以下问题:Java ClassShutter类的具体用法?Java ClassShutter怎么用?Java ClassShutter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassShutter类属于org.mozilla.javascript包,在下文中一共展示了ClassShutter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setJavaClassesVisibleInvisibleSandbox
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
private static void setJavaClassesVisibleInvisibleSandbox(Context cx)
{
cx.setClassShutter(new ClassShutter()
{
public boolean visibleToScripts(String className)
{
// No Java classes allowed inside scripts
return false;
}
});
}
示例2: getInstance
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
static synchronized ClassShutter getInstance() {
if (theInstance == null) {
theInstance = new RhinoClassShutter();
protectedClasses = new HashMap<String,Boolean>();
// For now, we just have AccessController. Allowing scripts
// to this class will allow it to execute doPrivileged in
// bootstrap context. We can add more classes for other reasons.
protectedClasses.put("java.security.AccessController", Boolean.TRUE);
}
return theInstance;
}
示例3: getInstance
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
static synchronized ClassShutter getInstance() {
if (theInstance == null) {
theInstance = new RhinoClassShutter();
protectedClasses = new HashMap<String, Boolean>();
// For now, we just have AccessController. Allowing scripts
// to this class will allow it to execute doPrivileged in
// bootstrap context. We can add more classes for other reasons.
protectedClasses.put("java.security.AccessController", Boolean.TRUE);
}
return theInstance;
}
示例4: secureContext
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
private void secureContext(Context context) {
context.setClassShutter(new ClassShutter() {
public boolean visibleToScripts(String className) {
if(className.startsWith("adapter") || className.startsWith("org.jpmml"))
return true;
return false;
}
});
}
示例5: onCommand
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
/**
* This executes the command. In ChannelCommands, this will set up a Context for Rhino to use to execute the
* command's JavaScript, which will be obtained from {@link #getJavaScript()}. Two global variables will be passed
* to the script: <code>event</code> and <code>args</code>, the same that are used in this method.
* <code>event</code> will always be a {@link MessageEvent}. If any exceptions occur while the JavaScript is being
* processed, they will be caught and pasted.
*
* @param event Event of receiving command
* @param callInfo Information received at the calling of this command
* @param args Arguments passed to the command
*/
@Override
public final void onCommand(GenericMessageEvent event, CallInfo callInfo, String[] args) {
if (!(event instanceof MessageEvent)) return; // these commands should only be channel messages
final MessageEvent me = (MessageEvent) event;
final Context c = ContextFactory.getGlobal().enterContext();
c.setClassShutter(new ClassShutter() {
@Override
public boolean visibleToScripts(String className) {
if (className.equals("org.royaldev.royalbot.BotUtils")) return true; // allow BotUtils
else if (className.equals("org.pircbotx.PircBotX")) return false; // no bot access
else if (className.startsWith("org.royaldev.royalbot")) return false; // no package access
return true;
}
});
final Scriptable s = c.initStandardObjects();
ScriptableObject.putProperty(s, "event", Context.javaToJS(me, s)); // provide message event for ease
ScriptableObject.putProperty(s, "args", Context.javaToJS(args, s)); // supply arguments
try {
c.evaluateString(s, getJavaScript(), getName(), 1, null);
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
rb.getLogger().warning("Channel command (\"" + getName() + "\") produced OutOfMemoryError! Removing.");
rb.getCommandHandler().unregister(getName());
}
final String url = BotUtils.linkToStackTrace(t);
notice(event, "Exception!" + ((url != null) ? " (" + url + ")" : ""));
} finally {
Context.exit();
}
}
示例6: getScope
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
@SuppressWarnings("nls")
public Scriptable getScope(Context jsContext)
{
Scriptable scope = new ImporterTopLevel(jsContext);
for( String name : scriptObjects.keySet() )
{
Object obj = scriptObjects.get(name);
if( obj instanceof Boolean )
{
scope.put(name, scope, obj);
}
else if( obj != null )
{
Scriptable jsArgs = Context.toObject(obj, scope);
scope.put(name, scope, jsArgs);
}
}
// Remove the ability to create new Java objects in the script. List
// comes from https://bugzilla.mozilla.org/show_bug.cgi?id=468385
scope.delete("Packages");
scope.delete("JavaImporter");
scope.delete("JavaAdapter");
scope.delete("getClass");
scope.delete("java");
scope.delete("javax");
scope.delete("com");
scope.delete("net");
scope.delete("edu");
scope.delete("org");
try
{
// Prevent existingObject.getClass().forName('...')
jsContext.setClassShutter(new ClassShutter()
{
@Override
public boolean visibleToScripts(String className)
{
return !className.equals("java.lang.Class");
}
});
}
catch( SecurityException se )
{
// ignore - there's no way to test presence of ClassShutter
// (indicative of a Context provided by calling module: ReportEngine
// for example) other than by attempting to set ClassShutter.
// See #8135
}
return scope;
}
示例7: makeContext
import org.mozilla.javascript.ClassShutter; //导入依赖的package包/类
@Override
protected TimeLimitContext makeContext()
{
TimeLimitContext context = new TimeLimitContext();
context.setWrapFactory(new WrapFactory()
{
@Override
public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, java.lang.Class<?> staticType)
{
return new NativeJavaObject(scope, javaObject, getClass())
{
private static final long serialVersionUID = 1L;
@Override
public Object get(String name, Scriptable start)
{
if (name.equals("getClass")) return NOT_FOUND;
return super.get(name, start);
}
};
}
});
context.setClassShutter(new ClassShutter()
{
@Override
public boolean visibleToScripts(String fullClassName)
{
Class<?> clz;
try
{
clz = Class.forName(fullClassName);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
return false;
}
if(ScriptBinding.class.isAssignableFrom(clz)) return true;
if(clz.equals(String.class)) return true;
return false;
}
});
return context;
}