RMI 如何添加库(并授予它们套接字权限)
对于学校项目,我必须从独立应用程序创建分布式系统。我们使用 RMI 进行通信,但遇到了一些问题。
我创建的服务器启动得很好,但是客户端(使用一些 swing 库等)给了我一个 classNotFound 异常。为了解决这个问题,我将项目使用的库添加到“C:\Program Files\Java\jre6\lib\ext”。我更喜欢将库放在客户端(就像我对构建所做的那样)。
有人可以告诉我这是否可能,如果可能,如何实现?
问题并没有在这里结束,如果我现在启动我的客户端,我会得到一个 java.security.AccessControlException 。我使用一个策略文件,它看起来像这样:
grant
{ permission java.net.SocketPermission
"*:1024-65535", "connect,accept";
};
我还尝试添加所有库,但这也没有帮助:
grant codebase "file:${java.home}/../lib/ext/appframework-1.0.3.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/beansbinding-1.2.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/jcalendar-1.3.3.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/looks-2.0.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swing-worker-1.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swingx-1.6.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swingx-bean.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swingx-ws-2011_01_16.jar" {
permission java.security.AllPermission;
};
grant
{ permission java.net.SocketPermission
"*:1024-65535", "connect,accept";
};
我希望任何人都可以帮助我。
-抢
For a school project I have to create a distributed system from a standalone application. We're using RMI for the communication, but we ran into some problems.
The server I created starts just fine, but the client (which uses some swing libraries etc.) was giving me a classNotFound exception. To fix this I added the libraries my project uses to "C:\Program Files\Java\jre6\lib\ext". I prefer to place to libs at the client (like I did with the builds).
Can someone tell me if this is possible and ifso, how?
The problems don't end here, if I start my client now I get an java.security.AccessControlException. I use a policy file, it looks like this:
grant
{ permission java.net.SocketPermission
"*:1024-65535", "connect,accept";
};
I also tried to add all the libs but this didn't help either:
grant codebase "file:${java.home}/../lib/ext/appframework-1.0.3.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/beansbinding-1.2.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/jcalendar-1.3.3.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/looks-2.0.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swing-worker-1.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swingx-1.6.1.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swingx-bean.jar" {
permission java.security.AllPermission;
};
grant codebase "file:${java.home}/../lib/ext/swingx-ws-2011_01_16.jar" {
permission java.security.AllPermission;
};
grant
{ permission java.net.SocketPermission
"*:1024-65535", "connect,accept";
};
I hope that anyone can help me.
-Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调试 java 2 安全异常是一个繁琐的试错过程。我猜您正在使用 JVM 开关启动客户端,以添加告诉它使用安全管理器 - 添加以下
-Djava.security.debug=access,failure
您将获得大量调试信息,但是搜索“拒绝访问”将显示需要针对哪个代码库授予哪些权限。这不是一个科学的过程 - 您只需不断尝试,直到您认为已经解决了所有安全问题。
Debugging java 2 security exceptions is a tedious trial and error process. I guess you are starting the client with a JVM switch to add tell it to use a security manager - add the following
-Djava.security.debug=access,failure
You'll get masses of debug information, but searcing it for "access denied" will show you what permissions need to be granted against which code base. It's not a scientific process - you just have to keep trying until you think you've fixed all the security problems.