Java 安全管理器 - 它检查什么?
这篇关于 Java 安全性的文章说:
Java库中的代码参考 安全经理每当出现危险时 即将尝试操作。
那么,这到底是什么意思呢?假设我已经实现了自己的安全管理器并为整个 JVM 启用了它。现在,java运行时是否会针对每个java调用(例如System.out.println()等)咨询我的安全管理器,还是仅针对危险的api调用(例如System.exit()、文件操作)进行咨询ETC?
编辑:让我澄清一下我的问题,
我并不是质疑安全经理的可能性。我只是想问安全检查是针对单独的危险API进行的,还是针对每个方法调用进行的。对于具有大量代码的应用程序来说,这反过来会导致性能大幅下降。
This article about Java security says:
Code in the Java library consults the
Security Manager whenever a dangerous
operation is about to be attempted.
So, what does this exactly mean? Say, if I've implemented my own securitymanager and enabled it for the whole JVM. Now, does the java runtime consults my securitymanager for each and every java call(like System.out.println() etc) or it consults only for dangerous
api calls like System.exit() ,file operations etc?
edit: let me clarify my question,
I'm not questioning the possiblities of the securitymanager. I'm just asking if the security checks are done for the dangerous api's alone or it is done for each and every method call. Which inturn causes a huge performance degradation in case of applications with large amounts of code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果代码如此,它只会咨询 SecurityManager。它不会对每一个操作都执行此操作。
例如,在
Runtime.exit
中,您会看到 SecurityManager 被咨询:同样,在
File
中,您将看到大多数方法都咨询 SecurityManager。示例:如果您正在编写一个可能“危险”的方法,那么您还应该咨询 SecurityManager。
It will only consult the SecurityManager if the code says so. It won't do it for every single operation.
For example in
Runtime.exit
, you see that the SecurityManager is consulted:Similarly, in
File
, you will see that most methods consult the SecurityManager. Example:If you are writing a method which might be "dangerous" then you should also consult the SecurityManager.
使用安全管理器,您可以控制对以下内容的访问:
对于每个这样的事情,SecurityManager 中都有一个 check*() 方法。
要获得详尽的列表,请检查 安全常量
Using security manager you could control access to :
For each such thing there is a check*() method in SecurityManager
For an exhaustive list check the constants in SecurityConstants
安全管理器使用策略文件来查看允许的内容和不允许的内容。由该策略文件确定的“危险”操作在执行期间被授予或拒绝。
您可以在此处找到有关 Sun/Oracle JVM 默认策略的更多详细信息:
http://download.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html
The security manager uses a policy file to see what is permitted and what's not permitted. "Dangerous" operations, as determined by this policy file, is granted or denied during the execution.
You can find more details about the default policy for Sun/Oracle JVM here:
http://download.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html