AccessDeniedException使用tomcat遍历文件树

时间:2013-07-30 18:14:35

标签: linux tomcat file-permissions directory-walk javapolicy

我正在创建一个servlet来在服务器上远程运行单独的Java程序。该程序在服务器上遍历文件夹树(KB360 / student和KB360 / admin)。该程序本身可以工作,但是当它在tomcat中运行时,我得到一个AccessDeniedException。我以递归的方式将用户和组追逐到tomcat7。我也尝试过root。从我迄今为止所做的研究来看,它似乎不应该是tomcat SecurityManager的问题。但是,要查看是否存在问题,我将所有权限添加到catalina.policy并重新启动tomcat。

任何想法都将不胜感激。感谢。

以下是文件夹列表和错误。

/home/user/Desktop/Dropbox/Public/KB360

drwxrwxr-x 5 tomcat7   tomcat7   4096 Jun 25 17:39 ./
drwxrwxr-x 5 user      user      4096 Jul  3 22:30 ../
drwxrwxrwx 2 tomcat7   tomcat7   4096 Jul 29 23:43 admin/
-rw-rw-r-- 1 tomcat7   tomcat7   2188 May 25 00:08 kb.jnlp
drwxrwxrwx 2 tomcat7   tomcat7   4096 Jul 29 23:42 student/
drwxrwxr-x 2 tomcat7   tomcat7   4096 Jul  1 02:58 upload/



java.nio.file.AccessDeniedException: /home/user/Desktop/Dropbox/Public/KB360/student 
  at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) 
  at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) 
  at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
  at sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
  at sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:143)
  at sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:96) 
  at java.nio.file.Files.readAttributes(Files.java:1684)
  at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:105) 
  at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
  at java.nio.file.Files.walkFileTree(Files.java:2600)
  at java.nio.file.Files.walkFileTree(Files.java:2633)
  at kb360.service.UpdateIndex.findFilesInFolder(UpdateIndex.java:66)
  at kb360.service.UpdateIndex.update(UpdateIndex.java:181)
  at kb360.service.UpdateIndexes.update(UpdateIndexes.java:50)
  at kb360.service.UpdateIndexes.update(UpdateIndexes.java:61)
  at kb360.service.UpdateIndexes.main(UpdateIndexes.java:132)
  at IndexFiles.startRMIServer(IndexFiles.java:57)
  at IndexFiles.doGet(IndexFiles.java:28) 
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:724)

1 个答案:

答案 0 :(得分:2)

我发现我必须从home开始授予父文件夹的权限。我将组更改为tomcat,并将chmod权限更改为对组提供所需的访问权限。