Using WebServiceTemplate with a keystore

后端 未结 6 617
无人共我
无人共我 2021-02-03 10:56

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

6条回答
  •  终归单人心
    2021-02-03 11:18

    I'm assuming you mean you want to configure the keystore used by JSSE, since that is the Template will use. JSSE will always always look at the javax.net.ssl.keyStore/javax.net.ssl.keyStorePassword system properties to find the keystore. You can configure these properties in Spring using an InitializingBean like this.

    Note that if you are running in an app server the JSSE may already be configured before Spring initializes. In this case you need to use the app server interface to set the keystore -- usually using -D params on command line.

    
            
            
            
            
    
    
    
    public class JsseInitializer implements InitializingBean {
    
        private String trustStoreLocation;
        private String trustStorePassword;
        private String keyStoreLocation;
        private String keyStorePassword;
    
        public String getTrustStoreLocation() {
            return trustStoreLocation;
        }
    
    
        public void setTrustStoreLocation(String trustStoreLocation) {
            this.trustStoreLocation = trustStoreLocation;
        }
    
    
        public String getTrustStorePassword() {
            return trustStorePassword;
        }
    
    
        public void setTrustStorePassword(String trustStorePassword) {
            this.trustStorePassword = trustStorePassword;
        }
    
    
        public String getKeyStoreLocation() {
            return keyStoreLocation;
        }
    
    
        public void setKeyStoreLocation(String keyStoreLocation) {
            this.keyStoreLocation = keyStoreLocation;
        }
    
    
        public String getKeyStorePassword() {
            return keyStorePassword;
        }
    
    
        public void setKeyStorePassword(String keyStorePassword) {
            this.keyStorePassword = keyStorePassword;
        }
    
        public void afterPropertiesSet() throws Exception {
            System.setProperty("javax.net.ssl.trustStore", trustStoreLocation);
            System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
            System.setProperty("javax.net.ssl.keyStore", keyStoreLocation);
            System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
    
        }
    }
    

提交回复
热议问题