| 6.170 | Laboratory in Software Engineering
Spring 2000 Amendments to Problem Set 5b Due: March 16, 2000 Handout 14 |
The following amendments deal with the runtime environment of the applet that you are writing. They do not alter specifications, or change the overall functionality of the applet. Amendment 3 deals with Java applet security, something that was strengthened between Java 1.1 and Java 2.
<applet code="ps5b.PathFinder" width=600 height=500 align="middle"></applet>
In addition to the content of the file, we request that you change the location of the file. Please put the file in your ~/6.170 directory. Note this was different than the previous specified directory.
1. When you run the appletviewer (with the security policy), the appletviewer completely ignores the currently set CLASSPATH in the environment. One way to solve this problem is to pass the CLASSPATH variable when you run appletviewer (you need to pass the security policy as well as discussed in Amendment 3):
| athena% appletviewer | -J-Djava.class.path="$CLASSPATH" |
| -J-Djava.security.policy=pathfinder.policy | |
| PathFinder.html |
Another solution is to copy your files from ~/6.170/ps5a directory into ~/6.170/ps5b directory and change the package name in every file from ps5a to ps5b. All of the *.class files in /mit/6.170/class/ps5a have been copied into /mit/6.170/class/ps5b under the appropriate package name (package ps5b), so you can copy them into your ps5b directory and run appletviewer without passing the CLASSPATH variable.
2. Assume that the running time of the methods in WtDigraph and DistanceChart is O(n) time, where n is the number of nodes in the graph (or distance chart).
3. Small change to the specs for WtDigraph and DistanceChart: for those methods that modify this, the following statement has been added to the effects clause: "if an exception is thrown, this is not modified".
When running the applet in the manner described in Handout 13, and accessing the database file located at http://web.mit.edu/6.170/src/ps5a/test.database, the applet throws a security exception (java.security.AccessControlException), claiming that the applet does not have permission to resolve the address "web.mit.edu".
Explanation:
Java applets have stricter security criteria than Java applications. The restriction that the applet is running up against here is the fact that an applet downloaded from one host cannot resolve word based internet addresses to the numerical internet addresses used to connect to a different host. Even if it was able to resolve the word based internet address "web.mit.edu" to its numerical internet address "18.72.0.42", the applet would next come upon the even worse restriction that it does not even have permission to connect to the host web.mit.edu. This is all because the host where you download the applet from (which we will call localhost), is not the host that the applet wants to connect to (web.mit.edu). The only case this would work is when you download the applet from web.mit.edu, which is entirely possible if you decided to put your applet in a directory that could be accessed over the web. Java people belovedly call these applet restrictions the Java sandbox. Sandbox refers to the restricted area in which a downloaded applet can "play".
Solution:
Copy the file "/mit/6.170/src/ps5b/pathfinder.policy" into your ~/6.170 directory using the following command:
athena% cp /mit/6.170/src/ps5b/pathfinder.policy ~/6.170
Invoke the appletviewer using the following command from your ~/6.170 directory, passing the policy along to the appletviewer:
athena% appletviewer -J-Djava.security.policy=pathfinder.policy PathFinder.html
The policy described in the file pathfinder.policy allows the applet to resolve addresses of hosts and connect to hosts within the *.mit.edu domain. For more information on Java applet security "fun", check out the web site Java 1.2 Security .