这个关于Java安全的文章说:
每当尝试进行危险操作时,Java库中的代码都会咨询Security。
那么,这到底意味着什么?比如说,如果我已经实现了自己的安全管理器并为整个JVM启用了它。现在,java运行时是为每个java调用(如System.out.println()等)咨询我的安全管理器,还是只为dangerous api调用(如System.exit()、文件操作等)提供咨询?
编辑:让我澄清我的问题,
我不是在质疑安全经理的可能性。我只是问,安全检查是针对危险api的单独完成的,还是针对每个方法调用的完成的。这反过来会导致大量代码的应用程序的性能大幅下降。
发布于 2011-03-04 11:27:28
只有在代码这么说的情况下,它才会咨询SecurityManager。不是每一次手术都是这样的。
例如,在Runtime.exit中,您可以看到查询了SecurityManager:
public void exit(int status) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkExit(status);
}
Shutdown.exit(status);
}类似地,在File中,您将看到大多数方法都参考了SecurityManager。示例:
public boolean canWrite() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.checkAccess(this, FileSystem.ACCESS_WRITE);
}如果您正在编写一个可能“危险”的方法,那么您也应该咨询SecurityManager。
发布于 2011-03-04 11:24:26
使用安全管理器,您可以控制对以下内容的访问:
对于每一种情况,SecurityManager中都有一个check*()方法
要获得详尽的列表,请检查SecurityConstants中的常量
发布于 2011-03-04 11:24:16
安全管理器使用策略文件来查看哪些是允许的,哪些是不允许的。由此策略文件确定的“危险”操作在执行过程中被授予或拒绝。
您可以在这里找到有关Sun/Oracle JVM默认策略的更多详细信息:
http://download.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html
https://stackoverflow.com/questions/5192965
复制相似问题