java.lang.ClassNotFoundException thrown on com.ms.security package when applet runs


Symptoms

When running an applet in a browser using the Sun JRE, a ClassNotFoundException is thrown by the ClassLoader on the com.ms.security package. The same applet runs under the Microsoft VM.

Cause

The Microsoft VM provides the proprietary com.ms.security package for applets and applications to access the security policy at runtime. This package is not available in the Sun JRE, so a ClassNotFoundException is thrown when the applet runs.

Resolution

The workaround is to migrate the applet source from using the com.ms.security package to using similar classes in the java.security package.

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 2 platform, java.security.AccessController provides similar functionality for permission assertion. Here is the source code after migration:

public class AssertPermissionApplet extends java.applet.Applet
{
    public void init()
    {
        try
        {     
            // Assert permission on network I/O
            java.net.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
}

Please refer to the J2SE API documentation for more details on security.

Related Information

        See Security.