У меня есть проект Spring Web Services (пример весны: https://spring.io/guides/gs/producing-web-service/), и я хочу установить защиту. Ну, когда я добавляю XwsSecurityInterceptor, выполнение не выполняется, потому что компилятор не нашел класс: com/sun/xml/wss/XWSSecurityExceptionПроблемы с Spring WS Security
Ниже вы можете найти мой pom.xml, настройку веб-службы и трассировку ошибок:
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
Спасибо!