Java Q&A
by Lou Grinzo


Listing One
public class mutableBoolean
{ public boolean enabled; }

Listing Two
// SMdemo: SecurityManager demo program. See the comment
// in main() before running this program.

import java.lang.*;
import java.io.*;
import java.util.*;

class SMdemo
{
  static public void main(String[] args)
  {
    // Only enable one of the following two lines!
    doSmartTest();
    // doSwitchableTest();
  }
  ///////////////////////////////////////////////////////////////////
  static void doSmartTest()
  {
    String[] untrusted_class_names = { "untrusted1" };
    String[] trusted_class_names = { "trustedSmart" };

    smartSM sm = new smartSM(untrusted_class_names,
      trusted_class_names);

    AddDumpLine("SMdemo: About to install custom SM.");
    System.setSecurityManager(sm);
    AddDumpLine("SMdemo: Just installed custom SM, about to run test.");

    trustedSmart tSmart = new trustedSmart();
    tSmart.doTest();

    AddDumpLine("SMdemo: Just returned from trustedSmart; about to end.");
  }
  ///////////////////////////////////////////////////////////////////
  static void doSwitchableTest()
  {
  AddDumpLine("SMdemo: About to run test.");
  trustedSwitchable tSwitchable = new trustedSwitchable();
  tSwitchable.doTest();
  AddDumpLine("SMdemo: Just returned from trustedSwitchable; about to end.");
  }
  ///////////////////////////////////////////////////////////////////
  static private void AddDumpLine(String s)
  {
    try
    {
      RandomAccessFile ofile =
        new RandomAccessFile("SMdemo_dump.txt","rw");
      ofile.seek(ofile.length());
      ofile.writeBytes(s);
      ofile.writeBytes("\r\n");
      ofile.close();
    }
    catch (IOException e)
    {
      System.err.println(e);
      return;
    }
  }
}



9


