沙盒JSR-223 [英] Sandboxing JSR-223

查看:133
本文介绍了沙盒JSR-223的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试沙箱JSR-223。具体来说,我不希望任何脚本可以访问我的任何类。 (我听说Rhino可以用ClassShutter做到这一点,但是我想这样做。即对于JSR-223的所有脚本引擎。)

I'm trying to sandbox JSR-223. Specifically, I don't want any script to have access to any of my classes. (I hear Rhino can do that with ClassShutter, but I want to do it generally. ie. for all script engines of JSR-223).

我首先尝试使用 AccessController.doPrivileged 解决方案,完全没有权限。它适用于大多数权限,但脚本仍然可以访问我的所有公共类(它似乎忽略包访问权限......?)。

I first tried to use the AccessController.doPrivileged solution, by passing no permissions at all. It works for most permissions, but the scripts can still access all my public classes (it seems to ignore "package access" permission ...?).

发现了这个。我的问题是:如何在脚本引擎上安装自定义ClassLoader? (或者,如果必须,如何全局替换ClassLoader?)

I found this. My question is : how do I install a custom ClassLoader on the script engine ? (Or How do I replace the ClassLoader globally if I have to ?)

推荐答案

ScriptEngineManager有一个构造函数,它带有一个类加载器。类加载器用于加载脚本引擎实现。当类继承它们的类加载器时,脚本引擎及其创建的任何对象也应该使用该类加载器。

There is a constructor for ScriptEngineManager that takes a classloader. The classloader is used to load the scripting engine implementation. As classes inherit their classloaders, the scripting engine and any objects it creates should also use that classloader.

该类加载器需要否认存在任何非白色的类 - 列出。

That classloader needs to deny the existence of any classes that are not white-listed.

使用自定义SecurityManager进行加强,以便您可以对正在使用的类加载器进行访问检查。

Top it off with a custom SecurityManager so you can base access checks on which classloader in use.

编辑:这是我在 Java中的沙盒犀牛。其中大部分内容也适用于JSR-223。 Sun的实现是Rhino的修改,因此可能存在一些差异。

Here's an article I found on Sandboxing Rhino in Java. Most of it should also apply to JSR-223. Sun's implementation is Rhino with modifications, so there may be some differences.

这篇关于沙盒JSR-223的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆