java - 无法安全调用 Web 服务

标签 java jax-ws cxf mule ws-security

我创建了一个 CXF JAXWS 服务,如下所示。

我提供了一个自定义 UserNameToken validator 和一个回调处理程序。

但这不起作用。每次都会抛出错误。

<http:inbound-endpoint address="http://localhost:8080/HelloService"  exchange-pattern="request-response">
    <cxf:jaxws-service serviceClass="com.example.service.HelloServiceImpl" >
    <cxf:ws-security>
    <cxf:ws-config>                     
    <cxf:property key="action" value="UsernameToken" />
    </cxf:ws-config>
    <cxf:ws-custom-validator >                  
        <cxf:username-token-validator ref="customUsernameTokenValidator" />
    </cxf:ws-custom-validator>                  
      </cxf:ws-security> 
     <cxf:properties>
            <spring:entry key="ws-security.ut.validator" value-ref="customUsernameTokenValidator" ></spring:entry>
            <spring:entry key="ws-security.callback-handler" value-ref="myPasswordCallback" ></spring:entry>
        </cxf:properties>
        .....
        .....

关于我的 WSDL 绑定(bind)的策略如下

        <sp:SupportingTokens> 
            <wsp:Policy>
                <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                    <wsp:Policy />
                </sp:UsernameToken>
            </wsp:Policy>
        </sp:SupportingTokens>

当我使用用户名 token 和密码从 SOAPUI 发出请求时,出现以下错误。

2013-04-10 11:08:13,811 WARN  [qtp1221956599-40 - /HelloService] logging.LogUtils (LogUtils.java:384) - Interceptor for {http://example.org/HelloService}ProductSOAPService#{http://example.org/HelloService}addCompany has thrown exception, unwinding now
    org.apache.cxf.interceptor.Fault
        at org.mule.module.cxf.MuleInvoker.invoke(MuleInvoker.java:106)
        at org.mule.module.cxf.MuleJAXWSInvoker.invoke(MuleJAXWSInvoker.java:47)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
        .....
        .....
    Caused by: java.lang.NullPointerException
        at org.mule.module.cxf.MuleInvoker.invoke(MuleInvoker.java:60)
        ... 29 more

请帮助我理解我在这里缺少的内容。

注意:我已经尝试使用 cxf:ws-security 的 Mule 方式在 jaxws 上实现安全性,并且我的服务正在运行并给出正确的响应。

最佳答案

您的 cxf jaxws-service 应如下所示。然后它应该可以工作。

<http:inbound-endpoint address="http://localhost:8080/HelloService"  exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="com.example.service.HelloServiceImpl" >
 <cxf:properties>
        <spring:entry key="ws-security.ut.validator" value-ref="customUsernameTokenValidator" ></spring:entry>
        <spring:entry key="ws-security.callback-handler" value-ref="myPasswordCallback" ></spring:entry>
    </cxf:properties>
  </cxf:jaxws-service>

关于java - 无法安全调用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15929997/

相关文章:

java - 运行用 Scala 编写的项目的所有测试套件,并覆盖 Intellij

java - jax-ws 生成 : @WebMethod vs. @ResponseWrapper

java - 在 JAX-WS 中定义绑定(bind)名称

java - 在 WebLogic 中运行的 JAX-WS 客户端中,PasswordDigest 身份验证失败

rest - Apache CXF 和 JAX-RS 中配置的 RequestHandler 的执行顺序

java - 从过滤器序列化 Jersey 异常会引发错误

java - iText 中的高棉语 Unicode

java - RoboSpring。如何在项目中从库中扩展bean

java - GWT 垃圾收集

java - Jetty vs CXF/选择哪一个?