gpt4 book ai didi

java rmi : access control exception, 访问被拒绝

转载 作者:行者123 更新时间:2023-12-02 06:42:35 24 4
gpt4 key购买 nike

我正在浏览sun网站上的教程,尝试使用RMI。

但是当我尝试启动服务器时出现此错误:

ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
at java.security.AccessController.checkPermission(AccessController.java:559)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:574)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at engine.ComputeEngine.main(ComputeEngine.java:31)

有人可以建议如何解决这个问题吗?我如何摆脱这个异常,如何修复它?

这是我遇到异常的地方(我在线右侧画了箭头):

package engine;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import compute.Compute;
import compute.Task;

public class ComputeEngine implements Compute {

public ComputeEngine() {
super();
}

public <T> T executeTask(Task<T> t) {
return t.execute();
}

public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
String name = "Compute";
Compute engine = new ComputeEngine();
Compute stub =
(Compute) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(name, stub); <<<<<------
System.out.println("ComputeEngine bound");
} catch (Exception e) {
System.err.println("ComputeEngine exception:");
e.printStackTrace();
}
}
}

最后,这就是我开始我的程序的方式:

Arguments to program and jvm

我将在下面留下可能有用的更多相关信息:

这是文件 ~/.server_policy:

grant codeBase "file:/home/jenia/Documents/eclipse/workspace/asti01/bin" {
permission java.security.AllPermission;
};

这是项目目录树:

/home/jenia/Documents/eclipse/workspace/asti01$ tree
.
├── bin
│   ├── client
│   │   ├── ComputePi.class
│   │   └── Pi.class
│   ├── compute
│   │   ├── Compute.class
│   │   └── Task.class
│   └── engine
│   └── ComputeEngine.class
└── src
├── client
│   ├── ComputePi.java
│   └── Pi.java
├── compute
│   ├── Compute.java
│   └── Task.java
├── compute.jar
└── engine
└── ComputeEngine.java

这是文件夹 ~/public_html 的树

/home/jenia/public_html/
└── classes
├── client
│   └── Pi.class
└── compute.jar

最佳答案

重申@EJP 的原始评论:

忽略教程中与配置/使用 SecurityManager 相关的所有内容。不要尝试使用远程代码加载。这些“功能”极大地增加了使用 rmi 的复杂性,并且 99% 的用户实际上并不需要它们。

关于java rmi : access control exception, 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18995306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com