简体   繁体   English

如何通过代码为Java RMI动态设置SSL?

[英]How to set up SSL for Java RMI dynamically from code?

I am using Java RMI and until now just used the following VM arguments 我正在使用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

and just used SslRMI socket factories for the registry and the export of the objects. 并仅使用SslRMI套接字工厂进行注册表和对象的导出。
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). 等等,然后自动进行设置(例如,以VM参数开头时会发生这种情况)。 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? 我是否必须使用密钥库和TrustManager创建自己的SSLContext? And how do I get this context to my SslRMIFactories? 以及如何将此上下文传递到SslRMIFactories?

Yes - those parameters can be set using System.setProperty as well. 是的-也可以使用System.setProperty设置这些参数。 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. 例如,在JBoss上,该文件是deploy文件夹下的properties-service.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM