[英]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.相同的可信签名小程序(Digicert 证书),在某些 PC 上运行良好,在其他 PC 上不起作用。 Exception occurs when i try to get an attachment stream through
URLConnection
当我尝试通过
URLConnection
获取附件流时发生异常
Where it doesn't works, i resolve with在它不起作用的地方,我解决了
grant {
permission java.security.AllPermission;
};
in在
java.policybut i would like to avoid to update every PC.
Could be a port
(8081) issue?可能是
port
(8081)问题? What should I investigate?我应该调查什么?
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.如果这是完整的清单,则该 JAR 根本没有签名,更不用说由受信任的证书签名了。 It should be full of
Name:
and SHA-256-Digest
entries.它应该充满
Name:
和SHA-256-Digest
条目。
Writing custom SecurityManager
for your applet could solve your issue.为您的小程序编写自定义
SecurityManager
可以解决您的问题。 Setting your own SecurityManager
will grant all permission for your applet.设置您自己的
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) 的影响
You must add "all-permissions" in manifest.mf instance "sandbox"您必须在 manifest.mf 实例“沙箱”中添加“所有权限”
and和
sign your jar file with code signing certificate.使用代码签名证书对您的 jar 文件进行签名。
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"; }
然后设置 SocketPermission
grant{ permission java.net.SocketPermission "localhost:8080", "connect,resolve"; }
grant{ permission java.net.SocketPermission "localhost:8080", "connect,resolve"; }
then restart and run your code. grant{ permission java.net.SocketPermission "localhost:8080", "connect,resolve"; }
然后重新启动并运行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.