连接活动目录的支持SSL的(LDAPS)(Connect active directory with

2019-07-29 09:35发布

我试图与支持SSL的Active Directory的连接。

我想从以下网站中的步骤。

http://confluence.atlassian.com/display/CROWD/Configuring+an+SSL+Certificate+for+Microsoft+Active+Directory

当我尝试从Active Directory中的Java代码连接它给了以下错误。

Exception in thread "main" javax.naming.CommunicationException: simple bind fail
ed: 172.16.12.4:636 [Root exception is java.net.SocketException: Connection rese
t]
        at com.sun.jndi.ldap.LdapClient.authenticate(Unknown Source)
        at com.sun.jndi.ldap.LdapCtx.connect(Unknown Source)
        at com.sun.jndi.ldap.LdapCtx.<init>(Unknown Source)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(Unknown Source)
        at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(Unknown Source)
        at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(Unknown Source)
        at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(Unknown Source)
        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
        at javax.naming.InitialContext.init(Unknown Source)
        at javax.naming.InitialContext.<init>(Unknown Source)
        at javax.naming.directory.InitialDirContext.<init>(Unknown Source)
        at ConnectActiveDirectory.main(ConnectActiveDirectory.java:39)
Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source)
        at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)

        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.waitForClose(Unknown Sourc
e)
        at com.sun.net.ssl.internal.ssl.HandshakeOutStream.flush(Unknown Source)

        at com.sun.net.ssl.internal.ssl.Handshaker.kickstart(Unknown Source)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.kickstartHandshake(Unknown
 Source)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Un
known Source)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(Unknown Source
)
        at com.sun.net.ssl.internal.ssl.AppOutputStream.write(Unknown Source)
        at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
        at java.io.BufferedOutputStream.flush(Unknown Source)
        at com.sun.jndi.ldap.Connection.writeRequest(Unknown Source)
        at com.sun.jndi.ldap.Connection.writeRequest(Unknown Source)
        at com.sun.jndi.ldap.LdapClient.ldapBind(Unknown Source)
        ... 13 more

那现在用的就是代码

import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;

public class ConnectActiveDirectory {

    public static void main(String[] args) throws NamingException {
        Hashtable env = new Hashtable();
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL,"Administrator@mysite.com");
        env.put(Context.SECURITY_CREDENTIALS, "password");
        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldaps://172.16.12.4:636/cn=Users,dc=mysite,dc=com");
        try{
            java.io.InputStream in = new java.io.FileInputStream("C:\\client.crt");
            java.security.cert.Certificate c = java.security.cert.CertificateFactory.getInstance("X.509").generateCertificate(in);
            java.security.KeyStore ks = java.security.KeyStore.getInstance("JKS");
            ks.load(null);
            if (!ks.containsAlias("alias ldap")) {
                ks.setCertificateEntry("alias ldap", c);
            }
            java.io.OutputStream out = new java.io.FileOutputStream("C:\\keystorefile.jks");
            char[] kspass = "changeit".toCharArray();
            ks.store(out, kspass);
            out.close();        
        }catch(Exception e){
            e.printStackTrace();
        }
        System.setProperty("javax.net.ssl.trustStore", "C:\\keystorefile.jks");
        DirContext ctx = new InitialDirContext(env);
        NamingEnumeration enm = ctx.list("");
        while (enm.hasMore()) {
            System.out.println(enm.next());
        }
        ctx.close();
    }
}

确实是在做什么错误?

我在哪里可以得到很好的教程做与Active Directory SSL连接?

确实http://confluence.atlassian.com/display/CROWD/Configuring+an+SSL+Certificate+for+Microsoft+Active+Directory网站有正确的步骤来创建和使用SSL连接的Active Directory?

可以在任何请帮助我。

Answer 1:

我有一个类似的问题,我的AD域更名后。 重新安装证书服务后,您需要删除并重新发出发给你的域控制器证书。 脚步:

  1. 打开MMC
  2. 添加管理单元>证书>计算机>本地计算机
  3. 导航到个人>证书
  4. 删除发给本机的任何旧证书(在我的情况,这是由旧CA颁发)
  5. 右键单击证书文件夹,单击申请新证书。
  6. 按照以下步骤发出新的证书到您的域控制器。
  7. 重新启动(不知道这是必要的,但我重新启动它的工作之前)


Answer 2:

我不得不使用Atlassian的人群,并通过SSL的Active Directory相同的错误消息。 它并不适用于这个特定的问题,但是当我试图找出发生了什么事这个线程是第一次谷歌搜索命中,所以我将它写下来这里。

在我来说,我没有先测试SSL后又改为SSL。 原来我忘了改在人群中连接器的设置使用的协议。

之前:LDAP://:389后:LDAPS://:636

不小心使用LDAP://:636给我的“连接复位”的错误。



文章来源: Connect active directory with the support of ssl (ldaps)