Search in sources :

Example 1 with KeyStoreFactoryBean

use of org.springframework.ws.soap.security.support.KeyStoreFactoryBean in project open-smart-grid-platform by OSGP.

the class DefaultWebServiceTemplateFactory method getSSLConnectionSocketFactory.

private SSLConnectionSocketFactory getSSLConnectionSocketFactory(final String keystore) throws GeneralSecurityException, IOException {
    // Open key store, assuming same identity
    final KeyStoreFactoryBean keyStoreFactory = new KeyStoreFactoryBean();
    keyStoreFactory.setType(this.keyStoreType);
    keyStoreFactory.setLocation(new FileSystemResource(this.keyStoreLocation + "/" + keystore + ".pfx"));
    keyStoreFactory.setPassword(this.keyStorePassword);
    keyStoreFactory.afterPropertiesSet();
    final KeyStore keyStore = keyStoreFactory.getObject();
    if ((keyStore == null) || (keyStore.size() == 0)) {
        throw new KeyStoreException("Key store is empty");
    }
    // Setup SSL context, load trust and key store and build the message
    // sender
    final SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, this.keyStorePassword.toCharArray()).loadTrustMaterial(this.trustStoreFactory.getObject(), new TrustSelfSignedStrategy()).build();
    final HostnameVerifier hostnameVerifier = this.getHostnameVerifier();
    return new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) KeyStoreException(java.security.KeyStoreException) SSLContext(javax.net.ssl.SSLContext) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) KeyStore(java.security.KeyStore) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier)

Example 2 with KeyStoreFactoryBean

use of org.springframework.ws.soap.security.support.KeyStoreFactoryBean in project open-smart-grid-platform by OSGP.

the class SoapClientConfig method keyStore.

@Bean
public KeyStoreFactoryBean keyStore() {
    final KeyStoreFactoryBean keyStoreFactoryBean = new KeyStoreFactoryBean();
    keyStoreFactoryBean.setLocation(this.keyStore);
    keyStoreFactoryBean.setPassword(this.keyStorePassword);
    return keyStoreFactoryBean;
}
Also used : KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) TrustManagersFactoryBean(org.springframework.ws.soap.security.support.TrustManagersFactoryBean) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) KeyManagersFactoryBean(org.springframework.ws.soap.security.support.KeyManagersFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with KeyStoreFactoryBean

use of org.springframework.ws.soap.security.support.KeyStoreFactoryBean in project open-smart-grid-platform by OSGP.

the class BaseWebServiceConfig method webServiceTrustStoreFactory.

@Bean
public KeyStoreFactoryBean webServiceTrustStoreFactory() {
    final KeyStoreFactoryBean factory = new KeyStoreFactoryBean();
    factory.setType(this.webserviceTruststoreType);
    factory.setLocation(new FileSystemResource(this.webserviceTruststoreLocation));
    factory.setPassword(this.webserviceTruststorePassword);
    return factory;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with KeyStoreFactoryBean

use of org.springframework.ws.soap.security.support.KeyStoreFactoryBean in project open-smart-grid-platform by OSGP.

the class NotificationWebServiceTemplateFactory method createKeyStore.

private KeyStore createKeyStore(final String type, final String location, final String password) throws WebServiceSecurityException {
    final KeyStoreFactoryBean keyStoreFactory = new KeyStoreFactoryBean();
    keyStoreFactory.setType(type);
    keyStoreFactory.setLocation(new FileSystemResource(location));
    keyStoreFactory.setPassword(password);
    try {
        keyStoreFactory.afterPropertiesSet();
        final KeyStore keyStore = keyStoreFactory.getObject();
        if ((keyStore == null) || (keyStore.size() == 0)) {
            throw new KeyStoreException("Key store is empty");
        }
        return keyStore;
    } catch (final GeneralSecurityException | IOException e) {
        LOGGER.error("Exception creating {} key store for file {}", type, location, e);
        throw new WebServiceSecurityException("Unable to create KeyStore", e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) FileSystemResource(org.springframework.core.io.FileSystemResource) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) KeyStore(java.security.KeyStore) WebServiceSecurityException(org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)

Example 5 with KeyStoreFactoryBean

use of org.springframework.ws.soap.security.support.KeyStoreFactoryBean in project open-smart-grid-platform by OSGP.

the class NotificationClientConfigBase method webServiceTrustStoreFactory.

@Bean
public KeyStoreFactoryBean webServiceTrustStoreFactory() {
    final KeyStoreFactoryBean factory = new KeyStoreFactoryBean();
    factory.setType(this.webserviceTruststoreType);
    factory.setLocation(new FileSystemResource(this.webserviceTruststoreLocation));
    factory.setPassword(this.webserviceTruststorePassword);
    return factory;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) KeyStoreFactoryBean(org.springframework.ws.soap.security.support.KeyStoreFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

KeyStoreFactoryBean (org.springframework.ws.soap.security.support.KeyStoreFactoryBean)6 Bean (org.springframework.context.annotation.Bean)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 KeyStore (java.security.KeyStore)2 KeyStoreException (java.security.KeyStoreException)2 KeyManagersFactoryBean (org.springframework.ws.soap.security.support.KeyManagersFactoryBean)2 TrustManagersFactoryBean (org.springframework.ws.soap.security.support.TrustManagersFactoryBean)2 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 SSLContext (javax.net.ssl.SSLContext)1 DefaultHostnameVerifier (org.apache.http.conn.ssl.DefaultHostnameVerifier)1 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)1 WebServiceSecurityException (org.opensmartgridplatform.shared.exceptionhandling.WebServiceSecurityException)1