Java CertificateException 没有与 IP 地址匹配的主题备用名称(尝试在 AD 中创建用户)



问题是当我尝试使用 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");

最新更新