如何从代码动态为 Java RMI 设置 SSL?
我正在使用 Java RMI,到目前为止仅使用以下 VM 参数
-Djavax.net.ssl.trustStore=${workspace_loc:/ssltest/server/servertruststore.jks}
-Djavax.net.ssl.trustStorePassword=server
-Djavax.net.ssl.keyStore=${workspace_loc:/ssltest/server/serverkeystore}
-Djavax.net.ssl.keyStorePassword=server
,并仅使用 SslRMI 套接字工厂来进行注册表和对象的导出。
现在我想摆脱额外的命令行参数并从属性文件中读取它。我希望为此我只需要通过
System.setProperty("javax.net.ssl.trustStore", "C:/servertruststore.jks");
等等设置属性,然后自动设置这些东西(就像从虚拟机参数开始时发生的那样)。我需要做什么才能实现这一点?
如果这不可能,我还能做什么?我是否必须使用密钥库和 TrustManager 创建自己的 SSLContext?如何将此上下文获取到我的 SslRMIFactories?
I am using Java RMI and until now just used the following VM arguments
-Djavax.net.ssl.trustStore=${workspace_loc:/ssltest/server/servertruststore.jks}
-Djavax.net.ssl.trustStorePassword=server
-Djavax.net.ssl.keyStore=${workspace_loc:/ssltest/server/serverkeystore}
-Djavax.net.ssl.keyStorePassword=server
and just used SslRMI socket factories for the registry and the export of the objects.
Now I want to get rid of the additional command line parameters and read that from a property file. I hoped that for that I just need to set the properties via
System.setProperty("javax.net.ssl.trustStore", "C:/servertruststore.jks");
and so on and then set up the stuff automatically (like it happens when starting with the VM arguments). What do I have to do to make that happen?
And if that is not possible, what else can I do? Do I have to create my own SSLContext with the Keystore and TrustManagers? And how do I get this context to my SslRMIFactories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的 - 也可以使用 System.setProperty 设置这些参数。答案取决于您的环境。如果您使用应用程序服务器,可能有一些配置文件可以自动设置/公开自定义系统属性。例如,在 JBoss 上,该文件是部署文件夹下的properties-service.xml。
Yes - those parameters can be set using System.setProperty as well. The answer to how depends on your environment. If you are using an application server, there might be some configuration file to set/expose custom system properties automatically. For example, on JBoss that file is properties-service.xml under deploy folder.