问题是,当我尝试使用Java在Active Directory(AD)中创建用户时,出现此异常,但是当我想从现有用户中获取值时,就没有问题。而且我需要一种解决方案,使它不仅可以在我的计算机上本地运行,而且可以在全球范围内运行(我不想强迫其他人进行相同的配置)。

我尝试导入/导出ssl证书,但是有2个问题。第一个是没有解决问题,第二个是即使解决了问题,这也只能是本地解决方案。

public void createUser(String username, String surname, String givenName) throws NamingException {

    //the exception is right here when I'm trying to initialize
    DirContext context = new InitialDirContext(ldapEnv);

    String distinguishedName = "cn=" + username + BASE;
    Attributes newAttributes = new BasicAttributes(true);
    Attribute objClasses = new BasicAttribute("objectclass");
    objClasses.add("top");
    objClasses.add("person");
    objClasses.add("organizationalperson");
    objClasses.add("user");
    newAttributes.put(objClasses);
    newAttributes.put(new BasicAttribute("sAMAccountName", username));
    newAttributes.put(new BasicAttribute("cn", username));
    newAttributes.put(new BasicAttribute("sn", surname));
    newAttributes.put(new BasicAttribute("givenName", givenName));
    newAttributes.put(new BasicAttribute("displayName", givenName + " " + surname));
    System.out.println("Creating: " + username);
    context.createSubcontext(distinguishedName, newAttributes);
}

最佳答案

没有与IP地址匹配的使用者替代名称


这个问题听起来像是适用于任何SSL连接,而不仅仅是LDAP。

SSL证书具有一个主域名和“主题备用名称”,这是该证书可用于的其他域名的列表。当启动SSL连接时,计算机将读取证书,查看允许使用该证书的所有域名,并检查其中是否与您用来发起连接的域名匹配。这是为了确保您连接到正确的服务器,因为这是安全通信(不仅仅是加密)工作的一部分。

问题是:如果您使用的是IP地址,则如下所示:

ldapEnv.put(Context.PROVIDER_URL, "ldaps://192.168.1.1:636");


那么SSL握手肯定会失败,因为SSL证书不会颁发给IP地址。您必须使用SSL证书中列出的域名之一:

ldapEnv.put(Context.PROVIDER_URL, "ldaps://example.com:636");

关于java - Java CertificateException没有与IP地址匹配的使用者替代名称(试图在AD中创建用户),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58504812/

10-14 12:09
查看更多