FilePermissions
Im trying to make an applet that will read from a file, but, since applets dont allows for that, i need to give it permissions. Unfortuently i dont know how to use FilePermmissions to do this. i think this is what i do but im not sure
FilePermission fi =new FilePermission("C:/Temp/file","Read");
Can someone help me or point me to a tutorial that shows me how to do this in java?
You need to sign your applet then the applet container will allow it to access local file system
LRMKa at 2007-7-14 20:59:44 >

Hi,tutorial on java security including permissions can be found here: http://java.sun.com/docs/books/tutorial/security/TOC.htmlL.P.
lukika at 2007-7-14 20:59:44 >

Im doing the tutorial now, but when i use command prompt to create a jar, it says jar is not a reconizable command, even though i coppied and pasted the code directly from the site.
Do you have JDK installed? if yes you havent put your java/bin directory in to the path environment variable.
LRMKa at 2007-7-14 20:59:44 >

Ok, i got the tutorial to work, but now i have a concern. Is this the only way to do it? Because i dont want the user to have to add a policy using policy tool in order to use my program. Im fine with using an executable jar, but how can i make it so they dont have to add policies and use command prompt to run the jar/java file? Also, how do i create a jar file for applets since applets do not have a main method?
Message was edited by:
h3lladvocate
See replies #1 and #2. Again.
ejpa at 2007-7-14 20:59:44 >

Ok, i have, over nd over again, and ive looked and did the tutorial. The tutorial, however, signs an application, not an applet. I need to sign the applet for write permissions, not an application.
> Im trying to make an applet that will read from a
> file, but, since applets dont allows for that, i need
> to give it permissions. Unfortuently i dont know how
> to use FilePermmissions to do this. i think this is
> what i do but im not sure
> > FilePermission fi = new
> w FilePermission("C:/Temp/file", "Read");
>
>
> Can someone help me or point me to a tutorial that
> shows me how to do this in java?
Hi Dear !!
The simplest way to assign permissions to the applet is just use policytool.
From the command prompt run the command policytool and add the necessary permissions and save the policy file with ".java.policy" name under your profile folder
Sign the JAR file of the applet.
ejpa at 2007-7-14 20:59:44 >

Ok, but what file do i add to the JAR file. Do i add the HTML file, or the class file of the java file that has the Init() method? Also, is there a way to edit the policy file without using policytool. Basically, i want the user to only have to use the java file, and nothing else if possible.
Message was edited by:
h3lladvocate
You don't edit the policy file because it's not on your computer. The user whose computer contains the policy file would have to edit it to include your permissions. So you'd have to provide instructions to the user about how to do that. And if you were careless (or evil), you could tell the user to change the policy file in such a way that it gave ALL applets permission to access data on their computer.
Does this still sound like a good idea? Didn't think so. Go back to the signed-applet idea and carry on with that.
Im trying to do the signed applet thing but im not getting how it works. First of all, im not sure how to use it with an applet, only an applecation. Second its a bit confusing. I know how to create the jar, create a certificate for the jar and stuff like that now, but im not sure how all this helps. If i sign it does it automatically give it permissions?
Please can someone answer the first question and tell me what signing actually does and how it helps with permissions?
> If i sign it does it automatically give it permissions?
No. What happens next is that somebody loads the page that includes your applet. The browser notices that it's a signed applet and it puts up a dialog telling the user that the applet is requesting permission to do whatever it was you asked for when you signed the applet. If the user accepts, then your applet has those permissions. If the user refuses, then it doesn't.
You probably haven't thought through the implications, but if you do you should realize there is nothing you can do that will automatically give you permission to do unsafe things on somebody else's computer. Frankly if you hadn't heard that there are people out there who want to break into other people's computers and install harmful software on them -- something you could do with a signed applet -- then you shouldn't be developing web software just yet. But I'm sure you had heard that, you just didn't make the connection to your own activities. Locks work equally against bad guys and good guys.
