CS 426, Spring, 2008, HW 5.
Due February 29, 2008, 11:30 AM (beginning of class).
In this homework, we will learn about the FilePermissions in Java.
***********************************************************************
Read about Java Security Architecture at
http://java.sun.com/j2se/1.5.0/docs/guide/security/spec/security-specTOC.fm.html.
Read the Sections 1, 2, 3.1, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.1.5.

Play with FilePermission - java.io.FilePermission. Use "javac" and "java" on lore.cs.purdue.edu at /p/java-1.5/bin.
Learn how to set permissions of a file - FilePermission p = new FilePermission("myfile", "read,write"); or so.
***************************************************************************

1. Write a program FilePermissions.java - with a class "FilePermissions". In comments, add your name, cs account id. The program does the following: there is a method for each step; the method for a step 'i' is named as "methodi". (1) Create a file "permstest", create a permission object with "write" permission using FilePermission; write the date at that time (java.util.Calendar.getInstance().getTime().toString()) and your e-mail id to the file "permstest". (2) Then change the permission of the file to "read". (3) Read the file "permstest" and print the content of the file and current date/time. (4) Then try to write the current date to the file; show the result - did it succeed? Change the permissions of the file to "read, write, execute". Compare its permissions to the file permissions - "read", "write", "execute" and "delete" and show the outputs as the comparison results. Write a main() method in the program that invokes method1,2,3,4 in this order with a delay in between each method call to be "n" seconds, where "n", is specified as a command-line parameter to the program. The program should be runnable as "Java FilePermissions n". The delay is added as Thread.sleep(). The program must display on the screen (=print), whatever it writes to or reads from the file. Before reading from and writing to the file, the program checks its permissions on the permission object for read/write respectively and proceeds if the check succeeds.

2.Turn in the following documents all together using "turnin".

A listing of the program "FilePermissions.java" in a directory "yourid_HW5" and a README file with solution to the following questions and with your name and email address (cs account) mentioned in README.

3. Could you set the permissions of a file to different permissions (that creates two different FilePermission Objects) at the same time? Could the permission of a file set by FilePermission be different than the permissions set in your Unix system - that is Unix has permission for a file to be "read", could it be set to "read" and "write" using Java? Yes/no?