Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4178705

STD: Problems debugging SecurityManager subclasses

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 1.3.0
    • 1.1.6
    • core-svc
    • beta
    • sparc
    • solaris_2.5.1
    • Not verified

    Description



      Name: mf23781 Date: 10/05/98


      There are problems debugging SecurityManager subclasses using JDK1.1.6.

      The following example is used to illustrate the problems.

      import java.io.*;

      public class OurSecurityManager extends SecurityManager {
       private String password = null;

       public OurSecurityManager(String st) {
        password = st;

       }
       private boolean access() {
        DataInputStream dis = new DataInputStream(System.in);
        String _str = null;

        try {
                System.out.println("Enter your password for verification");
                _str = dis.readLine();

        }
        catch (IOException e) { System.out.println("IOException");}
        return _str.equals(password);
       }

       public void checkRead(int fd) {
        if (!access())
              throw new SecurityException("Access is denied");

       }
       public void checkRead(String fileName) {
        if (!access()) //TC0003.01
              throw new SecurityException("Access is denied");

       }
       public void checkWrite(int fd) {
        if (!access())
              throw new SecurityException("Access is denied");

       }
       public void checkWrite(String fileName) {

        if (!access())
              throw new SecurityException("Access is denied");

       }

       public static void main(String args[]) {

              //'Java' is the password
              OurSecurityManager sm = new OurSecurityManager("Java");
              SecurityManager sm_current = System.getSecurityManager();

              System.setSecurityManager(sm);
              sm_current = System.getSecurityManager();

              Class c[] = sm.getClassContext();
              ClassLoader cl = sm.currentClassLoader();

              System.out.println(c);

              System.out.println(cl);

              try {

                //Open a file and read
                FileInputStream fis = new FileInputStream("OurSecurityManager_in.txt");
                //TC0002.01
                byte buffer[] = new byte[fis.available()];

                fis.read(buffer,0,buffer.length);
                System.out.write(buffer);

                fis.close();

              }
              catch (IOException e) {System.out.println("IOE") ;};
       }
      }

      1) typing "list" at the jdb prompt resumes executing the program
      instead of listing it.

      a) Set a breakpoint in OurSecurityManager.access
      b) run (to breakpoint)
      c) where (produces the stack trace)
      d) list (resumes executing the program)

      2) spurious java.lang.SecurityException

      a) Set a breakpoint stop in OurSecurityManager.main:49
          (on OurSecurityManager sm = new OurSecurityManager("Java");)
      b) type "next" three times and the Exception is raised
         trying to get the Security Manager.
      c) once the Exception is raised, the "where" command works but "list" comand
         starts running the "acess()" code.

      Note: stepping has similar problems.



      ======================================================================

      Attachments

        Activity

          People

            ghirschsunw Gordon Hirsch (Inactive)
            miflemi Mick Fleming
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: