使用cxf拦截器

时间:2017-01-20 14:25:28

标签: web-services cxf soapui ws-security wss4j

我已经开发了一种自顶向下的服务,并且使用apache cxf工作正常。现在我正在尝试向服务添加基本身份验证。我已经根据apache cxf文档配置了服务器回调处理程序和spring bean(cxf-servlet.xml)。但仍然 我在SOAP UI上执行soap请求时遇到错误。

<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" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Timestamp wsu:Id="TS-14"><wsu:Created>2017-01-20T13:54:07Z</wsu:Created><wsu:Expires>2017-01-20T14:27:27Z</wsu:Expires></wsu:Timestamp>
<wsse:UsernameToken wsu:Id="UsernameToken-13">
<wsse:Username>username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">vPFjyEznvPB8HkWDOoL7dw==</wsse:Nonce>
<wsu:Created>2017-01-20T13:54:07.244Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>

下面是我的servercallback处理程序部分。

<bean id="myPasswordCallback"
        class="com.firstbest.webservice.ofacimpl.ServerPasswordCallback" />
    <jaxws:endpoint publish="true" id="ofacid"
        implementor="com.firstbest.webservice.ofacimpl.OfacInquirySearchImpl"
        address="/PerformOFACValidationWS">
        <jaxws:inInterceptors>
            <bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
                <constructor-arg>
                    <map>
                        <entry key="action" value="UsernameToken" />
                        <entry key="passwordType" value="PasswordText" />
                        <entry key="passwordCallbackRef">
                            <ref bean="myPasswordCallback" />
                        </entry>
                    </map>
                </constructor-arg>
            </bean>
        </jaxws:inInterceptors>
    </jaxws:endpoint>

我在网上尝试了不同的解决方案。但是对我帮助不大。

以下是错误: -

  

警告:拦截器   {http://sdawweaid1.gc.win-na.com/QBE_OFAC/Producer/BridgerInsight/WS/executeIService_SearchWS} OfacInquirySearchImplService#{http://sdawweaid1.gc.win-na.com/QBE_OFAC/Producer/BridgerInsight/WS/executeIService_SearchWS} executeIService_Search   抛出异常,现在解除   org.apache.cxf.binding.soap.SoapFault:出现安全错误   在验证消息时遇到   org.apache.cxf.ws.security.wss4j.WSS4JUtils.createSoapFault(WSS4JUtils.java:233)     在   org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessageInternal(WSS4JInInterceptor.java:317)     在   org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:171)     在   org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessage(WSS4JInInterceptor.java:80)     在   org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)     在   org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)     在   org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:252)     在   org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)     在   org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)     在   org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)     在   org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)     在   org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)     在   org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at   org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)     在   org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)     在   org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)     在   org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)     在   org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)     在   org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)     在   org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)     在   org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)     在   org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)     在   org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)     在org.mortbay.jetty.Server.handle(Server.java:326)处   org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)     在   org.mortbay.jetty.HttpConnection $ RequestHandler.content(HttpConnection.java:945)     在org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)at   org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)at at   org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)at at   org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)     在   org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:582)   引起:org.apache.wss4j.common.ext.WSSecurityException:错误   被发现处理标题   org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.checkActions(WSS4JInInterceptor.java:361)     在   org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor.handleMessageInternal(WSS4JInIntercept

0 个答案:

没有答案