Class JNLPSecurityManager


  • class JNLPSecurityManager
    extends java.lang.SecurityManager
    Security manager for JNLP environment. This security manager cannot be replaced as it always denies attempts to replace the security manager or policy.

    The JNLP security manager tracks windows created by an application, allowing those windows to be disposed when the application exits but the JVM does not. If security is not enabled then the first application to call System.exit will halt the JVM.

    Version:
    $Revision: 1.17 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.SecurityException closeAppEx
      this exception prevents exiting the JVM
      private boolean exitAllowed
      Sets whether or not exit is allowed (in the context of the plugin, this is always false)
      private java.lang.Object exitClass
      only class that can exit the JVM, if set
      private static Logger LOG  
      private sun.awt.AppContext mainAppContext
      The AppContext of the main application (netx).
      private WeakList<ApplicationInstance> weakApplications
      weak list of applications corresponding to window list
      private WeakList<java.awt.Window> weakWindows
      weak list of windows created
    • Constructor Summary

      Constructors 
      Constructor Description
      JNLPSecurityManager()
      Creates a JNLP SecurityManager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addPermission​(java.security.Permission perm)
      Adds a permission to the JNLPClassLoader.
      private boolean askPermission​(java.security.Permission perm)
      Asks the user whether or not to grant permission.
      void checkAwtEventQueueAccess()
      Tests if a client can get access to the AWT event queue.
      void checkExit​(int status)
      Checks whether the caller can exit the system.
      void checkPermission​(java.security.Permission perm)
      Throws a SecurityException if the permission is denied, otherwise return normally.
      boolean checkTopLevelWindow​(java.lang.Object window)
      Checks whether the window can be displayed without an applet warning banner, and adds the window to the list of windows to be disposed when the calling application exits.
      protected void disableExit()  
      protected ApplicationInstance getApplication()
      Return the current Application, or null if none can be determined.
      protected ApplicationInstance getApplication​(java.awt.Window window)
      Return the application the opened the specified window (only call from event dispatch thread).
      protected ApplicationInstance getApplication​(java.lang.Thread thread, java.lang.Class<?>[] stack, int maxDepth)
      Return the current Application, or null.
      private JNLPClassLoader getJnlpClassLoader​(java.lang.ClassLoader cl)
      Returns the JNLPClassLoader associated with the given ClassLoader, or null.
      java.lang.ThreadGroup getThreadGroup()
      Returns the application's thread group if the application can be determined; otherwise returns super.getThreadGroup()
      boolean isExitClass()
      Returns whether the exit class is present on the stack, or true if no exit class is set.
      private boolean isExitClass​(java.lang.Class[] stack)
      Returns whether the exit class is present on the stack, or true if no exit class is set.
      void setExitClass​(java.lang.Class<?> exitClass)
      Set the exit class, which is the only class that can exit the JVM; if not set then any class can exit the JVM.
      • Methods inherited from class java.lang.SecurityManager

        checkAccept, checkAccess, checkAccess, checkConnect, checkConnect, checkCreateClassLoader, checkDelete, checkExec, checkLink, checkListen, checkMulticast, checkMulticast, checkPackageAccess, checkPackageDefinition, checkPermission, checkPrintJobAccess, checkPropertiesAccess, checkPropertyAccess, checkRead, checkRead, checkRead, checkSecurityAccess, checkSetFactory, checkWrite, checkWrite, getClassContext, getSecurityContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logger LOG
      • exitClass

        private java.lang.Object exitClass
        only class that can exit the JVM, if set
      • closeAppEx

        private java.lang.SecurityException closeAppEx
        this exception prevents exiting the JVM
      • weakWindows

        private WeakList<java.awt.Window> weakWindows
        weak list of windows created
      • exitAllowed

        private boolean exitAllowed
        Sets whether or not exit is allowed (in the context of the plugin, this is always false)
      • mainAppContext

        private sun.awt.AppContext mainAppContext
        The AppContext of the main application (netx). We need to store this here so we can return this when no code from an external application is running on the thread
    • Constructor Detail

      • JNLPSecurityManager

        JNLPSecurityManager()
        Creates a JNLP SecurityManager.
    • Method Detail

      • isExitClass

        public boolean isExitClass()
        Returns whether the exit class is present on the stack, or true if no exit class is set.
      • isExitClass

        private boolean isExitClass​(java.lang.Class[] stack)
        Returns whether the exit class is present on the stack, or true if no exit class is set.
      • setExitClass

        public void setExitClass​(java.lang.Class<?> exitClass)
                          throws java.lang.IllegalStateException
        Set the exit class, which is the only class that can exit the JVM; if not set then any class can exit the JVM.
        Parameters:
        exitClass - the exit class
        Throws:
        java.lang.IllegalStateException - if the exit class is already set
      • getApplication

        protected ApplicationInstance getApplication()
        Return the current Application, or null if none can be determined.
      • getApplication

        protected ApplicationInstance getApplication​(java.awt.Window window)
        Return the application the opened the specified window (only call from event dispatch thread).
      • getApplication

        protected ApplicationInstance getApplication​(java.lang.Thread thread,
                                                     java.lang.Class<?>[] stack,
                                                     int maxDepth)
        Return the current Application, or null.
      • getJnlpClassLoader

        private JNLPClassLoader getJnlpClassLoader​(java.lang.ClassLoader cl)
        Returns the JNLPClassLoader associated with the given ClassLoader, or null.
        Parameters:
        cl - a ClassLoader
        Returns:
        JNLPClassLoader or null
      • getThreadGroup

        public java.lang.ThreadGroup getThreadGroup()
        Returns the application's thread group if the application can be determined; otherwise returns super.getThreadGroup()
        Overrides:
        getThreadGroup in class java.lang.SecurityManager
      • checkPermission

        public void checkPermission​(java.security.Permission perm)
        Throws a SecurityException if the permission is denied, otherwise return normally. This method always denies permission to change the security manager or policy.
        Overrides:
        checkPermission in class java.lang.SecurityManager
      • askPermission

        private boolean askPermission​(java.security.Permission perm)
        Asks the user whether or not to grant permission.
        Parameters:
        perm - the permission to be granted
        Returns:
        true if the permission was granted, false otherwise.
      • addPermission

        private void addPermission​(java.security.Permission perm)
        Adds a permission to the JNLPClassLoader.
        Parameters:
        perm - the permission to add to the JNLPClassLoader
      • checkTopLevelWindow

        public boolean checkTopLevelWindow​(java.lang.Object window)
        Checks whether the window can be displayed without an applet warning banner, and adds the window to the list of windows to be disposed when the calling application exits.
      • checkExit

        public void checkExit​(int status)
        Checks whether the caller can exit the system. This method identifies whether the caller is a real call to Runtime.exec and has special behavior when returning from this method would exit the JVM and an exit class is set: if the caller is not the exit class then the calling application will be stopped and its resources destroyed (when possible), and an exception will be thrown to prevent the JVM from shutting down.

        Calls not from Runtime.exit or with no exit class set will behave normally, and the exit class can always exit the JVM.

        Overrides:
        checkExit in class java.lang.SecurityManager
      • disableExit

        protected void disableExit()
      • checkAwtEventQueueAccess

        public void checkAwtEventQueueAccess()
        Tests if a client can get access to the AWT event queue. This version allows complete access to the EventQueue for its own AppContext-specific EventQueue. FIXME there are probably huge security implications for this. Eg: http://hg.openjdk.java.net/jdk7/awt/jdk/rev/8022709a306d
        Throws:
        java.lang.SecurityException - if the caller does not have permission to access the AWT event queue.