我在理解Java安全模型时有些困惑。在我${JDK_HOME}/jre/lib/security/java.policy
文件,我可以看到如下条目:在Java中更改系统属性 - 安全策略文件
grant {
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See "http://java.sun.com/notes" for more information.
permission java.lang.RuntimePermission "stopThread";
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
// "standard" properies that can be read by anyone
permission java.util.PropertyPermission "java.vm.version", "read";
..... .....
最后一行,上面写着:permission java.util.PropertyPermission "java.vm.version", "read";
我把它解释为:运行在虚拟机有权限读取属性“Java程序java.vm.version”
按照这种理解我写了一个示例程序只是为了检查,如果我得到任何运行时错误。如果我改变这个属性:
System.setProperty("java.vm.version", "my.jvm.version.2345");
System.out.println(System.getProperty("java.vm.version"));
没有错误;而不是System.out.println
显示我的修改后的值,即my.jvm.version.2345
这是否意味着在java.policy
中设置的策略不起作用,我在这里丢失了什么?
谢谢安德鲁和我太同意你了。我只是好奇地看到,政策文件模型是如何工作的? – Vicky 2011-04-15 01:17:55
@Vicky我从来没有搞错政策文件足以告诉你! ;) – 2011-04-15 01:56:38
哈哈!所以你告诉人们不要乱搞政策文件,因为你自己不明白它们? – 2013-04-08 18:31:43