我在Windows 10上使用以下命令启动了Tomcat 9.0:
-Djava.security.manager
-Djava.security.policy==C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\catalina.policy
-Djava.security.debug=access,failure
使用类型为org.apache.coyote.http11.Http11Nio2Protocol的连接器并启用ssl。
我也只有(我自己的)ROOT应用正在运行,而没有其他内容。
在catalina.policy中,我已经定义(用于首次测试):
grant codeBase "file:${catalina.base}/webapps/ROOT/-" {
permission java.security.AllPermission;
};
当我现在检查tomcat9-stderr.log时,我发现以下条目:
access: access denied ("java.util.PropertyPermission" "org.apache.juli.logging.UserDataHelper.CONFIG" "read")
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Unknown Source)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at org.apache.tomcat.util.log.UserDataHelper.<init>(UserDataHelper.java:57)
at org.apache.coyote.AbstractProcessor.<init>(AbstractProcessor.java:90)
at org.apache.coyote.http2.StreamProcessor.<init>(StreamProcessor.java:56)
at org.apache.coyote.http2.Http2UpgradeHandler.processStreamOnContainerThread(Http2UpgradeHandler.java:261)
at org.apache.coyote.http2.Http2UpgradeHandler.headersEnd(Http2UpgradeHandler.java:1356)
at org.apache.coyote.http2.Http2AsyncUpgradeHandler.headersEnd(Http2AsyncUpgradeHandler.java:37)
at org.apache.coyote.http2.Http2Parser.onHeadersComplete(Http2Parser.java:583)
at org.apache.coyote.http2.Http2Parser.readHeadersFrame(Http2Parser.java:272)
at org.apache.coyote.http2.Http2AsyncParser$FrameCompletionHandler.completed(Http2AsyncParser.java:167)
at org.apache.coyote.http2.Http2AsyncParser$FrameCompletionHandler.completed(Http2AsyncParser.java:85)
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$VectoredIOCompletionHandler.completed(Nio2Endpoint.java:1148)
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$VectoredIOCompletionHandler.completed(Nio2Endpoint.java:1117)
at org.apache.tomcat.util.net.SecureNio2Channel$2.completed(SecureNio2Channel.java:1047)
at org.apache.tomcat.util.net.SecureNio2Channel$2.completed(SecureNio2Channel.java:992)
at sun.nio.ch.Invoker.invokeUnchecked(Unknown Source)
at sun.nio.ch.Invoker$2.run(Unknown Source)
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
access: domain that failed ProtectionDomain null
null
<no principals>
null
以及其中的两个:
access: access denied ("java.lang.RuntimePermission" "accessClassInPackage.org.apache.tomcat.util.net")
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Unknown Source)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPackageAccess(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.tomcat.util.net.SecureNio2Channel.flush(SecureNio2Channel.java:196)
at org.apache.tomcat.util.net.SecureNio2Channel.close(SecureNio2Channel.java:585)
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper.close(Nio2Endpoint.java:932)
at org.apache.coyote.http2.Http2UpgradeHandler.close(Http2UpgradeHandler.java:1010)
at org.apache.coyote.http2.Http2UpgradeHandler.upgradeDispatch(Http2UpgradeHandler.java:359)
at org.apache.coyote.http2.Http2AsyncUpgradeHandler.upgradeDispatch(Http2AsyncUpgradeHandler.java:37)
at org.apache.coyote.http2.Http2AsyncParser$FrameCompletionHandler.failed(Http2AsyncParser.java:240)
at org.apache.coyote.http2.Http2AsyncParser$FrameCompletionHandler.failed(Http2AsyncParser.java:85)
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$VectoredIOCompletionHandler.failed(Nio2Endpoint.java:1184)
at org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$VectoredIOCompletionHandler.failed(Nio2Endpoint.java:1117)
at org.apache.tomcat.util.net.SecureNio2Channel$2.failed(SecureNio2Channel.java:1055)
at org.apache.tomcat.util.net.SecureNio2Channel$2.completed(SecureNio2Channel.java:1049)
at org.apache.tomcat.util.net.SecureNio2Channel$2.completed(SecureNio2Channel.java:992)
at sun.nio.ch.Invoker.invokeUnchecked(Unknown Source)
at sun.nio.ch.Invoker$2.run(Unknown Source)
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
access: domain that failed ProtectionDomain null
null
<no principals>
null
所以我尝试添加
permission java.util.PropertyPermission "org.apache.juli.logging.UserDataHelper.CONFIG", "read";
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.tomcat.util.net";
在catalina.policy文件中的不同位置(对于webapps / ROOT /,CATALINA代码权限,Web应用程序权限)。
但是所有这些都不会使被拒绝的两次访问消失。
所以我的问题是如何清除这两个拒绝访问的信息?
更新1
对于accessClassInPackage.org.apache.tomcat.util.net我不知道为什么会这样,因为org.apache.tomcat.util.net位于Tomcat / lib / tomcat-coyote.jar中,该许可来自以下位置: / p>
grant codeBase "file:${catalina.home}/lib/-" {
permission java.security.AllPermission;
};
更新2
已更改
-Djava.security.policy=
到
-Djava.security.policy==
这让
access denied ("java.lang.RuntimePermission" "accessClassInPackage.org.apache.tomcat.util.net")
消失-从而仅朱利叶记录仍被拒绝。
更新3
现在,我还有一个例外:
access: access denied ("java.net.SocketPermission" "127.0.0.1:15484" "accept,resolve")
11-Feb-2019 14:46:43.895 SCHWERWIEGEND [https-openssl-nio2-443-exec-7] org.apache.tomcat.util.net.Nio2Endpoint$Nio2Acceptor.failed Socket accept failed
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:15478" "accept,resolve")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkAccept(Unknown Source)
at sun.nio.ch.WindowsAsynchronousServerSocketChannelImpl$AcceptTask$1.run(Unknown Source)
at sun.nio.ch.WindowsAsynchronousServerSocketChannelImpl$AcceptTask$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.nio.ch.WindowsAsynchronousServerSocketChannelImpl$AcceptTask.finishAccept(Unknown Source)
at sun.nio.ch.WindowsAsynchronousServerSocketChannelImpl$AcceptTask.completed(Unknown Source)
at sun.nio.ch.Iocp$EventHandlerTask.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.misc.InnocuousThread.run(Unknown Source)
这很奇怪,因为
org.apache.tomcat.util.net.Nio2Endpoint
属于
tomcat/lib/tomcat-coyote.jar
应该不受任何限制
grant codeBase "file:${catalina.home}/lib/-" {
permission java.security.AllPermission;
};
更奇怪的是,这之后是:
access: access allowed ("java.net.SocketPermission" "127.0.0.1:15485" "accept,resolve")
这使整个事情变得更加神秘。
顺便说一句。对于 UserDataHelper 来说,情况似乎也是这样。
答案 0 :(得分:1)
在我们的应用程序中发现了类似的问题。 catalina策略中的安全设置对代码没有任何影响;对我们来说更重要的是,它是间歇性地来的。
我们在Catalina调试模式(这有助于逐步通过Catalina线程进行调试)中进行了大量研究。
我们通过将server.xml中的连接器更改为org.apache.coyote.http11.Http11NioProtocol(NIO的第一个版本,而不是NIO2)解决了此问题。
我们以某种方式感到NIO2在后台创建多个异步线程时弄乱了安全策略。