Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

Using policytool [JDK 1.2]

 
Training Index


Help | Solution | API Docs | Expected Output
Course Notes | Magercises | Module Intro

Skeleton Code

This magercise takes you through the steps necessary to allow an applet to write to a local file. Using policytool, you open up a selected part of the Java security model to permit this capability. The JRE's access controller will not permit access to other files.

See the A Quick Look at policytool course section for additional information.

Perform the following tasks:

  1. Compile the PLTester.java program. It contains a JTextField that contains a file to save to, a JTextArea that contains the text to save, and a JButton to save the text area to the file specified by the text field, when the button is selected.

  2. Save the PLTester.html loader and try the program without using policytool. Select Save to try to save the contents to any filename entered. This will generate a security violation.

  3. Start up policytool.

  4. Open the real policy file.

  5. Select Add Policy Entry and enter "file:." in the CodeBase field. This means you are updating the security policy for classes loaded from the current directory.

  6. Next select Add Permission to bring up the Add New Permissions screen.

  7. For a permission, select FilePermission in the first option.

  8. For a target, enter the filename you wish to make writable.

  9. For the actions option, either select write or enter write in the field to its right.

  10. Then select OK to close this window.

  11. On the Policy Entry window, select Done.
    On the opening screen, select File|Save to update the policy file.

  12. At this point, rerun the test applet and see if the file is writable. Try different values for the filename to ensure ONLY that file is writable and nothing else.

  13. After testing the applet, be sure to remove the entry from the policy file with policytool. Just select the appropriate code base from the policy file then select Remove Policy Entry to get rid of it and confirm the removal. Next select File|Save to save the updated policies.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and a demonstration of the expected behavior.

Copyright © 1998 MageLang Institute. All Rights Reserved.