2016-07-28 55 views
2

我正在使用Spring SAML在我的应用程序中实现单点登录。 Evreything从SSO角度进行整合和正常工作。 也通过轴使用HTTP客户端后我的应用程序的另一种服务开始与下面的错误Spring SAML配置正在破坏其他http连接

{} http://xml.apache.org/axis/失败的堆栈跟踪:javax.net.ssl.SSLPeerUnverifiedException:SSL对失败的主机名名称验证:空

我已经看了答案提供的链接 Spring Security SAML + HTTPS to another page并遵循相同,但无济于事。

下面是TLSProtocolSocketFactory

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> 
    <property name="targetClass" value="org.apache.commons.httpclient.protocol.Protocol"/> 
    <property name="targetMethod" value="registerProtocol"/> 
    <property name="arguments"> 
     <list> 
      <value>https</value> 
      <bean class="org.apache.commons.httpclient.protocol.Protocol"> 
       <constructor-arg value="https"/> 
       <constructor-arg> 
        <bean class="org.springframework.security.saml.trust.httpclient.TLSProtocolSocketFactory"> 
         <constructor-arg ref="keyManager"/> 
         <constructor-arg><null/></constructor-arg> 
         <constructor-arg value="allowAll"/> 
        </bean> 
       </constructor-arg> 
       <constructor-arg value="443"/> 
      </bean> 
     </list> 
    </property> 
</bean> 

我已经导入了其他服务的证书在samlKeystore.jks以及配置。

在问题的任何帮助将apreciated

回答

0

我想这可能是你在找什么:Source

您正在使用豆TLSProtocolConfigurer这改变了HTTPS协议的受信任的证书和主机名验证HTTP客户端。您可以通过删除此Bean将HTTP客户端的行为恢复为默认值。然后,您需要确保加载元数据的实体(https://idp.ssocircle.com/idp-meta.xml)使用的证书在您的cacerts中可信,或者使用不带https的端点(http://idp.ssocircle.com/idp-meta.xml)。

或者,您可以通过将bean TLSProtocolConfigurer上的属性sslHostnameVerification设置为allowAll来禁用主机名验证。您还需要确保https://www.somepage.com(或其CA)的HTTPS证书包含在samlKeystore.jks中(请参阅Spring SAML manual)。

您可以在Spring SAML manual, chapter HTTP-based metadata provider with SSL中找到TLSProtocolConfigurer豆的更多详细信息。

+0

谢谢@ blur0224。我在上面的问题中发布了相同的链接,并遵循了指示。即使删除了上述bean,我也得到了异常'code' faultDetail: {http://xml.apache.org/axis/}stackTrace:javax.net.ssl.SSLException:主机名验证错误 at org。 opensaml.ws.soap.client.http.TLSProtocolSocketFactory.verifyHostname(TLSProtocolSocketFactory.java:153) at org.opensaml.ws.soap.client.http.TLSProtocolSocketFactory.createSocket(TLSProtocolSocketFactory。java:118) –

+0

如果您尝试使用具有自签名证书的java连接到webservice,也可能会出现此错误。 Java需要通过将它添加到JKS来显式信任该证书。是否有可能在同一时间转换为不同的JDK或更新为新的JDK,但可能没有加载该CA? – blur0224

+0

我拥有在samkeystore.jks和jre cacerts中加载的站点CA.一个观察我已经看到,当我使用Spring TLSSocketProtocolFcatory比在Opensaml的verifyHostname函数TLSProtocolFactory主机出来时总是从空的时候sslsesion.getPeerHost()... –

0

的问题是在PKIXX509CredentialTrustEnginecheckNames()功能,我们只为null而不是"null or Empty"检查trustedNames集合。

即使我们传递价值trustedNamesTLSProtocolSocketFactorygetPKIXResolver()方法来创建StaticPKIXValidationInformatonResolver,这个类的构造函数重新初始化的trustedNames收集到一个空的集合。
将行从
改为if(trustedNames == null)改为

if(trustedNames == null || trustedNames.isEmpty())
修复了我的问题。