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

LOGGING APIs: some methods does not throw required SecurityException

XMLWordPrintable

    • beta
    • generic
    • generic
    • Verified



      Name: dkR10031 Date: 09/12/2000


      Logging APIs implementation (v. 0.49) fails the test
      nsk/logging/StreamHandler/close/close002 from testbase_nsk.

      StreamHandler.close does not throw SecurityException when a security
      manager exists and the caller does not have LoggingPermission("control"),
      as it is stated by the spec.

      Log and simplified test source follow:

      $ java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      $ java close002
      ERROR: no SecurityException

      ------------------------------------------------------------------ close002.java
      import java.util.logging.*;
      import java.io.*;
      import java.security.*;

      public class close002 {

          static final int STATUS_FAILED = 2;

          static PrintStream out;
          static Logger logger = Logger.getLogger("close002");
          static ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
          static StreamHandler streamHandler2;
          private final static LoggingPermission loggingPermission
              = new LoggingPermission("control","");

          public static void main(String argv[]) {
      System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }

          public static int run(String args[], PrintStream ref) {
      LogManager manager = LogManager.getLogManager();
      manager.removeAllGlobalHandlers();
      logger = Logger.getLogger("close002");

      Formatter formatter = new close002_formatter();
      streamHandler2 = new StreamHandler(stream2, formatter);

      logger.setLevel(Level.ALL);
      logger.addHandler(streamHandler2);

              return execute(args, ref);
          }

          public static int execute(String args[], PrintStream out) {
      int res = 0; // STATUS_PASSED
      logger.info("m1");
      logger.severe("m2");
      System.setSecurityManager(new StrictSecurity());
      try {
      streamHandler2.close();
      out.println("ERROR: no SecurityException");
      res = STATUS_FAILED;
      } catch (SecurityException e) {
      }
      return res;
          }


          /**
           * Stricter security manager intended to deny logging permission.
           */
          private static class StrictSecurity extends SecurityManager {
              public void checkPermission (Permission permission) {
                  if ((permission instanceof LoggingPermission) ||
                       permission.implies(loggingPermission))
                  // then:
                      throw new SecurityException("denied by the test: "
                          + permission);
              }

              public void checkPermission
                  (Permission permission, Object context)
              {
                  if ((permission instanceof LoggingPermission) ||
                       permission.implies(loggingPermission))
                  // then:
                      throw new SecurityException("denied by the test: "
                          + permission + " at " + context);
              }
          }
      }

      class close002_formatter extends Formatter {

          public String format(LogRecord record) {
      return record.getMessage();
          }
      }

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

      Name: dkR10031 Date: 09/13/2000


      The same is true for MemoryHandler.setPushLevel method: it does not throw
      SecurityException when it should.
      ======================================================================

      Name: szR10032 Date: 09/14/2000


      The same is true for SocketHandler.close and FileHandler.close methods:
      they do not throw SecurityException when they should.

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

      Name: elR10090 Date: 02/01/2001


      This bug affects the following testbase_nsk test:
          nsk/logging/MemoryHandler/setPushLevel/setpushl002
          nsk/logging/FileHandler/close/close002
          nsk/logging/SocketHandler/close/close002


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

            ghamiltosunw Graham Hamilton (Inactive)
            dimasunw Dima Dima (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: