问题描述
我正在学习一门课程来回顾一些 Spring 概念,并且我正在尝试实现一个具有简单密码验证安全性的 SOAP WS。
我的bean配置如下
@EnableWs
@Configuration
public class WsdlConfigService extends WsConfigurerAdapter {
// Other beans...
@Bean
public XwsSecurityInterceptor requestInterceptor() {
XwsSecurityInterceptor interceptor = new XwsSecurityInterceptor();
interceptor.setCallbackHandler(callbackHandler());
interceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
return interceptor;
}
@Bean
public SimplePasswordValidationCallbackHandler callbackHandler() {
SimplePasswordValidationCallbackHandler handler = new SimplePasswordValidationCallbackHandler();
handler.setUsersMap(Collections.singletonMap("admin","password"));
return handler;
}
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
interceptors.add(requestInterceptor());
}
}
和 securityPolicy.xml
配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<xwss:SecurityConfiguration xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:RequireUsernametoken passwordDigestrequired="false" noncerequired="false" />
</xwss:SecurityConfiguration>
当我尝试测试端点安全性时(我使用的是 Wizdler Chrome 扩展程序),我收到一个意外错误:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">com.sun.xml.wss.impl.WssSoapFaultException: javax.security.auth.callback.UnsupportedCallbackException; nested exception is com.sun.xml.wss.XWSSecurityException: com.sun.xml.wss.impl.WssSoapFaultException: javax.security.auth.callback.UnsupportedCallbackException</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
在 Wizdler 界面中,由于 SimplePassWrodValidationCallbackHandler
bean,我使用了 WSSE PasswordText 身份验证。
我在这里做错了什么?我尝试使用 Spring Boot 版本 2.5.1(撰写本文时的最新版本)和 2.4.5(课程中使用的版本)
如果您需要有关此问题的更多详细信息,请告诉我。预先感谢您的回答/评论。
解决方法
最后我发现了错误:我使用了不正确的 javax.security.auth.callback.CallbackHandler
实现:我使用的是 org.springframework.ws.soap.security.wss4j2.callback.SimplePasswordValidationCallbackHandler
但正确的是 org.springframework.ws.soap.security.xwss.callback.SimplePasswordValidationCallbackHandler
。
两个实现都来自 Spring 框架,应该做同样的事情(根据文档),但由于某种原因,第一个不支持。如果有人有更详细的信息,请告诉我。