Here are some helpful hints for phase I of the programming assignment.
-
Grant the Necessary Permissions
The client connects to the server by opening a socket on port
6666 of localhost.
Thus, in order to run the client and
server, you must create a policy file that grants permissions for this
socket to both the client and server.
In addition, you will need to grant the
client permissions to use the AWT (see the
standard
permission documentation)
, as well as to grant the
ServerStub the RuntimePermission checked for in the
Server.
More generally, to determine what permissions are needed to execute
some piece of code, simply try to execute that code.
If the Java 2 runtime system throws a security exception then
(i) read the error message,
(ii) note the permission that is lacking,
and (iii) add the necessary lines to the policy file.
-
Take Care Typing Policy Files
Java 2 has poor support for debugging policy files.
The system does not give warnings about typos and other common
errors that you can (and will) make in building a policy file.
It is easy to leave-off a slash, for example, and have created a completely
useless policy file.
(We speak from experience.)
Also, remember the meanings of the different policy file codebase specifications,
as described in the policy
file documentation.
For example, codebases refer to directories -- not individual files.
It is easy to use the wrong suffix on a codebase specification
to create a policy file that is too liberal in the
permissions it grants.
Practice the Principle of Least Privilege!
A good strategy would be to separate the server and client directories so that
it is more difficult to make a mistake is writing your policy files.
Once you have finished developing your solution, make sure the
directory structure you devised also conforms to the
submission directions.
- Edited 2/27:
Safeguard Only Communication Operations
Invocations of CheckPermission or doPrivilege
you add in Part I.1 to ensure that
- ClientStub can only be used by Client.
- ClientComm can only be used by ClientStub.
- ServerStub can only be used by ServerComm.
- Server can only be used by ServerStub.
might be added to the
red operations in problem specification and
to doCommand() in ServerComm.
-
Syntax of doPrivileged
This syntax is "magical" and it's easy to make a mistake.
Read the doPrivileged documentation --
especially the section on returning values and accessing local
variables.
-
Set Your classpath Correctly
Make sure all your directories are in the classpath
when you compile and run the client and the server.
Use the -classpath
argument to javac and the -cp argument to
java.
-
Added 2/22:
Codebases versus classpaths
The relationships between codebases in the Java 2 policy file,
the "classpath" used by the Java 2 tools,
and the way directories are used to create packages in Java 2 is confusing.
Packages appear in directories, but only the root of such a directory is usable
in policy file codebases or in classpaths.
For example, the class A in package B is named B.A
and appears as file B\A.class.
Permissions for A should be given to the parent directory of B (!!!).
Thus, if the full path is
Z:\home\fbs\B\A.class then the directory to use
in a codebase of a classpath argument is Z:\home\fbs.
Confusing?
Make codebase and classpath references point to the parent directory of all
package directories.
Returning to GradeSheet,
if the client package directory and the server package directory are both placed in the
same directory, then both the client and the server will have the same codebase.
But this would not allow a policy file to grant different permissions
to the client than it grants to the server --- a problem.
To circumvent the problem, a different directory structure should be used.