Results 1 to 6 of 6
  1. #1
    kimi is offline Member
    Join Date
    Aug 2013
    Posts
    11
    Rep Power
    0

    Default Override SecurityManager checkPermission(Permission p) method

    I need a custom SecurityManager but whenever I try to override its checkPermission(Permission p) method the application throws an exception, and I *really* can't understand what's happening...

    Why would this work

    Java Code:
    public static void main(String[] args) {
    
        System.setSecurityManager(new SecurityManager() {});
    
        new JFrame().setVisible(true);
    
    }
    whereas this doesn't??

    Java Code:
    public static void main(String[] args) {
    
        System.setSecurityManager(new SecurityManager() {
            @Override
            public void checkPermission(Permission p) {
                super.checkPermission(p);
            }
        });
    
        new JFrame().setVisible(true);
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: Override SecurityManager checkPermission(Permission p) method

    What exception does it throw?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,277
    Rep Power
    6

    Default Re: Override SecurityManager checkPermission(Permission p) method

    On my Java 6 runtime it produces this:

    Java Code:
    Could not load Logmanager "null"
    java.security.AccessControlException: access denied (java.util.PropertyPermission java.util.logging.manager read)
            at java.security.AccessControlContext.checkPermission(Unknown Source)
            at java.security.AccessController.checkPermission(Unknown Source)
            at java.lang.SecurityManager.checkPermission(Unknown Source)
            at Test2$1.checkPermission(test2.java:11)
            at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
            at java.lang.System.getProperty(Unknown Source)
            at java.util.logging.LogManager$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.util.logging.LogManager.<clinit>(Unknown Source)
            at java.util.logging.Logger.demandLogger(Unknown Source)
            at java.util.logging.Logger.getLogger(Unknown Source)
            at java.awt.Component.<clinit>(Unknown Source)
            at Test2.main(test2.java:15)
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at java.util.logging.Logger.demandLogger(Unknown Source)
            at java.util.logging.Logger.getLogger(Unknown Source)
            at java.awt.Component.<clinit>(Unknown Source)
            at Test2.main(test2.java:15)
    Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission setContextClassLoader)
            at java.security.AccessControlContext.checkPermission(Unknown Source)
            at java.security.AccessController.checkPermission(Unknown Source)
            at java.lang.SecurityManager.checkPermission(Unknown Source)
            at Test2$1.checkPermission(test2.java:11)
            at java.lang.Thread.setContextClassLoader(Unknown Source)
            at java.util.logging.LogManager$Cleaner.<init>(Unknown Source)
            at java.util.logging.LogManager$Cleaner.<init>(Unknown Source)
            at java.util.logging.LogManager.<init>(Unknown Source)
            at java.util.logging.LogManager$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.util.logging.LogManager.<clinit>(Unknown Source)
            ... 4 more
    I'm stumped.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,923
    Rep Power
    5

    Default Re: Override SecurityManager checkPermission(Permission p) method

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,277
    Rep Power
    6

    Default Re: Override SecurityManager checkPermission(Permission p) method

    Ah, a clear "If you don't know how it works, it will break" situation.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    kimi is offline Member
    Join Date
    Aug 2013
    Posts
    11
    Rep Power
    0

    Default Re: Override SecurityManager checkPermission(Permission p) method

    Basically the SecurityManager class in Java calls AccessController, which in turns analyzes the whole call stack. The set of allowed permission is the intersection of the single permission of each item in the stack. When I extend SecurityManager and call super.checkPermission(Permission p), my subclass is on the stack and apparently not with the permissions I need... I still don't know I could solve this problem, however moving from Swing to JavaFX allowed me to override that method without any super() call, and seems to work alright now... The workaround I used before was to override every single checkXXX method but checkPermission(Permission p)

Similar Threads

  1. Override toString() Method
    By Apparition78 in forum New To Java
    Replies: 1
    Last Post: 02-03-2012, 11:32 PM
  2. Can we override static method?
    By srinivasmallabathula in forum Advanced Java
    Replies: 3
    Last Post: 06-24-2011, 03:29 PM
  3. Override class method
    By Mekie in forum New To Java
    Replies: 8
    Last Post: 11-01-2010, 07:26 AM
  4. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  5. Override Entity Callback Method
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-13-2009, 07:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •