java - 如何安全实现Java插件安全?

标签 java multithreading security plugins policy

我正在设计一个用于在 Java 应用程序中加载、处理和支持插件的系统。在每次部署之前,我认为对此绝对至关重要的一个功能是能够建立一个安全的环境,在该环境中插件被限制在允许的范围内。

如果不在启动时运行 -Djava.security.manager 参数,我无法理解如何以编程方式使用策略文件。所以现在就结束了。

我的下一个想法是在我自己的 SecurityManager 子类中覆盖我在 SecurityManager 中关心的所有方法,并对谁可以执行它们施加限制。

然后问题出现了,找出谁在请求此权限的唯一方法是通过线程 ID 检查。因此,我设计了一个系统,其中所有插件线程都驻留并且只能驻留在 PluginThreads 线程组中。

这奏效了……直到一切都开始崩溃。问题是一些被阻止的东西是由 Sun 的代码执行的内部操作。

因此,即使是最基本的操作(例如打开窗口)也会失败,因为我的安全经理拒绝访问 Sun 的代码。使用我的线程检查方法无法解决这个问题,因为 Sun 的代码在 PluginThreads 组中执行。

所以我需要知道的是:

1) 有没有一种方法可以找出调用来自当前线程的上下文?

2) 有没有我不知道的更好的方法?

3) 如果该方法涉及策略文件,您如何将它们加载到您的代码中?

4)有没有其他方法可以防止Sun内部Java代码被封杀?

最佳答案

SecurityManager 是一团糟。与其反复授予更多可能被滥用的权限,直到它看起来有效,您应该考虑要求插件在 Java 的子集中编写,使您能够合理地推断它们可以做什么。

Joe-E提供可分解的安全性。来自 http://lambda-the-ultimate.org/node/3830 :

We present Joe-E, a language designed to support the development of secure software systems. Joe-E is a subset of Java that makes it easier to architect and implement programs with strong security properties that can be checked during a security review. It enables programmers to apply the principle of least privilege to their programs; implement application-specific reference monitors that cannot be bypassed; introduce and use domain-specific security abstractions; safely execute and interact with untrusted code; and build secure, extensible systems. Joe-E demonstrates how it is possible to achieve the strong security properties of an object-capability language while retaining the features and feel of a mainstream object-oriented language...

关于java - 如何安全实现Java插件安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8281695/

相关文章:

.NET 插件安全

linux - C++11线程库是否调用OS API来运行多线程程序?

java - 使用线程逐 block 处理文件

java - 如何清除 Google Proxy 或 googleusercontent.com 缓存?

java - 更改字符串 java 中的每 5 个字符

c# - 如何创建自定义消息泵?

php - PHP 中的 SQL 注入(inject) MySql

iphone - iPhone 上 SQLite 数据库的光保护

java - 应用程序在访问 RecyclerView 时崩溃

java - Jersey 多部分表单数据默认值?