Quick Tour of Controlling Applets |
To grant theWriteFile
applet permission to create and write to thewritetest
file, you must create a policy entry granting this permission.Select the Add Policy Entry button in the main "Policy Tool" window. This brings up the "Policy Entry" dialog box:
A policy entry specifies one or more permissions for code from a particular code source - either code from a particular location (URL), or code signed by a particular entity, or both.
The CodeBase and SignedBy text boxes are used to specify which code you want to grant the permission(s) you will be adding.
- A CodeBase value indicates the code source location; you grant the permission(s) to code from that location. An empty CodeBase entry signifies "any code"; it doesn't matter where the code originates from.
- A SignedBy value indicates the alias for a certificate stored in a keystore. The public key within that certificate is used to verify the digital signature on the code; you grant the permission(s) to code signed by the private key corresponding to the public key in the keystore entry specified by the alias. The SignedBy entry is optional in that, if it is omitted, it signifies "any signer". It doesn't matter whether the code is signed or not or by whom.
If you have both a CodeBase and a SignedBy entry, the permission(s) will be granted only to code that is both from the specified location and signed by the named alias.
To grant
WriteFile
the permission it needs, you can grant the permission to all code from the location (URL) whereWriteFile.class
is stored.Type the following URL into the CodeBase text box of the "Policy Entry" dialog box:
http://java.sun.com/docs/writing/tutorial/src/security1.2/tour1/example-1dot2/(Note, this is a URL and thus must always have slashes, not backslashes.)Leave the SignedBy text box blank, since you aren't requiring the code to be signed.
Note: If you wanted to grant the permission to any code (.class
file) from thehttp://java.sun.com/docs/writing/tutorial/src/security1.2directory and its subdirectories rather than just to code from the directory specified above, you would type the following into the CodeBase box:http://java.sun.com/docs/writing/tutorial/src/security1.2/-
Now that you've specified where the code comes from (the CodeBase), and that the code does not have to be signed (since there's no SignedBy value), you are ready to grant permissions to that code.
Select the Add Permission button. This brings up the "Permissions" dialog box:
Do the following to grant code from the specified CodeBase permission to write (and thus also create) the file namedwritetest
:
java.io.FilePermission
)
now appears in the text box to the right of the drop-down list.
writetest
:
writetest
Select the OK button. The new permission appears in a line in the "Policy Entry" dialog. So now the policy entry window looks like this:
Note: Each backslash in the file path you typed has been replaced with two backslashes, as described in Note Regarding File Specifications.
You are now done specifying this policy entry, so select the Done button in the "Policy Entry" dialog. The "Policy Tool" window now contains a line representing the policy entry, showing the CodeBase value:
On Windows systems, when you type a file name and path into a Policy Tool dialog box (e.g., as a FilePermission target name), you can use any of the following as the directory separator:
Single backslashes are the "normal" Windows directory separators, and slashes are also accepted.
- a single backslash, as in
C:\Temp\data
- a double backslash, as in
C:\\Temp\\data
- a slash, as in
C:/Temp/data
However, policy files themselves cannot contain single backslashes. When a policy file is read, the strings are processed by a tokenizer, which allows "\" to be used as an escape string (e.g., "\n" to indicate a new line) and which thus requires two backslashes to indicate a single backslash.
If you use single backslashes as your separators, Policy Tool automatically converts them to double backslashes (e.g., after you select OK in the Permissions dialog box), for your convenience.
Quick Tour of Controlling Applets |