Andrea Baglioni
Andrea Baglioni

Reputation: 303

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8081 connect,resolve) - main reasons

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?

Upvotes: 5

Views: 43990

Answers (4)

raja raja cholan
raja raja cholan

Reputation: 11

go to path of java jdk and ./jre/lib/security/ open java policy file

then set the grant permission for SocketPermission grant{ permission java.net.SocketPermission "localhost:8080", "connect,resolve"; } then restart and run your code.

Upvotes: 1

user207421
user207421

Reputation: 310850

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.

Upvotes: 2

VOLVO
VOLVO

Reputation: 561

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

and

sign your jar file with code signing certificate.

Upvotes: 0

Vicky Thakor
Vicky Thakor

Reputation: 3916

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)

Upvotes: 0

Related Questions