Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

Help is available for each task, or you can go straight to the solution source code.



Task 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.


javac PLTester.java

Task 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.


appletviewer PLTester.html

Task 3

Start up policytool.


policytool

Task 4

Open the real policy file.


By default, this is the java.policy file in the security directory, under the JRE installation. If you do not have write permission on this file, create a file called .java.policy in your home directory.

Task 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.


Task 6

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


Task 7

For a permission, select FilePermission in the first option.


This will place java.io.FilePermission to the right of the selection.

Task 8

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


For demonstration purposes, use c:\temp\test.out or some reasonable facsimile.

Task 9

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


Task 10

Then select OK to close this window.


This returns you to the Policy Entry window.

Task 11

On the Policy Entry window, select Done.


This adds an entry to the first screen for the new code base.

Task 12

On the opening screen, select File|Save to update the policy file.


You should see a status message displayed, just select OK to close it.

Task 13

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.


Task 14

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.


Copyright © 1998 MageLang Institute. All Rights Reserved.

[ This page was updated: 16-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.