jax-ws之如何在 tomcat 服务器上使用 jaxws 验证 ws-security soap header
无情
阅读:81
2025-05-04 20:05:19
评论:0
我使用 JAX-WS RT 开发了一个简单的 Web 服务,并将其部署在 Tomcat 6 服务器上。我需要在 SOAP header 中使用 ws-security 来验证对我的 Web 服务的调用。
我的方法是使用链处理程序来提取 soap header 中的用户名和密码,并在我的代码中进行身份验证。这是正确的方法吗?如果不是,正确的方法是什么?
使用 soapUI 我已通过以下 header 发送
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>test</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">test</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
使用这个标题我得到以下错误
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<faultstring>MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood</faultstring>
<faultcode>SOAP-ENV:MustUnderstand</faultcode>
</SOAP-ENV:Fault>
如何使用 JAX-WS rt 设置我的 Web 服务以接受此类 header 并进行身份验证。
请您参考如下方法:
使用链处理程序是处理 ws-security header 的一种方法,与 rampart 等框架相比,它只是一种较低级别的方法(尽管这些框架通常只是为您实现这些处理程序)。如果您编写自己的消息处理程序,则必须重写
Set<QName> getHeaders()
声明您了解哪些 header 。在这种情况下,返回一个包含
QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security")
避免“必须理解”错误。
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。



