Reputation: 273
I have coded a Tomcat application that serves up pdf’s that are located on a network (domain) directory. It works on my local laptop but when I deploy it to the tomcat server (installed as a service) I get Access is denied. The Helpdesk did setup the shared directory with read and execute permissions with the server name that Tomcat is running on but it still doesn’t work. It works on my laptop because I am logged into the domain, but since Tomcat is running as a service I would assume authentication isn’t being handled but I thought that giving permissions to the Tomcat server would solve that. Both the Tomcat server and the shared directory are on the same domain. Has anyone else run into this issue?
Helpdesk said they can setup a service account that I can login to but I am not sure how to code that in my application.
Error:
java.io.FileNotFoundException: \\server\directory\file.pdf (Access is denied)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(Unknown Source)
com.strateproc.controller.LoadPDFServlet.doPost(LoadPDFServlet.java:58)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int processID = Integer.parseInt(request.getParameter("processID"));
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
// get filename from process id
Eprocess process = DBMain.getProcessFromId(processID);
// get pdf
String contextPath = PROCESS_DIRECTORY + process.getFileName();
InputStream in = new FileInputStream(contextPath);
// get output steam
OutputStream out = response.getOutputStream();
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
}
Upvotes: 0
Views: 1247
Reputation: 16625
Get helpdesk to set up the service account and then configure your Tomcat service (via the provided control panel app or via the standard Windows services control panel) to log in as that service.
Upvotes: 1
Reputation: 8659
I have a system that does the same thing, and the way we did it was to grant the access to the machine itself, by domain\machinename$
with the $ afterwards. That will grant access to every service running on the machine as Local System or Network Service.
Upvotes: 0