Results 1 to 12 of 12
  1. #1
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Java Thread dropping permissions for no apparent reason - Bug??

    Hi,

    My signed Applet has the following classes...

    package com.beep;
    import java.security.AccessController;
    import java.security.AllPermission;
    public class Boop extends BoopImpl
    {
    public static void init()
    {
    try{
    AccessController.checkPermission(new AllPermission());
    DB.print("#4 AllPermission=OK");
    }catch(Throwable t){
    DB.print("#4 AllPermission=FAIL");
    }
    BoopImpl.init();
    }
    }

    package com.beep;
    import com.beep.DB;
    import java.security.AccessController;
    import java.security.AllPermission;
    public abstract class BoopImpl
    {
    public static void init()
    {
    try{
    AccessController.checkPermission(new AllPermission());
    DB.print("#5 AllPermission=OK");
    }catch(Throwable t){
    DB.print("#5 AllPermission=FAIL");
    }
    }
    }

    My output is as follows...

    TestRunner START
    java.runtime.name #2=Java(TM) SE Runtime Environment
    #2 AllPermission=OK
    #4 AllPermission=OK
    #5 AllPermission=FAIL


    BoopImpl has the same package as Boop.
    BoopImpl has the same ProtectionDomain as Boop.

    Can anyone please explain why the thread suddenly loses permissions?

    Regards
    Penny

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

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    Java might tell you but you are not allowing it to. Do a printStackTrace() on the exception you get and lets see what Java has to say about the matter before we initiate into pointless wild guessing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    here you go gimbal2...

    ========================================
    ERROR:Wed Dec 11 13:15:28 GMT 2013
    Thread=Thread[Thread-15,4,http://PC.home/test/-threadGroup]
    java.security.AccessControlException: access denied ("java.security.AllPermission" "<all permissions>" "<all actions>")
    java.security.AccessControlContext.checkPermission (-1)
    java.security.AccessController.checkPermission(-1)
    com.test.BoopImpl.init(10)
    com.test.Boop.init(14)
    com.test.TestRunner.start(31)
    sun.reflect.NativeMethodAccessorImpl.invoke0(-2)
    sun.reflect.NativeMethodAccessorImpl.invoke(-1)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(-1)
    java.lang.reflect.Method.invoke(-1)
    com.test.Utility.start(39)
    com.test.Test.run(52)
    java.lang.Thread.run(-1)
    ========================================


    As you can see from the stack trace Boop.init() runs with permissions but BoopImpl.init() does not.

    BoopImpl has the same ProtectionDomain and Boop so I don't understand why BoopImpl is losing permissions.

    How can I enable/allow BoopImpl.init() to run with permissions??

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

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    I wonder why BoopImpl actually has an init(), given that it is abstract. I would expect only Boop to have one, since that is "the application".

    HOW are you running this exactly?
    Last edited by gimbal2; 12-11-2013 at 02:40 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    It is to set some system constants in the singleton.

    the original code is...

    static {
    AccessController.doPrivileged(new PrivilegedAction<String>() {
    @Override
    public String run() {
    // initialisation code
    }
    });

    but as this only throws ExceptionInInitialisationError I needed to pull it apart a bit.

    Lets try to focus on why the thread is losing permissions instead of what the program does thank you.

  6. #6
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    Note: both Boop and BoopImpl are dynamically loaded using defineClass after having the certificates verified and using the ProtectionDomain of the loaded Applet.

    Boop runs with permissions so I have no idea why BoopImpl shouldn't.

    but it isn't. I would really appreciate some help in how to get BoopImpl to run with permissions.

    Thanks

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

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    Quote Originally Posted by Penny666 View Post
    Lets try to focus on why the thread is losing permissions instead of what the program does thank you.
    Lets try to find the root of the problem in stead of making assumptions.

    Not that I have any ideas anymore, what you are doing and attempting to do is entirely vague to me.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    What I am attempting to do, as stated in my first post, is to run BoopImpl.init() with permissions.

    I load both Boop and BoopImpl dynamically and assign them with the same ProtectionDomain.

    However, when it comes to thread execution BoopImpl somehow has a different ProtectionDomain...

    Boop permissions=java.security.Permissions@e3572b (
    ("java.net.SocketPermission" "zenny-x11.home" "connect,accept,resolve")
    ("java.util.PropertyPermission" "javapi.*" "read,write")
    ("java.util.PropertyPermission" "javaplugin.version" "read")
    ("java.util.PropertyPermission" "javaplugin.vm.options" "read")
    ("java.util.PropertyPermission" "browser.version" "read")
    ("java.util.PropertyPermission" "mrj.version" "read")
    ("java.util.PropertyPermission" "http.agent" "read")
    ("java.util.PropertyPermission" "jnlp.*" "read,write")
    ("java.util.PropertyPermission" "browser" "read")
    ("java.util.PropertyPermission" "javaws.*" "read,write")
    ("java.util.PropertyPermission" "browser.vendor" "read")
    ("com.sun.deploy.security.SecureCookiePermissio n" "origin.http://zenny-x11.home:80")
    ("java.security.AllPermission" "<all permissions>" "<all actions>")
    ("java.lang.RuntimePermission" "accessClassInPackage.sun.audio")
    )

    BoopImpl permissions=java.security.Permissions@f89376 (
    ("java.io.FilePermission" "\C:\Users\Penny\AppData\Paradigm\test-platform.jar" "read")
    )

    Thread context=com.test.MyClassLoader@7b7bee
    BoopImpl classLoader=com.test.MyClassLoader@7b7bee
    #4 AllPermission=OK
    #5 AllPermission=FAIL


    I would like to point out that I have not made any assumptions whatsoever. I have stated that I am puzzled as to why BoopImpl doesn't run with permissions when I have loaded the class with defineClass and have set the permissions to AllPermission. There must be some mechanism that is interfering, that I am unaware of, and my whole purpose of posting on this forum is to try and learn a better understanding from someone who has sufficient knowledge to be able to offer some insight.

    gimbal2, I am disappointed that you were unable to offer any insight but thanks for your effort anyway :)

  9. #9
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    I have figured it out.

    In a nutshell I needed to override the loadClass functions in my class loader.

    The reason is that defineClass subsequently calls loadClass to define dependents and the parent class loader defines classes without any permissions. My class loader was then generating "Already Defined" when it tried to define the dependent classes with permissions.

    By overriding the loadClass functions I ensure every class is defined with permissions.

    Thank you

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

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    Thanks for posting the answer.
    It's solutions to rare problems like this that help prevent someone else's premature baldness.
    :)

    So, essentially, the code above was loading Boop, which caused the BoopImpl to be loaded as it is a dependency, which was done by the parent class loader. That loader (obviously) only used the normal loading routines (ie no permissions). When you attempt to load BoopImpl later on with your class loader it didn't do it as it was already there.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    yes exactly!

  12. #12
    Penny666 is offline Member
    Join Date
    Dec 2013
    Posts
    11
    Rep Power
    0

    Default Re: Java Thread dropping permissions for no apparent reason - Bug??

    Just in case anyone is reading this thread to gleam information. I read an article which stated that the only function that needs to be overridden is findClass(String _name)

    Originally I had them all overridden so I tried this and it works. Saved a lot of unnecessary code.

Similar Threads

  1. JAVA Permissions Applet
    By Magnos in forum New To Java
    Replies: 9
    Last Post: 10-01-2013, 10:09 AM
  2. NullPointerException for no apparent reason?
    By xpl0rerchr in forum New To Java
    Replies: 12
    Last Post: 04-10-2012, 05:26 PM
  3. dropping a URL: how to get page title?
    By zacchia in forum AWT / Swing
    Replies: 3
    Last Post: 06-20-2011, 03:45 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
  •