我有一些不使用 SecurityManager 但使用 RMI 的旧代码。据我所知,RMI 需要一个安全管理器,但代码似乎可以在同一台机器上和两台机器之间正常运行。我已经在 1.5 上测试过这些东西,但没有在 1.6 上测试过。
我找不到任何资源讨论什么时候需要 SecurityManager 什么时候不需要,或者该要求是否随 Java 版本而改变。
我打算更新代码使用一个,我只是想了解它背后的细节。
感谢任何反馈!
最佳答案
只有在 RMI 从远程机器下载代码时才需要安全管理器。如果客户端和服务器都使用相同的类,则不需要。
来自 RMI Tutorial :
A security manager determines whether downloaded code has access to the local file system or can perform any other privileged operations.
If an RMI program does not install a security manager, RMI will not download classes (other than from the local class path) for objects received as arguments or return values of remote method invocations. This restriction ensures that the operations performed by downloaded code are subject to a security policy.
关于没有 SecurityManager 的 Java RMI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2298853/