[英]Changing System Property in Java - Security Policy file
我對理解Java安全模型有些困惑。 在我的${JDK_HOME}/jre/lib/security/java.policy
文件中,我可以看到以下條目:
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";
我把它解釋為:在VM中運行的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
設置的策略不起作用,我在這里缺少什么?
java.policy文件不在普通的java進程中使用。 您必須首先配置java進程以使用SecurityManager(.eg將“-Djava.security.manager”添加到命令行)。 更多細節在這里 。
不要浪費時間搞亂政策文件。 對於程序員來說,他們很難做到正確,而對於最終用戶來說幾乎是不可能的。
如果一個應用程序 需要信任,對其進行數字簽名,並在提示時說服用戶信任代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.