This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
i have a question/problem regarding reading files from a JAR file with active SecurityManager. I don't know if i'm right in this forum. Please correct me if i should eventually post in the "Java in general" forums.
I have a webapplication which loads a properties file from inside a JAR file. This causes an Exception like this:
Notice that the URL contains a "...securitytest.jar!/de/...". If i grant specific access to this file using a policy like this:
I still get the AccessControlException. Enabling the <<ALL FILES>> policy works but is in my opinion no feasible solution.
Does anybody know how to allow the application to read the file and which permissions i have to grant. I Also tried the URLs:
Any hints or (better ) solutions would be greatly appreciated.
Code to reproduce SecurityTest.java
You have to create a jar (i did it using Eclipse).
The commandline (using SUNs Java):
Thanks very much in advance!
Edit: I know that i could circumvent this problem if catch the AccessControlException and ignore it but unfortuneionatly this code is in a 3rd party JAR.
best regards, Sebastian
[ May 04, 2007: Message edited by: Sebastian Himberger ]
[ May 04, 2007: Message edited by: Sebastian Himberger ] [ May 04, 2007: Message edited by: Sebastian Himberger ]
I've checked that the container is using my policies and granted the permissions to either the complete codebase (for testing) and also to the specific webapplication using:
The problem is imho that java is not able (or i'm not able to tell it ) to handle this kind of URL. You can see this if you add the following inside the IOException catch block:
You'll see that if you're running the code without a security manager an IOException "File not found" will be thrown. If the security manager is enabled the right to access this (for Java IO not accessible) file is checked and fails because this kind of URL seems not to be handled by my policies. Therefore the method returns with the AccessControlException .
My only idea is either enabling file reading for all files or patch the library what could be a maintenance problem.
Any ideas left?
thanks very much, Sebastian [ May 04, 2007: Message edited by: Sebastian Himberger ]
Joined: Nov 29, 2005
You can try out this.Use Absolute location , if this works then try using some TOMCAT or CATILINA varialbe in the path .AtLeast you will come to know what exactly is the promble.
Would giving permissions to read all of the jar file work (i.e., without the part about the path inside of the file)? I doubt that file permissions work on a level more fine-grained than a complete file.