带有 https 和未签名证书的 Spring HTTP 调用程序

标签 spring ssl https ssl-certificate httpinvoker

我们已经使用 Springs HttpInvoker 几个星期了,它的效果非常好。从我的前端(网络)应用程序,我像这样连接到后端的 userService:

<bean id="userService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="http://${backend.host}/backend-ws/remoting/UserService"/>
    <property name="serviceInterface" value="com...service.UserService"/>
</bean>

然后将 UserService 很好地注入(inject)到我们的前端类中。

现在我们将其部署在适当的 (WAS7) 服务器上,并且要求使用 SSL (https)。因此,我将(serviceUrl 的)http 更改为 https,但随后我得到:

 org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [https://pbp-dev.dev.echonet/public/backend-ws/remoting/ParameterHelper]; nested exception is 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

这是有道理的,因为安装在服务器(WAS 运行的地方)上的证书不是由 CA 签名的。

我们已经有了一些这方面的经验,因为在同一个 WAS 上运行着一个网络服务;为此,我们使用 cxf 并生成了一个 jks 文件(使用 keytool),该文件驻留在客户端应用程序中并设置如下:

<http:conduit name="https://serverurl/.*">
<http:tlsClientParameters secureSocketProtocol="SSL" disableCNCheck="false">
    <sec:trustManagers>
        <sec:keyStore type="jks" password="pass123" resource="trust.jks"/>
    </sec:trustManagers>
</http:tlsClientParameters>

我想对于 Http Invoker,我们需要做类似的事情,但我们不知道如何在调用程序中使用这个 trust.jks。

我发现的一件事是使用不同的 requestExecutor;像这样:

<bean id="userService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="https://${backend.host}/backend-ws/remoting/UserService"/>
    <property name="serviceInterface" value="com...service.UserService"/>
    <property name="httpInvokerRequestExecutor">
    <bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor" />
    </property>
</bean>

此后我不再收到证书错误,但从那时起我似乎没有创建 userService:

NoSuchBeanDefinitionException: No matching bean of type [com...service.UserService] found for dependency

最佳答案

如果您混合在此处 (http://stackoverflow.com/questions/5947162/https-and-self-signed-certificate-issue) 中找到的内容来配置返回的 HttpClient 以具有预配置的 SSLSocketFactory,您可以更改套接字工厂的主机名验证程序以接受证书,类似于此:

xxx.setHostnameVerifier(new HostnameVerifier() {
    public boolean verify(String hostname, SSLSession session) { println("bypassing ssl cert handshaking as configured for self signed cert."); return true; }
});

根据您的配置,除了使用 CommonsHttpInvokerRequestExecutor 之外,您还必须配置使用的 HTTPClient 和 SSL Socket 工厂

我知道这可能无法完全回答您的问题,但它是其他搜索的起点!祝你好运,不要忘记发布最终解决方案。

关于带有 https 和未签名证书的 Spring HTTP 调用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741431/

相关文章:

spring - 具有自己的 UI 和 Spring 和 Thymeleaf 的微服务

mysql - 如何在 Spring JSF MySQL 应用程序中正确显示阿拉伯语?

unit-testing - AbstractTransactionalJUnit4SpringContextTests : can't get the dao to find inserted data

android - Ubuntu-Apache ssl 更新

java - Spring框架: Register conversion-service with java config

javax.net.ssl.SSLContext 到 io.netty.handler.ssl.SslContext

ruby-on-rails - 如何在 Heroku 上的自定义域上使用 HTTPS?

apache - 更改 apache2 服务器的 ssl 端口。 (ERR_SSL_PROTOCOL_ERROR)

ssl - 无法激活与 Django 和 Nginx 的 HTTPS 链接

java - 如何在 Java/使用 Firebug 中检索 Google Analytic cookie?