Web服务基于SSL的出站网关(.cert +用户/密码)

时间:2014-12-12 09:53:20

标签: web-services certificate spring-integration keystore ws-security

我正在使用Spring Integration,我想知道是否可以通过MarshallingWebServiceOutboundGateway以任何方式保护输入/输出。

我的结构:

请求频道 - >网关 - >响应渠道


更新III

  • 安全性是HTTPS用户/密码
  • 凭证书验证

现在,我简化了我的逻辑。我试图以其他方式配置Wss4jSecurityInterceptor。从Spring WS文档中,我看到了这个例子:

<bean id="wsSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
    <property name="securementActions" value="UsernameToken"/>
    <property name="securementUsername" value="Ernie"/>
    <property name="securementPassword" value="Bert"/>
    <property name="validationActions" value="Signature"/>
    <property name="validationSignatureCrypto">
    <bean class="org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean">
        <property name="keyStorePassword" value="123456"/>
        <property name="keyStoreLocation" value="classpath:/keystore.jks"/>
    </bean>
</property>
</bean>

适应我的Java配置:

@Bean
public Wss4jSecurityInterceptor wss4jSecurityInterceptor() throws IOException, Exception{
    Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
    interceptor.setSecurementActions("UsernameToken Encrypt");
    interceptor.setSecurementUsername("https user");
    interceptor.setSecurementPassword("https password");
    interceptor.setValidationActions("Signature");
    interceptor.setValidationSignatureCrypto( signature().getObject() );
    return interceptor;
}

public CryptoFactoryBean signature() throws IOException{
    CryptoFactoryBean trustStore = new CryptoFactoryBean();
    trustStore.setKeyStoreLocation( new ClassPathResource("security/keystore.jks") );
    trustStore.setKeyStorePassword( "keystore_password" );
    return trustStore;
}

这非常令人沮丧,但我收到了一个新错误:

Caused by: java.lang.IllegalArgumentException: validationSignatureCrypto is required
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor.afterPropertiesSet(Wss4jSecurityInterceptor.java:515)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
... 58 more

更新II

在我的第二种方法中,我将配置更改为@Bean方法。此时,我刚刚配置用户/密码但没有成功,但我需要使用我的.cert文件连接到服务器。

@Bean
public CallbackHandler passwordCallbackHandler(){
    SimplePasswordValidationCallbackHandler handler = new SimplePasswordValidationCallbackHandler();
    Properties users = new Properties();
    users.setProperty("user1", "pass1");
    users.setProperty("user2", "pass2");
    handler.setUsers(users);
    return handler;
}

@Bean 
public ClientInterceptor wsSecurityInterceptor(){
    XwsSecurityInterceptor xws = new XwsSecurityInterceptor();
    xws.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
    xws.setCallbackHandlers(new CallbackHandler[]{
        passwordCallbackHandler()
    });
    return xws;
} 

我的securityPolicy.xml:

<xwss:SecurityConfiguration xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:RequireUsernameToken passwordDigestRequired="false" nonceRequired="false"/>
</xwss:SecurityConfiguration>

收到以下错误:

Caused by: java.lang.ClassNotFoundException: com.sun.xml.wss.XWSSecurityException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 72 more

更新我

我整合了:

  • 弹簧整合-WS
  • 弹簧的WS-Security

    @Configuration
    @EnableWs
    @EnableIntegration
    public class ConfigWS {
    @Bean
      public MessageHandler wsOutboundGateway() throws Exception {
    
        MarshallingWebServiceOutboundGateway gw =new MarshallingWebServiceOutboundGateway(myprovider, 
                jaxb2Marshaller(), 
                jaxb2Marshaller());
        gw.setOutputChannelName("responseChannel");
    
        SimplePasswordValidationCallbackHandler spvch = new SimplePasswordValidationCallbackHandler();
        Properties users = new Properties();
        users.setProperty("user", "pass");      
        spvch.setUsers( users );    
    
        XwsSecurityInterceptor xws = new XwsSecurityInterceptor();
        xws.setSecureRequest(true);
        xws.setSecureResponse(true);
        xws.setPolicyConfiguration( new ClassPathResource("securityPolicy.xml"));
        xws.setCallbackHandler( spvch );
    
        gw.setInterceptors( xws );
        gw.afterPropertiesSet();
    
        return gw;
    }
    ....
    }
    

我得到了:

Caused by: java.lang.ClassNotFoundException: com.sun.xml.wss.impl.callback.PasswordValidationCallback$PasswordValidator
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    ... 50 more
  • 如何配置安全性securityPolicy.xml 对服务器证书进行身份验证。
  • SimplePasswordValidationCallbackHandler是否需要解决方案 使用服务器证书?也许我必须使用其他处理程序。
  • 我的证书提供商为我提供了一个.cert文件。因此,我生成了 .keystore与Oracle的keytool,但我不知道如何 在我的配置中包含此证书。

1 个答案:

答案 0 :(得分:1)

Spring Integration WebServices模块完全基于Spring WS。因此,只需遵循其giudeline,如何在client side上配置WSS。

只需将XwsSecurityInterceptorWss4jSecurityInterceptor注入<int-ws:outbound-gateway>