java.security.AccessControlException:拒绝访问(" java.net.SocketPermission"" localhost:1527"" listen,resolve")

时间:2016-09-19 07:17:40

标签: java database security glassfish

我再次面对这个错误。

Fri Sep 16 17:17:29 CEST 2016 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkListen(SecurityManager.java:1131)
    at java.net.ServerSocket.bind(ServerSocket.java:374)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.createServerSocket(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.access$000(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.executeWork(Unknown Source)
    at org.apache.derby.drda.NetworkServerControl.main(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.enterprise.admin.cli.optional.DerbyControl.invokeNetworkServerControl(DerbyControl.java:158)
    at com.sun.enterprise.admin.cli.optional.DerbyControl.main(DerbyControl.java:245)
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkListen(SecurityManager.java:1131)
    at java.net.ServerSocket.bind(ServerSocket.java:374)
    at java.net.ServerSocket.<init>(ServerSocket.java:237)
    at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.createServerSocket(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.access$000(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
    at org.apache.derby.impl.drda.NetworkServerControlImpl.executeWork(Unknown Source)
    at org.apache.derby.drda.NetworkServerControl.main(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.enterprise.admin.cli.optional.DerbyControl.invokeNetworkServerControl(DerbyControl.java:158)
    at com.sun.enterprise.admin.cli.optional.DerbyControl.main(DerbyControl.java:245)

这次我无法解决编辑java.policy文件的问题。

java -version的结果:

openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

我在

中找到了java.policy文件
/etc/java-8-openjdk/security
/usr/java/jdk1.8.0_25/jre/lib/security

他们两个都有一行:

permission java.net.SocketPermission "localhost:1527", "listen,resolve";

我的机器是Linux 16.04.01,服务器是Glassfish4

是否有其他可能的位置来编辑java.policy文件? 还有其他可能的原因吗?

2 个答案:

答案 0 :(得分:6)

首先,运行derby批处理文件sysinfo.bat以确定正在使用哪个JDK / JRE来运行它。如果您无法确定它,请转到计算机的环境变量并检查JAVA_HOME的值。

然后转到JDK / JRE的\jre\lib\security文件夹并添加:

grant {
    permission java.net.SocketPermission "localhost:1527", "listen";
};

答案 1 :(得分:1)

来自https://docs.oracle.com/cd/E18930_01/html/821-2418/beabx.html

每个GlassFish Server域都有自己的全局J2SE策略文件,位于domain-dir / config中。该文件名为server.policy。