Spring WS安全性问题

时间:2016-05-20 08:15:41

标签: spring web-services spring-security spring-boot ws-security

我有一个Spring Web Services项目(Spring的例子:https://spring.io/guides/gs/producing-web-service/),我想设置安全性。好吧,当我添加XwsSecurityInterceptor时执行失败,因为编译器没有找到类:com / sun / xml / wss / XWSSecurityException

下面,您可以找到我的pom.xml,Web服务配置和错误跟踪:

的pom.xml

  ...
  <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.3.5.RELEASE</version>

  <!-- Dependencia Proyecto Web de Spring Boot -->
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  <!-- Dependencia para Web Services de Spring Boot -->
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-ws</artifactId>
  </dependency>

 <dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-security</artifactId>
    <version>2.3.0.RELEASE</version>
</dependency>


  <dependency>
      <groupId>wsdl4j</groupId>
      <artifactId>wsdl4j</artifactId>
  </dependency>

  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
  </dependency>

  <dependency>
        <groupId>org.apache.ws.security</groupId>
        <artifactId>wss4j</artifactId>
        <version>1.6.19</version>
    </dependency>

...

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }
@Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("CountriesPort");
    wsdl11Definition.setLocationUri("/ws");
    wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
    wsdl11Definition.setSchema(countriesSchema);
    return wsdl11Definition;
}

@Bean
public XsdSchema countriesSchema() {
    return new SimpleXsdSchema(new ClassPathResource("ws/countries.xsd"));
}


@Bean(name= "wsSecurityInterceptor")
public XwsSecurityInterceptor xwsSecurityInterceptor(){

    Resource securityPolicy = new ClassPathResource("ws/resources/SecurityPolicy.xml");

    XwsSecurityInterceptor xwsSI = new XwsSecurityInterceptor();

    xwsSI.setPolicyConfiguration(securityPolicy);
    xwsSI.setCallbackHandler(simplePasswordValidationCallbackHandler());

    return xwsSI;

}


@Bean(name = "passwordValidationHandler")
public SimplePasswordValidationCallbackHandler simplePasswordValidationCallbackHandler(){

    HashMap<String, String> user = new HashMap<String, String>();
    user.put("Bert", "Ernie");

    SimplePasswordValidationCallbackHandler spvch = new SimplePasswordValidationCallbackHandler();
    spvch.setUsersMap(user);

    return spvch;       
}

}

错误跟踪

Caused by: java.lang.ClassNotFoundException: com.sun.xml.wss.XWSSecurityException
    at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_20]
    at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_20]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_20]
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_20]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_20]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_20]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_20]
    ... 30 common frames omitted

谢谢!

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,我刚刚为我的pom添加了下一个依赖项:

<dependency>
        <groupId>com.sun.xml.wss</groupId>
        <artifactId>xws-security</artifactId>
        <version>3.0</version>
        <exclusions>
            <exclusion>
                <groupId>javax.xml.crypto</groupId>
                <artifactId>xmldsig</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

谢谢!