使用Wildfly 8.1配置Java策略文件

时间:2014-06-22 23:33:24

标签: java security wildfly

在wildfly 8.1中运行我的应用程序时,我遇到了AccessControlException:

Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "uka.karmi.useDistributedThreads" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457 [rt.jar:1.8.0_05]
at java.security.AccessController.checkPermission(AccessController.java:884) [rt.jar:1.8.0_05]
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) [rt.jar:1.8.0_05]
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294) [rt.jar:1.8.0_05]
at java.lang.System.getProperty(System.java:714) [rt.jar:1.8.0_05]

我正在使用VM参数运行我的wildfly服务器:

-Djava.security.policy=/opt/misc/test.policy

test.policy的样子:

grant {
    permission java.security.AllPermission;
};

我也尝试修改test.policy:

grant {
    permission java.security.AllPermission;
    permission java.util.PropertyPermission "uka.karmi.useDistributedThreads", "read";
};

但仍然会遇到同样的错误。

1 个答案:

答案 0 :(得分:0)

在WildFly中定义部署权限的首选方法是META-INF/permissions.xml(或特定于供应商的META-INF/jboss-permissions.xml)文件,该文件随Java EE 7一起提供。

问题是,WildFly似乎有an issue (WFLY-3651)

您案例中的permissions.xml文件可能如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<permissions xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/permissions_7.xsd"
    version="7">
    <permission>
        <class-name>java.util.PropertyPermission</class-name>
        <name>uka.karmi.useDistributedThreads</name>
        <actions>read</actions>
    </permission>
</permissions>