How to make a signed applet to check for file permissions?

I have two applets both of which will be called simultaneously. In the applet there are is a text field.Is it is possible to stop the user from writing anything into to the applets text field.Thanks in Advance!
[231 byte] By [ThirukumaranGa] at [2007-9-29 19:51:53]
# 1

I have some questions about your post, it's not very clear to me:

a) what has you post to do with your subject line (file permissions) ?

b) why are there two applets. the question has nothing to do with both applets

c) your question has nothing to do with the fact, that both applets are called simultaneously.

d) why do you want to stop the user from editing a text field? just remove the text field from the applet, and the user won't be able to edit it any more....

okay, perhaps you wanted to know, if it is possible, that Applet A can control Applet B in such a way, that if something happens, the textfield in Applet B gets disabled (remotely by Applet A) ?

you can get a list of all running applets on the same website with the following code:

Enumeration applets = this.getAppletContext().getApplets();

while(applets.hasMoreElements()) {

Applet otherApplet = (Applet) applets.nextElement();

// now you can control the other applet

}

use this in Applet A to get Applet B. once you have found Applet B, you can call a method , something like disableTextfield().

To disable a textfield, use this:

TextField username = new TextField();

username.setEditable(false);

hamstaa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 2
hi,My description didn't mean that and in-fact I would like to know how to make the applets file reading permisssions with the help of the .java.policy. It may be for one or more than one applets.Thanks in advance
ThirukumaranGa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 3
The fact is that it it reads a file "autoexec.bat " from the system drive. How to make it read only using an applet.
ThirukumaranGa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 4

sorry, but i really don't understand you.

do you mean this:?

grant codeBase "http://url.to/your/applet.jar" {

permission java.security.AllPermission;

permission java.io.FilePermission "autoexec.bat", "read";

};

or do you want to change the file attributes (read-only, system file, hidden) of the file? ("make the file read-only")

hamstaa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 5
I'd like to change the attributes of the file.
ThirukumaranGa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 6
i have only found a method to set the read-only attribute of a file.i could not find anything about setting the hidden, system-files or archive-bits.File f = new File("myfile.txt");f.setReadOnly();
hamstaa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 7
Well, I would like to do the same in the policy file itself instead of doing the same programatically.Thanks in advance!
ThirukumaranGa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 8

please, please, please be MORE INFORMATIVE.

your posts are very hard to understand, in fact, not understandable.

at first, you are talking about a text field, which you want to be read-only.

then, it's the policy file. and after that, it's a file attribute in the file system.

then, it's the policy file again.

you will explain all that to me with at least 200 words, otherwise i won't answer.

hamstaa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 9

Hi,

Here is what I would like to do.Please revert back the part you dont understand

1.The applet has an option to open the file and read its contents.

2.It may be any file which is readable in the notepad.

3.I want the end user to stop writing anything on it.

4.When he writes anything on it then it should throw a security exception in the command prompt.

5.With the .java.policy file can this be done?

6.If know then please tell other methods?

7. I want the command prompt to throw an security exception when something is done?

ThankYou.Please revert back if you have any clarifications in this regard and the portion of the mail you dont understand.

ThirukumaranGa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 10

you tried the setReadOnly() method and it didn't work?

i don't think the java.policy file will work, because it seems that you want to change the behaviour while the program is running?

you are writing that you have an applet. the user starts the applet. when he can use the applet to change the contents of a text file (files which can be opened in notepad?)

if some event occurs, you want to stop editing, so the user can't edit any more. you want that a security exception is thrown.

you can throw your own security exception with "throw <ExceptionName>"

hamstaa at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 11

Hi Experts, I need to know how to make a read-only file writable. The File class has a method to find out if a file is read-only and a method to set a file read-only called setReadOnly(), but not a method to set a file not read-only; i.e. setNotReadOnly(). Does anyone know a way to make files not read-only/writable?

Regards,

Deepali

deepali25a at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 12

Hi People,

I have found a solution, I am not sure if its the best one but just thought of post FYI.

Process p = Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\attrib -r " + filename);

This did the trick. Please let me knwo if anybody has a better solution.

Regards,

Deepali

deepali25a at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...
# 13

> Hi People,

>

> I have found a solution, I am not sure if its the

> best one but just thought of post FYI.

>

> Process p =

> Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\attr

> ib -r " + filename);

>

> This did the trick. Please let me knwo if anybody has

> a better solution.

>

> Regards,

> Deepali

IO API doesn't allow to make file writable that is currently read only.

I would prefer to delete the file and write it again.

This seems portable solution though ugly.

k_i_shora at 2007-7-15 21:45:29 > top of Java-index,Security,Signed Applets...