javaspringsslspring-ws

Using WebServiceTemplate with a keystore


Is it possible to configure a WebServiceTemplate with a java keystore?

edit
I'm looking for a way to configure the location of the keystore in the spring config


Solution

  • I think you can programatically load a keystore based using a KeyStore.Builder:

    http://java.sun.com/j2se/1.5.0/docs/api/java/security/KeyStore.Builder.html#newInstance%28java.lang.String,%20java.security.Provider,%20java.io.File,%20java.security.KeyStore.ProtectionParameter%29

    So maybe have a class that has a webservice template or extends it, then set the file path of the keystore on it in your spring config and make it an inizialing bean (@PostConstruct in Spring 3?) which then loads the keystore.

    File f = new File(keyStorePath);
    KeyStore.Builder builder = KeyStore.Builder.newInstance("type",provider,file,protection);
    KeyStore keystore = builder.getKeyStore();
    

    Ok - to actually use it with your webservicetemplate i think it must be based around the keystore callback as documented here: http://static.springsource.org/spring-ws/sites/1.5/reference/html/security.html#d0e4462

    Or maybe by using the spring org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender which you can set keystoremanager on. Then that can be used by your webservicetemplate.

    A bit like this:

    <bean id="template" class="org.springframework.ws.client.core.WebServiceTemplate">
        <property name="messageSender">
            <bean class="org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender">
                <property name=""></property>
            </bean>
        </property>
    </bean>
    

    HTH