java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8081 connect,resolve) - 主要原因

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25074623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:34:13  来源:igfitidea点击:

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

javasecurityapplet

提问by Andrea Baglioni

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

相同的可信签名小程序(Digicert 证书),在某些 PC 上运行良好,在其他 PC 上不起作用。当我尝试通过附件流时发生异常URLConnection

Where it doesn't works, i resolve with

在它不起作用的地方,我解决了

grant { 
    permission java.security.AllPermission; 
};

in

java.policy
但我想避免更新每台 PC。

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

可能是port(8081)问题吗?我应该调查什么?

回答by Vicky Thakor

Writing custom SecurityManagerfor your applet could solve your issue. Setting your own SecurityManagerwill grant all permission for your applet.

SecurityManager为您的小程序编写自定义可以解决您的问题。设置您自己的SecurityManager将授予您的小程序的所有权限。

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)

注意System.setSecurityManager(null) 的影响

回答by VOLVO

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

您必须在 manifest.mf 实例“沙箱”中添加“所有权限”

and

sign your jar file with code signing certificate.

使用代码签名证书对您的 jar 文件进行签名。

回答by user207421

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

相同的可信签名小程序(Digicert 证书),在某些 PC 上运行良好,在其他 PC 上不起作用。

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

它不受那些其他 PC 的信任,并且在被询问时未被用户接受为受信任。

OR

或者

This is my manifest.mf

这是我的 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-Digestentries.

如果这是完整的清单,则该 JAR 根本没有签名,更不用说由受信任的证书签名了。它应该充满Name:SHA-256-Digest条目。

回答by raja raja cholan

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

转到java jdk和./jre/lib/security/打开java策略文件的路径

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

然后为 SocketPermission 设置授予权限, grant{ permission java.net.SocketPermission "localhost:8080", "connect,resolve"; }然后重新启动并运行您的代码。