I'm having trouble solving a permissions issue with my Java Servlet running on Tomcat 6.0
I encounter an AccessDeniedException when I try to manipulate files stored on a Network Share.
Here is the stack trace:
java.nio.file.AccessDeniedException: \\192.168.1.150\san\input\picture.jpg -> \\192.168.1.150\san\output\picture.jpg
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileCopy.move(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.move(Unknown Source)
at java.nio.file.Files.move(Unknown Source)
at com.package.Task.MoveFile.exec(MoveFile.java:33)
at com.package.Task.PostProcess.doPost(Download.java:101)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Unknown Source)
After researching posts on StackOverflow, I'm unable to find a solution that matches my situation.
A few things to note:
I only experience this issue with my deployed application (war file in webapps directory of Tomcat 6 server).
No access problems when running the application within Eclipse Tomcat server.
Windows permissions on Network Share appear correct (User = Everyone, Permission = Full Control).
The files are located on a Network Share and physically reside on a SAN.
No permissions issues when manipulating the same files on a standalone Java application.
One of the lines of code that draws this exception is:
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
I've confirmed that the Paths being passed to this function are correct and the files do exist.
I'm not sure what else to do at this point and any help would be greatly appreciated.
The problem is the User that the Apache Tomcat Service is using doesn't have permission to access the network resource. The solution is to change the Apache Tomcat Service User. The default user is Local System. Change the user to Administrator by going Services.msc > Right-Click on the Apache Tomcat Service > Properties > Log On and Select "This account:" and fill out the applicable Administrator credentials.