Solved

Access files on Netwrok drive from JBoss

Posted on 2007-12-06
26
1,375 Views
Last Modified: 2013-12-02
I have a Java application running on JBoss on Windows. I am trying to access files on a network drive. Based on earlier reponses I tried accessing it as
File f = new File("\\computername\folder\filename.pdf");
I can access this file from the Windows "Run" console, but when I try to access it from the browser through my application it says, "<URL path> (Access Denied)"

When the application is running on the same system as where I can invoke the file from "Run" menu command, why can't the application access it? Any ideas?
0
Comment
Question by:ptjha
  • 11
  • 9
  • 6
26 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
As i mentioned earlier, the access will have to be done purely by the 'back end' of the web app. You can't otherwise access anything outside the web folders
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
... and any SecurityManager run by JBoss will have to allow this
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
you cannot access a file via a webapp like that, see my suggestions in your earlier question.
Basically it needs to be implemented on your app server (typically as a servlet)
0
 

Author Comment

by:ptjha
Comment Utility
Objects,
I am trying to test this in jsp. That is what gave the "access denied" message.

CEHJ,
I am not very familiar with such file handling. Could you elaborate on what you mean by - "the access will have to be done purely by the 'back end' of the web app". I will check the Security Manager setting but what back end access manipualtion are you referring to.

Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>but what back end access manipualtion are you referring to.

That's a general point, but since you're using a jsp, let's make it specific: please post the code you're trying
0
 

Author Comment

by:ptjha
Comment Utility
Here's it.
<%@ page language="java" %>

<%@ page import="java.io.File" 

%><%@ page import="java.io.FileInputStream"

%><%@ page import="java.io.InputStream"

%><%@ page import="java.io.OutputStream"

%><%@ page import="java.io.IOException"

%><%

    File f = null;

    InputStream is = null;

    OutputStream os = null;

    try

    {

      f = new File("\\\\server\\folder\\TestPDF.pdf");

      is = new FileInputStream(f);

      os = response.getOutputStream();

      response.setContentType("application/force-download");

      response.setHeader("Content-Disposition", "attachment; filename=\"TestPDF.pdf\"");

    

      int l;

      byte[] b = new byte[1024];

      while(true) 

      {

        l = is.read(b);

        if(l==0) break;

        os.write(b, 0, l);

      }

    }

    catch(IOException ioe)

    { %> <%= e.getMessage() %> <%} 

    finally

    {

      if (is != null)

        is.close();

      if (os != null)

        os.close();

    }

%>

Open in new window

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> I am trying to test this in jsp. That is what gave the "access denied" message.

could be that jboss just does not have access to the remote drive.
Make sure you are trying to access it as a file, and not as a url

> Could you elaborate on what you mean by - "the access will have to be done purely by the 'back end' of the web app".

he means what i outlined in your earlier q
0
 

Author Comment

by:ptjha
Comment Utility
Sorry, that was the earlier version. "e.getMessage()" should be replaced with "ioe.getMessage()". I have that in the server version.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
first thing to check would be your security manager (try disabling it as a test)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
That's probably being disallowed by the container's SecurityManager. If so, you need to change the policy file
0
 

Author Comment

by:ptjha
Comment Utility
Thanks for your quick response. I tested it out by setting the policies in java.policy file, but it still gives "Access is denied" message. Apart from AllPermissions to the SecurityManager, I even added,
 permission java.io.FilePermission "\\\\server\\folder\\TestPDF.pdf", "read, write, execute";
all java.policy. But it still doesn't seem to work.
    Where am I going wrong?

Objects - "could be that jboss just does not have access to the remote drive. Make sure you are trying to access it as a file, and not as a url"
How do I ensure that I am accessing it as file an not URL? Do I need to put "file:///\\\\corp.telephia.com......? Please let me know.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>I tested it out by setting the policies in java.policy file

Make sure it's the right file and it's being accessed

>>How do I ensure that I am accessing it as file an not URL?

As i mentioned before - you create a File object
0
 

Author Comment

by:ptjha
Comment Utility
>> As i mentioned before - you create a File object

Yes, that's what I am doing. Refering back to the cocde snipet I posted earlier. I am using it as,
 f = new File("\\\\server\\folder\\TestPDF.pdf");

As for the policy file, I made cchanges to the security policy file. Is it mandatory to make these chcanges in the user policy file too i.e. at ${USER.HOME}. Moreover, I haven't been able to locate the user policy file yet. The server has Windows Server 2003 and I did not find the C:\Windows\Profiles so I could not loate the user policy file. Where could it be?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
To be on the safe side, just do a global search and check the file stamps
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
Comment Utility
easier to just disable the security manager, that will tell you if its what blocking your access.
0
 

Author Comment

by:ptjha
Comment Utility
By default JBoss does not start with Security Manager. So when I tried earlier with Security Manager disabled, it did not work. Now I have made relevant changes to run.bat - JAVA_OPTS to enable security manager and made changes to all java.policy files on the server. But unfortunately it is still not working. I still get access denied and infact it is not an AccessControlException but is an IOException. Not sure why.

Does anybody have any more ideas? I am just stuck at this point.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
thought so, didn't seem security manager related.
would appear that jboss just don't have access to the drive

why aren't you mounting the drive in the 1st place?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 125 total points
Comment Utility
>>and infact it is not an AccessControlException but is an IOException.

Make sure that the account under which JBoss is running has read permissions
0
 

Author Comment

by:ptjha
Comment Utility
Objects,
As for fileserver, it is a shared repository and some other applications use it too. So it resides on a separate system. However I did map it as network drive on the app server and tried but that doesn't work as well.

CEHJ,
JBoss service has the following specified as Log On as - Local System Account. I enabled "Allow services to interact with desktop).  As for the file server, folder and files on it, my user id has all read, write, execute and modify provileges. I even set the JBoss Log on to use my credentials which should mean that the application should be able to access the fileserver without any issues. But even then it did not work. Moreover I use the same credentials for the app server and the file server. So that should be simple for the setup as well. So now I can't figure out what else to do or set from my end.

Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
What do you get from

System.out.println(f.canRead());

?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> However I did map it as network drive on the app server and tried but that doesn't work as well.

did u change the path in your code?

> System.out.println(f.canRead());

that will fail
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Oh and please post the IOException stack trace
0
 

Author Comment

by:ptjha
Comment Utility
There is no stack trace in it. I am invoking it from jsp and the jsp just has whatever code you see in the above posted snipet. So stack trace does not print anything. The only message for IOException I get is,

"\\server\folder\TestPDF.pdf (Access is denied)"
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>There is no stack trace in it. I am invoking it from jsp ...

The stack trace (if there IS an exception) should appear in your container's log file
0
 

Author Comment

by:ptjha
Comment Utility
It is working now. I did not change anything at our end but had asked the IT group to revisist and reset the permissions on the folders/files. Not sure if that worked because the JBoss user had "Full Control" on the fileserver folders and files from teh beginning.

Thanks for all your help and prompt responses.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
OK - glad you've got it
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now