当前位置: 首页 > 知识库问答 >
问题:

晒太阳。安全验证器。ValidatorException:PKIX路径生成失败错误

姬振
2023-03-14

我的应用程序调用一个web服务,以便对该web服务中的特定用户进行身份验证。该web服务有自己的自签名CA证书。我正在使用该服务的POST REST调用,通过传递用户的用户名和密码来验证用户,但随后我收到了这个错误。。

我创建了一个密钥库,并将该服务器证书导入其中。我在应用程序中使用该密钥库来信任web服务。将证书导入JDK的cacerts可以解决我的问题,但该应用程序可以根据客户机的要求迁移到其他服务器。因此,将该证书导入jdk不会解决问题,因为该证书也必须在该服务器上导入。所以我必须通过使用密钥库的应用程序代码来信任它。我搜索了很多博客和帖子,每个人都建议将CA证书导入JDK的cacerts,或者忽略异常,盲目接受每个CA证书,比如链接PKIX路径构建在进行SSL连接时失败。

我的错误非常相似,但在这种情况下,这些方法似乎都不适用于我。为了验证用户身份,我在应用程序中所做的工作如下,如果这种方法有任何错误,请纠正我。。。

>

  • 创建密钥库“authenticate.keystore”

    -imported the self-signed certificate into that keystore.
    

    声明了加载密钥库的静态块

    static{
    Properties properties;
    try {
    properties = new Properties();
    properties.load(Util.class.getClassLoader().getResourceAsStream("application.properties"));
    System.out.println("Properties loaded successfully");
    } catch (IOException e) {
    properties = null;
    e.printStackTrace();
    }
    String keyStore = Util.class.getClassLoader().getResource(properties.getProperty("KeyStoreLocation")).getFile();
    System.setProperty("javax.net.ssl.trustStore", keyStore );
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    Security.addProvider( (Provider)Class.forName("com.sun.crypto.provider.SunJCE").newInstance());
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    }
    

    然后从会话中获取用户凭据,并使用REST调用对客户端进行身份验证。这里我使用的是org。阿帕奇。平民httpclient。方法。后方法

    HttpSession session = request.getSession();
    String userName = (String) session.getAttribute("j_username");
    String password = (String) session.getAttribute("USER_PASSWORD");           
    PostMethod methodP = new PostMethod("location");
    method.addParameter("username", userName);
    method.addParameter("password", password);
    authenticateUser(method);
    

    打开连接并尝试进行身份验证。我正在使用org.apache.commons.httpclient.HttpClient

    public String authenticateUser(PostMethod method){
    try{
    final HttpClient httpClient = new HttpClient();
    httpClient.executeMethod(method);
    if(statusCode==200)
    method.releaseConnection();
    }
    catch(Exception e){
    e.printStackTrace();
    method.releaseConnection();
    }        
    return null;
    }
    

    但在执行时,我得到了PKIX路径绑定错误。正在粘贴下面的完整堆栈跟踪。。。

    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1902)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1338)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1032)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1328)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1299)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getResponseCode(HttpsURLConnectionOldImpl.java:308)
    at sysvana.helpdesk.HelperTicket.httpTicketGET(HelperTicket.java:238)
    at sysvana.helpdesk.ActionHelpDeskBean.loadTickets(ActionHelpDeskBean.java:329)
    at sysvana.helpdesk.ActionHelpDeskBean.getAllTickets(ActionHelpDeskBean.java:292)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
    at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:273)
    at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
    at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
    at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
    at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2508)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2129)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2077)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:286)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:244)
    at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:670)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at com.liferay.faces.bridge.lifecycle.LifecycleWrapper.render(LifecycleWrapper.java:45)
    at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:280)
    at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:92)
    at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:99)
    at javax.portlet.faces.GenericFacesPortlet.doView(GenericFacesPortlet.java:255)
    at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
    at javax.portlet.faces.GenericFacesPortlet.doDispatch(GenericFacesPortlet.java:204)
    at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)
    at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:607)
    at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:359)
    at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1207)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:97)
    at com.liferay.portal.servlet.PACLRequestDispatcherWrapper.doDispatch(PACLRequestDispatcherWrapper.java:90)
    at com.liferay.portal.servlet.PACLRequestDispatcherWrapper.include(PACLRequestDispatcherWrapper.java:54)
    at com.liferay.portal.util.PortalImpl.renderPortlet(PortalImpl.java:5158)
    at com.liferay.portal.util.PortalUtil.renderPortlet(PortalUtil.java:1569)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processPortlet(RuntimePortletImpl.java:165)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processPortlet(RuntimePortletImpl.java:97)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.doProcessTemplate(RuntimePortletImpl.java:531)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.doDispatch(RuntimePortletImpl.java:394)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processTemplate(RuntimePortletImpl.java:228)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletImpl.processTemplate(RuntimePortletImpl.java:216)
    at com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil.processTemplate(RuntimePortletUtil.java:113)
    at org.apache.jsp.html.portal.layout.view.portlet_jsp._jspService(portlet_jsp.java:507)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
    at com.liferay.portal.action.LayoutAction.includeLayoutContent(LayoutAction.java:468)
    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:735)
    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:249)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:176)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:560)
    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:537)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:138)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:335)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:294)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:246)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:163)
    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:216)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:57)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:187)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
    
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
    at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
    at sun.security.validator.Validator.validate(Validator.java:260)
    at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1320)
    ... 210 more
    
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:196)
    at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:268)
    at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
    ... 216 more
    

    我被这种情况困扰了很长一段时间,真的被它所困扰。任何帮助或指导都将不胜感激。

  • 共有2个答案

    戚奇略
    2023-03-14

    在我的例子中,发生的是我的JRE版本。我使用的是EclipseX64,我的tomcat使用的是JRE x32,在我为JDKx64中的JRE更改了tomcat的JRE之后,这个错误停止了。

    端木鹏
    2023-03-14

    我认为问题在于:

    String keyStore = Util.class.getClassLoader().getResource(properties.getProperty("KeyStoreLocation")).getFile();
    

    这有两个问题:

    >

  • URL。getFile()方法不会将文件:URL转换为文件名。该方法返回URL的路径部分。文件名中的许多合法字符必须在URL中转义,在这种情况下,原始路径部分将不是现有文件名。(术语解释:在90年代早期,当java.net.URL类被设计时,通常将URL的路径部分称为“文件”,因为大多数URL指的是远程系统上的物理文件,尤其是ftp:URL。)

    如果您的类位于。jar文件(如果不是,它应该是),URL根本不是文件:URL;它是一个jar:URL。

    javax。网ssl。信任库必须指向一个文件,因此如果您的类确实位于。jar文件,您根本无法将资源URL转换为文件。但是,您可以将其复制到文件:

    try (InputStream keystoreStream =
            Util.class.getClassLoader().getResourceAsStream(
                properties.getProperty("KeyStoreLocation"))) {
    
        Path keystore = Files.createTempFile("keystore", ".jks");
        Files.copy(keystoreStream, keystore,
            StandardCopyOption.REPLACE_EXISTING);
        System.setProperty("javax.net.ssl.trustStore", keystore.toString());
    }
    

  •  类似资料:
    • 我有三个基于java的web应用程序app1,app2和app3在生产。所有3个都由经过验证的CA进行验证,并托管在3个不同的Web服务器和http上。 下面是证书的层次结构,当我通过web浏览器点击这些应用程序时,我可以看到。 app1、app2证书租用人制度相同。E app3证书雇佣关系为 现在,当app1连接到app2时,一切正常。但当app1连接到app3时,会出现以下异常 现在我看了一下

    • 我有一个类,它用一个xml点击一个安全的URL(以https开头),然后在最后处理xml并返回响应。但在这样做的同时,我也遇到了一些例外<代码>javax。网ssl。例外:太阳。安全验证器。ValidatorException:PKIX路径生成失败:sun。安全供应商。certpath。SunCertPathBuilderException:找不到请求目标的有效认证路径 我在谷歌上搜索了很多,找到

    • 我越来越不正常了 太阳安全验证器。ValidatorException:PKIX路径生成失败:sun。安全供应商。certpath。SunCertPathBuilderException:找不到请求目标的有效证书路径 我已在该位置设置SSL证书 C:\Program Files\AdoptOpenJDK\jdk-11.0.9.11-hotspot\lib\security 但我在点击服务器时遇到了

    • 我正在获取javax.net.ssl.sslHandShakeException:Sun.Security.Validator.ValidatorException:PKIX路径构建失败:Sun.Security.Provider.CertPath.SunCertPathBuilderException:找不到请求目标的有效认证路径异常,如何解决?这是我的密钥库

    • 正在尝试从创建wsdl客户端https://example.com?wsdl.使用以下命令wsimport-keephttps://example.com?wsdl 我已经使用这个命令keytool-import-alias ctp-file C:\Users\ravi\Desktop\ctplive安装了ssl证书。cer-keystore C:\Program Files\Java\jdk1。

    • 我一直在尝试调试这个错误,但没有成功。 本质上,我是通过我的应用程序联系外部应用程序的。连接建立良好,应用程序通过回调URL联系回我的应用程序,然后我需要向外部应用程序发送最终验证。最后一步由于SSLhandshajee异常而失败。 javax。网ssl。例外:太阳。安全验证器。ValidatorException:PKIX路径生成失败:sun。安全供应商。certpath。SunCertPath