Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > give servlet permission to create file

Reply
Thread Tools

give servlet permission to create file

 
 
tiewknvc9
Guest
Posts: n/a
 
      08-23-2006
Hi!

I am creating a servlet that uploads a file from the users computer to
my servers computer.

When I write the file to the server I am getting continually an access
denied message. Which sux, because Im paying for the space on the
serve, why cant I write to it programatically?!

Anyway Im wondering if there is a certain server setting that I can ask
them to change, or a permission that i should be asking for, or
something. I mean surely other people must want to write files to
their servers, right?

Thanks for any (non-evil) thoughts, including a better hosting service
that is cheap (not making any money off of site).

Thanks! Error message is below.


org.apache.jasper.JasperException: access denied
(java.io.FilePermission /pleaseWork.jb write)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
sun.reflect.GeneratedMethodAccessor326.invoke(Unkn own Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:239)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:517)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:266)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:157)

 
Reply With Quote
 
 
 
 
tiewknvc9
Guest
Posts: n/a
 
      08-23-2006
and we're using apache tomcat as the server...


tiewknvc9 wrote:
> Hi!
>
> I am creating a servlet that uploads a file from the users computer to
> my servers computer.
>
> When I write the file to the server I am getting continually an access
> denied message. Which sux, because Im paying for the space on the
> serve, why cant I write to it programatically?!
>
> Anyway Im wondering if there is a certain server setting that I can ask
> them to change, or a permission that i should be asking for, or
> something. I mean surely other people must want to write files to
> their servers, right?
>
> Thanks for any (non-evil) thoughts, including a better hosting service
> that is cheap (not making any money off of site).
>
> Thanks! Error message is below.
>
>
> org.apache.jasper.JasperException: access denied
> (java.io.FilePermission /pleaseWork.jb write)
> org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:372)
> org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
> org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
> javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
> sun.reflect.GeneratedMethodAccessor326.invoke(Unkn own Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
> java.lang.reflect.Method.invoke(Method.java:585)
> org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:239)
> java.security.AccessController.doPrivileged(Native Method)
> javax.security.auth.Subject.doAsPrivileged(Subject .java:517)
> org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:266)
> org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:157)


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      08-23-2006
tiewknvc9 wrote:
.....
> I am creating a servlet that uploads a file from the users computer to
> my servers computer.

....
> org.apache.jasper.JasperException: access denied
> (java.io.FilePermission /pleaseWork.jb write)


I *suspect*
1) that your host *does* allow writing to files,
but files located within your own directories.
2) Anything pointing to the 'root' e.g. file '/..'
is in *their* directories, rather than yours.

You might try a 'getRealPath' to find where
that file is really (trying) to go.

Andrew T.

 
Reply With Quote
 
tiewknvc9
Guest
Posts: n/a
 
      08-23-2006
I just called my hosting company, who say I have all the appropriate
access priviledges...

Which I would rather not believe, but they say its true...

Here is what my code reads as:

String curDir = application.getRealPath("");
System.out.println(curDir);

File filFile = new File(curDir + "/pleaseWork.txt");

out.println(filFile.getAbsolutePath());
//filFile.createNewFile(); //breaks here!

any idea what IM doing wrong?!?!!


Andrew Thompson wrote:
> tiewknvc9 wrote:
> ....
> > I am creating a servlet that uploads a file from the users computer to
> > my servers computer.

> ...
> > org.apache.jasper.JasperException: access denied
> > (java.io.FilePermission /pleaseWork.jb write)

>
> I *suspect*
> 1) that your host *does* allow writing to files,
> but files located within your own directories.
> 2) Anything pointing to the 'root' e.g. file '/..'
> is in *their* directories, rather than yours.
>
> You might try a 'getRealPath' to find where
> that file is really (trying) to go.
>
> Andrew T.


 
Reply With Quote
 
Scott Harper
Guest
Posts: n/a
 
      08-23-2006
In article <(E-Mail Removed). com>, "tiewknvc9" <(E-Mail Removed)> wrote:
>When I write the file to the server I am getting continually an access
>denied message. Which sux, because Im paying for the space on the
>serve, why cant I write to it programatically?!
>
>Anyway Im wondering if there is a certain server setting that I can ask
>them to change, or a permission that i should be asking for, or
>something. I mean surely other people must want to write files to
>their servers, right?


>org.apache.jasper.JasperException: access denied
>(java.io.FilePermission /pleaseWork.jb write)


We were having very similar issues in our hosted environment. It turned out
that the Tomcat Security Manager had been enabled, and basically denied
everything by default. So they had to go tweak the policies to allow the
things we needed. In addition to file access permissions, we had problems
with sockets and also accessing system properties.

Take a look at the following links... there is probably something similar in
the tomcat 5.x documentation as well.

http://tomcat.apache.org/tomcat-4.1-...ger-howto.html
http://tomcat.apache.org/tomcat-3.3-...-security.html

The policy files are:

$CATALINA_HOME/conf/catalina.policy
$JAVA_HOME/jre/lib/security/java.policy

Good luck...


scott
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-23-2006
tiewknvc9 wrote:

Please refrain from top-posting - I find it most confusing.

> I just called my hosting company, who say I have all the appropriate
> access priviledges...
>
> Which I would rather not believe, but they say its true...


I believe them. Their answer does not surprise me.
(I have heard similar answers from my own web-host/s!)

> Here is what my code reads as:
>
> String curDir = application.getRealPath("");
> System.out.println(curDir);


When I suggested using getRealPath, what I meant was ..

a) Use getRealPath on the string that indicates 'root' - "/".
b) Print the result.
c) Tell *us* that result here...

Andrew T.

 
Reply With Quote
 
tiewknvc9
Guest
Posts: n/a
 
      08-25-2006
Trying to write a file using

FIle x = new File (var + "myNewFile.txt");

where var equals....

BAD -> request.getServletPath()

BAD -> request.getRemoteHost()

BAD -> request.getRemoteAddr()

BAD -> request.getRequestURL()

BAD -> getServletContext().getRealPath("/")



Im at a lose. What am I doing wrong? My hosting company tells me that
I have all the proper permissions.



Andrew Thompson wrote:
> tiewknvc9 wrote:
>
> Please refrain from top-posting - I find it most confusing.
>
> > I just called my hosting company, who say I have all the appropriate
> > access priviledges...
> >
> > Which I would rather not believe, but they say its true...

>
> I believe them. Their answer does not surprise me.
> (I have heard similar answers from my own web-host/s!)
>
> > Here is what my code reads as:
> >
> > String curDir = application.getRealPath("");
> > System.out.println(curDir);

>
> When I suggested using getRealPath, what I meant was ..
>
> a) Use getRealPath on the string that indicates 'root' - "/".
> b) Print the result.
> c) Tell *us* that result here...
>
> Andrew T.


 
Reply With Quote
 
tiewknvc9
Guest
Posts: n/a
 
      08-25-2006
sorry, I did not print the path that was generated. Since they
restart the server at 3am, I uploaded a new file, outputting the path.
So tomorrow I will be able to write the path here...


tiewknvc9 wrote:
> Trying to write a file using
>
> FIle x = new File (var + "myNewFile.txt");
>
> where var equals....
>
> BAD -> request.getServletPath()
>
> BAD -> request.getRemoteHost()
>
> BAD -> request.getRemoteAddr()
>
> BAD -> request.getRequestURL()
>
> BAD -> getServletContext().getRealPath("/")
>
>
>
> Im at a lose. What am I doing wrong? My hosting company tells me that
> I have all the proper permissions.
>
>
>
> Andrew Thompson wrote:
> > tiewknvc9 wrote:
> >
> > Please refrain from top-posting - I find it most confusing.
> >
> > > I just called my hosting company, who say I have all the appropriate
> > > access priviledges...
> > >
> > > Which I would rather not believe, but they say its true...

> >
> > I believe them. Their answer does not surprise me.
> > (I have heard similar answers from my own web-host/s!)
> >
> > > Here is what my code reads as:
> > >
> > > String curDir = application.getRealPath("");
> > > System.out.println(curDir);

> >
> > When I suggested using getRealPath, what I meant was ..
> >
> > a) Use getRealPath on the string that indicates 'root' - "/".
> > b) Print the result.
> > c) Tell *us* that result here...
> >
> > Andrew T.


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      08-25-2006
tiewknvc9 wrote:

Noted your next post, but just quickly..

> Trying to write ..


Stop! Let's just find out exactly where we are
before anyone tries writing (or even thinking of
writing) anything.

>...a file using
>
> FIle x = new File (var + "myNewFile.txt");


Now. Drop the filename for the moment and
try the file name "." to indicate 'the current directory'
as understood by the server at this moment in time.

Then (assuming even that is successful) try
printing it out to ..HTML or whatever.

Also, please refrain from top-posting.
I find it most confusing.

Andrew T.

 
Reply With Quote
 
tiewknvc9
Guest
Posts: n/a
 
      08-25-2006

Andrew Thompson wrote:
> tiewknvc9 wrote:
>
> Noted your next post, but just quickly..
>
> > Trying to write ..

>
> Stop! Let's just find out exactly where we are
> before anyone tries writing (or even thinking of
> writing) anything.
>
> >...a file using
> >
> > FIle x = new File (var + "myNewFile.txt");

>
> Now. Drop the filename for the moment and
> try the file name "." to indicate 'the current directory'
> as understood by the server at this moment in time.
>
> Then (assuming even that is successful) try
> printing it out to ..HTML or whatever.
>
> Also, please refrain from top-posting.
> I find it most confusing.
>
> Andrew T.


will try tonight. Will report results tomorrow morning, if I am asleep
before 4am

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixed: The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID {555F3418-D99E-4E51-800A-6E89CFD8B1D7} to the user NT AUTHORITY\LOCAL SERVICE SID (S-1-5-19). Skybuck Flying Windows 64bit 1 06-29-2009 06:17 PM
file sharing violation. Which permission should I give to the directory and files? James ASP .Net 2 05-02-2006 05:22 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
how to give ASP permission to write to local hard drive? Laszlo Szijarto ASP .Net 1 01-23-2004 07:11 PM
chmod or setuid? Need to give script permission to write files Michael Lubavin Perl 1 07-25-2003 01:16 AM



Advertisments