java.lang.ClassNotFoundException Thrown by the
ClassLoader on the com.ms.security
Package
Symptoms
When running an applet in a browser using the Sun
JavaTM Runtime Environment
(JRETM), a
java.lang.ClassNotFoundException is thrown by the
ClassLoader on the com.ms.security
package. The same applet runs without any error under the Microsoft
Virtual Machine (VM).
Cause
The Microsoft VM provides the proprietary
com.ms.security package for applets and applications
to access the security policy at runtime. Because this package is
not available in the Sun JRE, a
java.lang.ClassNotFoundException is thrown when the
applet runs in a browser.
Resolution
Migrate the applet source from the com.ms.security
package to the java.security package by using similar
classes.
For example, the following applet uses
com.ms.security.PolicyEngine to assert the network I/O
permission before connecting to a URL:
public class AssertPermissionApplet extends
java.applet.Applet
{
public void init()
{
try
{
// Assert permission on network I/O
com.ms.security.PolicyEngine.assertPermission
(com.ms.security.PermissionID.NETIO);
java.net.URL url = new
java.net.URL("http://randomhost/randomfile");
.....
} catch
(java.net.MalformedURLException mue) {
}
catch
(java.io.IOException ioe) {
}
} // init
}
In the Java technology,
java.security.AccessController provides similar
functionality for permission assertion. The following source code
displays the functionality after migration:
public class AssertPermissionApplet extends
java.applet.Applet
{
public void init()
{
try
{
// Assert permission on network I/O
java.security.AccessController.checkPermission(new
java.net.SocketPermission("randomhost:80",
"connect,accept"));
java.net.URL url = new
java.net.URL("http://randomhost/randomfile");
.....
} catch
(java.net.MalformedURLException mue) {
}
catch
(java.io.IOException ioe) {
}
} // init
}
See the JavaTM SE technology
API documentation for more details about security.