Hi,

I'm new to this forum, and to developing for/using Tomcat in general (and a
bit of a novice in programming in general). I tried various websites and
tutorials to rectify my problem, with no results.


My Apache Tomcat version is 5.5, installed on Ubuntu 8.04 through the
aptitude package manager.
My Java version (the one $JAVA_HOME points to) is OpenJDK 6, also installed
through aptitude. I am logged in as root user.


PROBLEM DESCRIPTION:


Please note that on my development machine (a manual install of Tomcat 6 on
Ubuntu 9.10), the problem does not exist. I imagine this is an issue between
versions.


I am attempting to log survey responses in a file called "records.txt",
which I keep in the directory of my webapp
(".../webapps/MyWebApp/records.txt"). To this end, I pass parameters to a
JSP file through the "post" method, and write it to a file thus:


RecordKeep.CreateRecord (record, outfile);


This routine is stored in a JAR file in the directory of my webapp (compiled
as v.1.5).  Here is the code for it:



        public static synchronized boolean CreateRecord (String record, String
filename)
        {
                boolean success = true;
                try 
                {
                        File file = new File(filename);
                BufferedWriter out = new BufferedWriter(new FileWriter(file,
true));
                out.write(RECORD_START + record + '\n');
                out.close();
            } 
                catch (IOException e) 
                {
                success = false;
            }

                return success;
        }
}


When I attempt to execute the code through a browser, I get the following
exception from the line where I try to write to the file (the entire trace
is too long to include):


java.security.AccessControlException: access denied (java.io.FilePermission
/usr/share/tomcat5.5/webapps/MyWebapp/records.txt write)


ATTEMPTED SOLUTIONS:

From
http://www.mkyong.com/tomcat/tomcat-javasecurityaccesscontrolexception-access-denied-loggingproperties-read/
I tried two solutions:


1) Change the grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar"
category of permissions in 03catalina.policy to: grant codeBase
"file:${catalina.home}/bin/tomcat-juli.jar" {
        permission java.security.AllPermission;
};


2) Add an additional permission to the same permission clause: permission
java.io.FilePermission
"$${catalina.base}${file.separator}webapps${file.separator}*", "read,
write";


I don't know whether these options are used by default, so I tried running
both ./catalina.sh start and ./catalina.sh start -security to see whether
the security manager might have something to do with it. By this time I was
just groping around in the dark...

Also, I unfortunately can't see whether accessing the server from localhost
might bring different results.


Help would be most welcome, as I'm completely lost, and I need to get this
up and running in a matter of days. Thanks for your time in advance!


Sincerely,

Victor.
-- 
View this message in context: 
http://old.nabble.com/Tomcat-Java-permission-issue----cannot-write-to-file-from-a-webapp.-tp27871316p27871316.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

Reply via email to