首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring LdapContextSource忽略SSLSocketFactory

Spring LdapContextSource忽略SSLSocketFactory
EN

Stack Overflow用户
提问于 2015-05-30 12:30:28
回答 2查看 4.8K关注 0票数 2

Spring-Ldap 1.3.1

为了用TLS测试spring,我创建了一个CustomSSLSocketFactory类,接受所有证书(我知道这个安全性问题)。

但是,运行测试将导致

代码语言:javascript
复制
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

启用SSL调试后,将记录标准信任存储被认为是:

代码语言:javascript
复制
trustStore is: [path_to_jre]\cacerts
trustStore type is : jks
trustStore provider is : 
init truststore

以下是测试的执行方式:

代码语言:javascript
复制
    LdapContextSource lcs = new LdapContextSource();

    lcs.setBase("[base]");
    lcs.setUserDn("[userDn]");
    lcs.setPassword("[password]");
    lcs.setPooled(false);
    lcs.setUrl("ldaps://[server-address]:636");

    DefaultTlsDirContextAuthenticationStrategy strategy = new DefaultTlsDirContextAuthenticationStrategy();
    strategy.setShutdownTlsGracefully(true);
    strategy.setSslSocketFactory(new CustomSSLSocketFactory());  // <-- not considered at all
    strategy.setHostnameVerifier(new HostnameVerifier(){

        @Override
        public boolean verify(String hostname, SSLSession session){

            return true;
        }
    });

    lcs.setAuthenticationStrategy(strategy);
    lcs.afterPropertiesSet();
    lcs.getContext("[principal]", "[credential]");

对于另一个测试,我像这样扩展了LdapContextSource:

代码语言:javascript
复制
public class ExtLdapContextSource extends LdapContextSource{

    public DirContext getContext(String principal, String credentials) {

        getAnonymousEnv().put("java.naming.security.protocol", "ssl");
        getAnonymousEnv().put("java.naming.ldap.factory.socket", "[package].CustomSSLSocketFactory");
        return super.getContext(principal, credentials);
    }
}

握手比预期的要好,但是出现了另一个错误:

代码语言:javascript
复制
javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: DSID-0C090DF2, comment: TLS or SSL already in effect, data 0, v1db1
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.extendedOperation(Unknown Source)
at javax.naming.ldap.InitialLdapContext.extendedOperation(Unknown Source)
at org.springframework.ldap.core.support.AbstractTlsDirContextAuthenticationStrategy.processContextAfterCreation(AbstractTlsDirContextAuthenticationStrategy.java:133)
at org.springframework.ldap.core.support.AbstractContextSource.getContext(AbstractContextSource.java:109)

因此,问题是:如何正确设置spring以使其使用所提供的SSLSocketFactory?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-01 12:08:50

因为ldaps,它实际上失败了。如果相应地设置了信任存储,则异常显示不能建立TLS/SSL,因为它已经在运行(因此不能组合ldaps-URL和DefaultTlsDirContextAuthenticationStrategy )。

而且,无论StartTLS是否在端口389上工作,似乎都依赖于目录。

票数 2
EN

Stack Overflow用户

发布于 2018-05-24 21:51:06

若要修复错误,请使用SimpleDirContextAuthenticationStrategy而不是DefaultTlsDirContextAuthenticationStrategy

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30546193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档