Maven 中的 SSL 客户端证书 [英] SSL client certificate in Maven
问题描述
我使用maven-jaxb22-plugin"来生成类,以便我可以调用用 .Net 编写的 Web 服务.通常它工作正常,但这次,我只能通过 HTTPS 使用客户端证书访问 WSDL(不能通过 HTTP 访问).
I use the "maven-jaxb22-plugin" to generate classes so I can call a web service written in .Net. Usually it works fine but this time, I can only access the WSDL using a client certificate through HTTPS (not available through HTTP).
我能够让它与 SoapUI 一起工作.我将客户端证书添加到 JKS 密钥库中,并将其添加到 SoapUI 首选项中.然后我通过指定如下所示的 URL 创建了一个新项目:https://server.com/Service?wsdl.SoapUI 生成了请求模板.我可以轻松地查询 Web 服务并获得响应.所以这证明了 WSDL 可用并且 Web 服务正在工作.
I was able to make it work with SoapUI. I added the client certificate into a JKS keystore and added it to the SoapUI preferences. Then I created a new project by specifying the URL which looks like this: https://server.com/Service?wsdl. SoapUI generated the request template. I was easily able to query the web service and get a response. So this prove that the WSDL is available and the web service is working.
现在,在我的 pom 文件中,我正在使用这个插件:
Now, in my pom file, I am using this plugin:
<build>
<finalName>MyService</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb22-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<extension>true</extension>
<removeOldOutput>true</removeOldOutput>
<schemaLanguage>WSDL</schemaLanguage>
<verbose>true</verbose>
<schemaIncludes>
<includeSchema>https://server.com/Service?wsdl</includeSchema>
</schemaIncludes>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
如何告诉 Maven 我的客户端证书在哪里?
How can I tell Maven where my client certificate is?
谢谢
推荐答案
您可以使用 Maven属性插件或使用 JVM 属性来提供信任存储位置.
You could use the Maven properties plugin or use a JVM property to provide the trust store location.
在您的 POM build/plugins 部分中,添加一个新的 plugin 条目,其中的密钥库将是 YourKeyStore.jks 对于这个例子:
In your POM build/plugins section, add a new plugin entry, where the keystore would be YourKeyStore.jks for this example:
..
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<property>
<name>javax.net.ssl.trustStore</name>
<value>${basedir}/src/test/jmeter/jmeterTrustedKeystore.jks</value>
</property>
<property>
<name>javax.net.ssl.keyStorePassword</name>
<value>changeit</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
...
这篇关于Maven 中的 SSL 客户端证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!