The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Security in Java 2 SDK 1.2
Lesson: Quick Tour of Controlling Applets

Grant the Required Permission

To grant the WriteFile applet permission to create and to write to the writetest file, you must create a policy entry granting this permission. To do so, choose the Add Policy Entry button in the main Policy Tool window. This brings up the Policy Entry dialog box, as shown in the following figure.


This figure has been reduced to fit on the page.
Click the image to view it at its natural size.

A policy entry specifies one or more permissions for code from a particular code source - code from a particular location (URL), code signed by a particular entity, or both.

The CodeBase and the SignedBy text boxes are used to specify which code you want to grant the permission(s) you will be adding.

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) where WriteFile.class is stored.

Type the following URL into the CodeBase text box of the Policy Entry dialog box:

http://java.sun.com/docs/books/tutorial/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) not just from the directory specified previously but from the security1.2 directory and its subdirectories, you'd type the following URL into the CodeBase box:
http://java.sun.com/docs/books/tutorial/security1.2/-

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). Now you are ready to grant permissions to that code.

Choose the Add Permission button to bring up the Permissions dialog box.


This figure has been reduced to fit on the page.
Click the image to view it at its natural size.

Do the following to grant code from the specified CodeBase permission to write (and thus also to create) the file named writetest.
  1. Choose File Permission from the Permission drop-down list. The complete permission type name (java.io.FilePermission) now appears in the text box to the right of the drop-down list.

  2. Type the following in the text box to the right of the list labeled Target Name to specify the file named writetest:
    writetest
    
  3. Specify write access by choosing the write option from the Actions drop-down list.
Now the Permissions dialog box looks like the following.


This figure has been reduced to fit on the page.
Click the image to view it at its natural size.

Choose the OK button. The new permission appears in a line in the Policy Entry dialog. So now the policy entry window looks like this.


This figure has been reduced to fit on the page.
Click the image to view it at its natural size.

You are now done specifying this policy entry, so choose the Done button in the Policy Entry dialog. The Policy Tool window now contains a line representing the policy entry, showing the CodeBase value.


This figure has been reduced to fit on the page.
Click the image to view it at its natural size.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.