Spring LDAP-java.io.IOException:无效的密钥库格式

时间:2018-11-02 16:51:34

标签: java spring-boot ldap

我们正在将LDAP迁移为使用SSL。我有一个Spring Boot应用程序,它将使用 spring-boot-starter-data-ldap unboundid-ldapsdk

这就是我设置LDAP上下文的方式

@Bean
public LdapContextSource contextSource() {
    LOGGER.info("Loading LDAP Context");
    LdapContextSource contextSource = new LdapContextSource();

    contextSource.setUrl(url);
    contextSource.setBase(base);
    contextSource.setUserDn(username);
    contextSource.setPassword(password);
    contextSource.setPooled(true);

    System.setProperty("com.sun.jndi.ldap.connect.pool", "true");
    System.setProperty("com.sun.jndi.ldap.connect.pool.maxsize", "300");
    System.setProperty("com.sun.jndi.ldap.connect.pool.timeout", "300000");
    contextSource.afterPropertiesSet();
    return contextSource;
}

LdapTemplate

@Bean
public LdapTemplate ldapTemplate() {
    return new LdapTemplate(contextSource());
}

我以这种方式设置证书

ClassLoader classLoader = getClass().getClassLoader();

    System.setProperty("javax.net.ssl.trustStore", new File(classLoader.getResource("certificates/prod.jks").getFile()).getAbsolutePath());

应用程序正常启动,但是当我在LDAP中查询类似内容时

        Filter filter = new EqualsFilter(filterAttr, request.getIdValue());

    LdapQuery query = query().searchScope(SearchScope.SUBTREE)
            .attributes(PROFILE_ATTRS).filter(filter);

    List<LDAPInfoResponse> response = ldapTemplate.search(query, new LDAPInfoResponseAttributesMapper());

我收到以下错误

  

2018-11-02 11:00:06.640错误10936 --- [nio-9010-exec-1] oaccC [。[。[。[。dispatcherServlet]:Servlet.dispatcherServlet]的Servlet.service()路径[/ ldapuser]引发异常[请求处理失败;嵌套的异常是org.springframework.ldap.CommunicationException:abc.com:636;嵌套异常是javax.naming.CommunicationException:abc.com:636 [根本异常是java.net.SocketException:java.security.NoSuchAlgorithmException:构造实现时出错(算法:默认,提供程序:SunJSSE,类:sun.security.ssl。 SSLContextImpl $ DefaultSSLContext)]]的根本原因

     

java.io.IOException:无效的密钥库格式       在sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:658)〜[na:1.8.0_171]       在sun.security.provider.JavaKeyStore $ JKS.engineLoad(JavaKeyStore.java:56)〜[na:1.8.0_171]       在sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224)〜[na:1.8.0_171]       在sun.security.provider.JavaKeyStore $ DualFormatJKS.engineLoad(JavaKeyStore.java:70)〜[na:1.8.0_171]       在java.security.KeyStore.load(KeyStore.java:1445)〜[na:1.8.0_171]       在sun.security.ssl.TrustManagerFactoryImpl.getCacertsKeyStore(TrustManagerFactoryImpl.java:226)〜[na:1.8.0_171]       在sun.security.ssl.SSLContextImpl $ DefaultManagersHolder.getTrustManagers(SSLContextImpl.java:771)〜[na:1.8.0_171]       在sun.security.ssl.SSLContextImpl $ DefaultManagersHolder。(SSLContextImpl.java:748)〜[na:1.8.0_171]       在sun.security.ssl.SSLContextImpl $ DefaultSSLContext。(SSLContextImpl.java:913)〜[na:1.8.0_171]       在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)〜[na:1.8.0_171]       在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)〜[na:1.8.0_171]       在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)〜[na:1.8.0_171]       在java.lang.reflect.Constructor.newInstance(Constructor.java:423)〜[na:1.8.0_171]       在java.security.Provider $ Service.newInstance(Provider.java:1595)〜[na:1.8.0_171]       在sun.security.jca.GetInstance.getInstance(GetInstance.java:236)〜[na:1.8.0_171]       在sun.security.jca.GetInstance.getInstance(GetInstance.java:164)〜[na:1.8.0_171]       在javax.net.ssl.SSLContext.getInstance(SSLContext.java:156)〜[na:1.8.0_171]       在javax.net.ssl.SSLContext.getDefault(SSLContext.java:96)〜[na:1.8.0_171]       在javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:122)〜[na:1.8.0_171]       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[na:1.8.0_171]       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_171]       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_171]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_171]       在com.sun.jndi.ldap.Connection.createSocket(Connection.java:284)〜[na:1.8.0_171]       在com.sun.jndi.ldap.Connection。(Connection.java:203)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapClient。(LdapClient.java:137)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1615)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2749)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapCtx。(LdapCtx.java:319)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:192)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:210)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:153)〜[na:1.8.0_171]       在com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:83)〜[na:1.8.0_171]       在javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)〜[na:1.8.0_171]       在javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)〜[na:1.8.0_171]

我真的不认为这与证书有关,因为该证书是公司给我的,并且可以为其他人使用。不知道我的配置是否做错了。

谢谢

0 个答案:

没有答案
相关问题