1

我有一个使用 netbeans 7 和 glassfish 3.1.2 开发的 jax-ws Web 服务。我将 Web 服务配置为使用具有对称密钥安全性和默认密钥库的用户名身份验证。当我在 localhost 中测试我的 Web 服务时,一切正常,但是当我在远程测试服务器中部署它时,它没有工作。首先,我收到异常抱怨,Key used to decrypt EncryptedKey cannot be null所以我将本地 keystore.jks 和 cacerts.jks 上传到远程服务器。

现在我得到了这些例外:

服务器端:

WSITPVD0035: Error in Verifying Security in Inbound Message. com.sun.xml.wss.impl.PolicyViolationException: com.sun.xml.wss.impl.WssSoapFaultException: Invalid Security Header at 
com.sun.xml.wss.impl.policy.verifier.MessagePolicyVerifier.verifyPolicy(MessagePolicyVerifier.java:151) at 
com.sun.xml.ws.security.opt.impl.incoming.SecurityRecipient.createMessage(SecurityRecipient.java:1003) at 
com.sun.xml.ws.security.opt.impl.incoming.SecurityRecipient.validateMessage(SecurityRecipient.java:248) at 
com.sun.xml.wss.provider.wsit.WSITServerAuthContext.verifyInboundMessage(WSITServerAuthContext.java:588) at 
com.sun.xml.wss.provider.wsit.WSITServerAuthContext.validateRequest(WSITServerAuthContext.java:361) at 
com.sun.xml.wss.provider.wsit.WSITServerAuthContext.validateRequest(WSITServerAuthContext.java:264) at 
com.sun.enterprise.security.webservices.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:173) at 
com.sun.enterprise.security.webservices.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:144) at 
com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119) at 
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:961) at 
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:910) at 
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:873) at 
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:775) at 
com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:386) at 
com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:640) at 
com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263) at 
com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:163) at 
org.glassfish.webservices.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:120) at 
org.glassfish.webservices.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:91) at 
org.glassfish.webservices.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:200) at 
org.glassfish.webservices.EjbWebServiceServlet.service(EjbWebServiceServlet.java:131) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:770) at 
com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059) at 
com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999) at 
com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434) at 
com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:384) at 
com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179) at 
com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117) at 
com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354) at 
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at 
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) at 
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at 
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at 
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at 
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at 
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at 
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at 
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at 
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at 
com.sun.grizzly.ContextTask.run(ContextTask.java:71) at 
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at 
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at 
java.lang.Thread.run(Thread.java:662) Caused by: com.sun.xml.wss.impl.WssSoapFaultException: Invalid Security Header at 
com.sun.xml.ws.security.opt.impl.util.SOAPUtil.newSOAPFaultException(SOAPUtil.java:159) at 
com.sun.xml.wss.impl.policy.verifier.MessagePolicyVerifier.processSecondaryPolicy(MessagePolicyVerifier.java:220) at 
com.sun.xml.wss.impl.policy.verifier.MessagePolicyVerifier.verifyPolicy(MessagePolicyVerifier.java:144) ... 43 more

客户端:

Exception in thread "AWT-EventQueue-0" javax.xml.ws.soap.SOAPFaultException: Invalid Security Header
    at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:126)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:123)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
    at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)

我怎样才能解决这个问题 ?

谢谢 。

4

2 回答 2

0

堆栈跟踪对我来说看起来并不熟悉,但也许您的问题是证书本身

创建证书时,您应该设置一个“服务器名称”。客户端将使用它来检查证书的 'server name' 是否与 URL 'server name' 匹配。如果服务器名称不匹配,客户端应该中止连接,因为它可能是被盗的证书!!!。有关更多信息,请查看本教程

以 java 客户端为例:如果您为客户端创建证书,'localhost'当且仅当它使用类似'https://localhost/stuff...'. 因此,如果您尝试使用相同的客户端访问相同的应用程序但使用 IP 之类'https://10.0.0.1/stuff...'的,则应该会出现验证错误。

注意:Java Web 服务客户端的默认配置会执行此检查,但如果您想绕过此客户端验证,请查看此帖子

尝试检查这是否是您遇到的问题。如果是这种情况,您有几种解决方案:

  • 为部署应用程序的服务器创建证书
  • 禁用客户端验证

PS:我从来没有在服务器端做一些特别的事情来解决这类问题。安装正确的证书就足够了

于 2012-06-28T16:15:48.923 回答
0

就我而言,问题出在 CommandMap 中。需要在 CommandMap 中添加“应用程序/密码值”处理程序,因为 WSIT 在加载 CVDataHandler 类时只执行一次。

有关如何添加的更多详细信息,请参见 com.sun.xml.ws.security.opt.impl.util.CVDataHandler 静态块。

于 2016-11-16T12:38:34.233 回答