Axis2 SSLContext with Client Stubs

2019-07-16 07:47发布

I'm attempting to configure a Java client using Axis2 client stubs(WSDL2Java). The application consumes a WCF service that requires client certificates. The only way I've been able to get the application to work is by changing the system properties as in this code:

System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStore","path/to/my/keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");

However, I would like to use a different keystore for different applications on the same Tomcat server. I have looked into using an SSLContext based on some of the research I've done, but I haven't found any examples that use client stubs created with WSDL2Java. Does anyone have an example or have any idea how to do this?

Thanks!

I would like to add that we are using WS-Policy and use a ConfigurationContext to engage Rampart. I was thinking that I could edit our policy.xml file to indicate the keystore. Would this work? I'm getting a SocketException when I attempt to run the application: SocketException: Unconnected sockets not implemented. Here is the policy.xml file in its current form.

<?xml version="1.0" encoding="UTF-8"?>
<wsp:Policy wsu:Id="BasicHttpBinding"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wsecurity-secext-1.1.xsd"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:ExactlyOne>
    <wsp:All>
        <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
            <wsp:Policy>
                <sp:TransportToken>
                    <wsp:Policy>
                        <sp:HttpsToken RequireClientCertificate="true" /> 
                    </wsp:Policy>
                </sp:TransportToken>
                <sp:AlgorithmSuite>
                    <wsp:Policy>
                        <sp:Basic256 /> 
                    </wsp:Policy>
                </sp:AlgorithmSuite>
                <sp:Layout>
                    <wsp:Policy>
                        <sp:Strict /> 
                    </wsp:Policy>
                </sp:Layout>
            </wsp:Policy>
        </sp:TransportBinding>
        <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
            <ramp:user>myapplication</ramp:user>
            <ramp:passwordCallbackClass>com.myproject.classes.PWCBHandler</ramp:passwordCallbackClass>
            <ramp:sslConfig>
                <ramp:property name="javax.net.ssl.keyStoreType">JKS</ramp:property>
                <ramp:property name="javax.net.ssl.keyStore">path/to/my/keystore</ramp:property>
                <ramp:property name="javax.net.ssl.keyStorePassword">changeit</ramp:property>
                <ramp:property name="javax.net.ssl.trustStoreType">JKS</ramp:property>
                <ramp:property name="javax.net.ssl.trustStore">path/to/my/truststore</ramp:property>
                <ramp:property name="javax.net.ssl.trustStorePassword">changeit</ramp:property>
            </ramp:sslConfig>
        </ramp:RampartConfig>
    </wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>

标签: java wcf ssl axis2
0条回答
登录 后发表回答