java.security.AccessControlException: access denie

2019-06-26 19:21发布

问题:

What are the main reasons that cause the exception reported?

Same trusted signed applet (Digicert certificate), works great on some PCs, doesn't work on other. Exception occurs when i try to get an attachment stream through URLConnection

Where it doesn't works, i resolve with

grant { 
    permission java.security.AllPermission; 
};

in

java.policy
but i would like to avoid to update every PC.

Could be a port (8081) issue? What should I investigate?

回答1:

Same trusted signed applet (Digicert certificate), works great on some PCs, doesn't work on other.

It isn't trusted by those other PCs, and wasn't accepted by the user as trusted when asked.

OR

This is my manifest.mf

Trusted-Library: true
Application-Name: MyApp
Name: MyName
Permissions: all-permissions
Created-By: 1.6.0_16 (Sun Microsystems Inc.)
Caller-Allowable-Codebase: *
Main-Class: MyClass
Codebase: *

If that's the complete manifest, this JAR isn't signed at all, let alone by a trusted certificate. It should be full of Name: and SHA-256-Digest entries.



回答2:

Writing custom SecurityManager for your applet could solve your issue. Setting your own SecurityManager will grant all permission for your applet.

class customSecurityManager extends SecurityManager {

        SecurityManager original;

        customSecurityManager(SecurityManager original) {
            this.original = original;
        }

        /**
         * Deny permission to exit the VM.
         */
        public void checkExit(int status) {
            //throw(new SecurityException("Not allowed"));
        }

        /**
         * Allow this security manager to be replaced, if fact, allow pretty
         * much everything.
         */
        public void checkPermission(Permission perm) {
        }

        public SecurityManager getOriginalSecurityManager() {
            return original;
        }
    }

Now set this security manager for your applet

public void init() {
   customSecurityManager cSM = new customSecurityManager(System.getSecurityManager());
   System.setSecurityManager(cSM);
}

Caution: Impact of System.setSecurityManager(null)



回答3:

You must add "all-permissions" in manifest.mf instance "sandbox"

and

sign your jar file with code signing certificate.