Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

FilePermission in an Applet

Thread view: 
dbaldes - 28 Nov 2005 12:16 GMT
Hello,

i have a strange thing here with FilePermission in an Applet. To my
understanding an Applet is allowed to access files on the host where it
is loaded from via http, for example; escpecially the applet should be
able to load files included in jars which are given in the
"archive"-attribute of its applet tag (making up its classpath).

I use kodo (a JDO OR-mapping library) in the applet to access a
database. Kodo now tries to read some metadata from a file included in
a jar, which leads to the following exception:

java.security.AccessControlException: access denied
(java.io.FilePermission
http:\gosling:9180\swing-editor\lib\dbobjects.jar!\com\open\mss\db\stop\package.jdo
read)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.File.exists(Unknown Source)
    at
com.solarmetric.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:296)
    at
com.solarmetric.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:279)
[...]

(note the strange http-url)

When i grant FilePermission in the client's policy file, all works
well.

Can somebody tell me what's wrong here? Is it due to the method how
kodo accesses the file?

Thanks in advance,
Daniel
Robert Klemme - 28 Nov 2005 13:26 GMT
> Hello,
>
[quoted text clipped - 3 lines]
> should be able to load files included in jars which are given in the
> "archive"-attribute of its applet tag (making up its classpath).

Normal applets do not have permissions to access files - they are only
allowed to open a network connectio to the host they were loaded from.

> I use kodo (a JDO OR-mapping library) in the applet to access a
> database. Kodo now tries to read some metadata from a file included in
> a jar, which leads to the following exception:
>
> java.security.AccessControlException: access denied
> (java.io.FilePermission

http:\gosling:9180\swing-editor\lib\dbobjects.jar!\com\open\mss\db\stop\package.jdo
> read)
> at java.security.AccessControlContext.checkPermission(Unknown Source)
[quoted text clipped - 18 lines]
> Thanks in advance,
> Daniel

Your problem is that the code tries to access the File through the File
interface while you want to do it via the ClassLoader (try to use
getResourceAsStream()).  You should hand XMLMetaDataParser.parse() a
stream obtained from the ClassLoader instead of using a file name.  This
file name is most likely interpreted as local file (i.e. on the browser's
machine).

Kind regards

   robert
Roedy Green - 28 Nov 2005 16:43 GMT
>i have a strange thing here with FilePermission in an Applet. To my
>understanding an Applet is allowed to access files on the host where it
>is loaded from via http, for example; escpecially the applet should be
>able to load files included in jars which are given in the
>"archive"-attribute of its applet tag (making up its classpath).

I have found they have to be "downstream".  See
http://mindprod.com/jgloss/applet.html
for what I mean by that
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.