问题描述
我不想修改我的java主目录中的任何内容,但是,我担心有时我的默认java.policy文件可能过于宽松。当我使用 -Djava.security.manager
选项运行java时,有没有办法让我使用指定的策略文件作为唯一的策略文件?
I don't want to modify anything in my java home directory, however, I am afraid that sometimes my default java.policy file may be too permissive. Is there a way for me to use a specified policy file as the only policy file when I run java with the -Djava.security.manager
option?
如果我添加 -Djava.security.policy = myPolicy.policy
选项,除了默认策略文件外,它还会使用我的策略文件 - 这很糟糕,因为看起来仍然授予默认策略文件中授予的所有权限。
If I add a -Djava.security.policy=myPolicy.policy
option, it uses my policy file in addition to the default policy file -- which is bad because it looks like all permissions granted in the default policy file is still granted.
推荐答案
:
-
使用SecurityManager和默认的Java安全策略运行,
是$ JAVA_HOME / jre / lib / security / java.policy:
To run with SecurityManager and default Java security policy, whichis $JAVA_HOME/jre/lib/security/java.policy:
java -Djava.security.manager Main
运行使用SecurityManager和
仅限您的自定义安全策略(忽略默认的java安全
策略):
java -Djava.security.manag er -Djava.security.policy == security.policy Main
使用SecurityManager和默认的java安全策略运行
首先,然后是您的自定义安全策略:
To run with SecurityManager and default java security policyfirst, then your custom security policy:
java -Djava.security.manager -Djava.security.policy = security.policy Main
如果您不想要SecurityManager,那么只需省略
java.security.policy以避免任何混淆。
If you don't want a SecurityManager, then simply leave outjava.security.policy to avoid any confusion.
这篇关于在没有默认java.policy文件的情况下运行Java Security Manager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!