简体   繁体   English

根据使用wsdl2java创建的存根,将客户端证书附加到Web服务调用

[英]Attach client certificate to web service call based on stubs created with wsdl2java

I have created the stub classes for consuming the web service with wsdl2java but I need to specify a client certificate for the transport. 我已经使用wsdl2java创建了使用Web服务的存根类,但我需要为传输指定客户端证书。 How do I do this? 我该怎么做呢?

In .NET I am used to be able to directly attach a X509Certificate object to similar stub classes before making the call. 在.NET中,我习惯于在进行调用之前将X509Certificate对象直接附加到类似的存根类。

In Java, you have a couple options: 在Java中,您有几个选择:

  • Specify the java.net.ssl* parameters to setup a cert store, password, etc. You'll want to use keytool to set up these objects. 指定java.net.ssl*参数以设置证书存储区,密码等。您将需要使用keytool来设置这些对象。

Here's the code, or these can be specified on the command line with -D. 这是代码,或者可以在命令行中使用-D指定这些代码。 Note that these will be global to your app. 请注意,这些将是您的应用程序的全局。

System.setProperty("javax.net.ssl.keyStore", "myKeyStore.p12");
System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
  • Create a custom SSLFactory which configures your certs at a lower level and set it on your WS context. 创建一个自定义SSLFactory ,在较低级别配置您的证书并将其设置在您的WS上下文中。 You can google for this and find lots of info out there. 你可以谷歌这个,并找到很多信息。 Also check this question (the author says it's for JAX-RPC, but in the comments he changes his impl to JAX-WS). 还要检查这个问题 (作者说它适用于JAX-RPC,但在评论中他改变了对JAX-WS的影响)。

You can find more info in the JSSE docs (this for java 1.5). 您可以在JSSE文档中找到更多信息(这适用于java 1.5)。

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

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