java - 使用 GSSAPI 连接到 ldap。服务主体错误

标签 java ldap kerberos jaas gssapi

我正在尝试使用 SASL 连接到 ldap 服务器。我使用 url ldaps://ldap.example.com 进行连接,但服务器主机名是 host.example.comldap.example.comhost.example.com 的 cname。我的程序正在尝试获取 ldap/ldap.example.com 的服务票证,而不是执行反向 DNS 请求并获取 ldap/host.example.com 的票证。当我使用 ldap://host.example.com 时一切正常,但我更喜欢使用服务 CNAME。

这是我创建连接工厂的代码:

public DefaultConnectionFactory connectionFactory(){
    return new DefaultConnectionFactory(connectionConfig());
}

private ConnectionConfig connectionConfig(){
    final SaslConfig saslConfig = new SaslConfig();
    saslConfig.setMechanism(Mechanism.GSSAPI);

    final BindConnectionInitializer connectionInitializer = new BindConnectionInitializer();
    connectionInitializer.setBindSaslConfig(saslConfig);

    ConnectionConfig connConfig = new ConnectionConfig("ldaps://ldap.example.com");
    connConfig.setConnectionInitializer(connectionInitializer);
    return connConfig;
}

和 jaas.config:

com.sun.security.jgss.initiate {
  com.sun.security.auth.module.Krb5LoginModule required
    doNotPrompt=true
    keyTab="/etc/ldap.keytab"
    principal="ldap@EXAMPLE.COM"
    storeKey=true
    useKeyTab=true
    debug=true
    ;
};

有什么办法可以改变这种行为吗?

最佳答案

您应该请求一个新证书,其中 ldap.example.com 作为使用者名称,并使用 host.example.com 作为使用者备用名称。证书协商在 Kerberos 之前处理。

还有一些建议:

  1. 所有 SPN 均应在您的 KDC 中定义:

LDAP/ldap.example.com

LDAP/host.example.com

  • 这两条 A 记录都应在 DNS 中设置。 Avoid use of CNAMES, while it might be OK at any given time, different browser versions and future updates could cause inconsistent behavior :
  • ldap.example.com

    host.example.com

  • jaas.config中的校长并且 key 表应该匹配。你有:
  • principal="ldap@EXAMPLE.COM"

    我建议应该是:principal=“ldap/host.example.com“;

  • 最后,应将 ldap/host.example.com 定义为 key 表中的 SPN。如果不是,则可能没问题,只要 (1) 将其添加为 key 表中相关的附加 SPN:How do you add multiple SPNs to the same keytab file for Spnego or Kerberos Configuration?或 (2) 参见Setspn如果您使用的是 Active Directory 并且您的应用程序服务器支持它。
  • 请参阅 GSSAPI 的进一步阅读.

    关于java - 使用 GSSAPI 连接到 ldap。服务主体错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42317943/

    相关文章:

    java - 用 3 种颜色给三角形上色

    php - GMail LDAP 身份验证?

    java - 不明白这个 Java LDAP 错误

    linux - 预认证失败 : Password read interrupted while getting initial credentials

    java - KerberosAuthenticationProvider 与 KerberosServiceAuthenticationProvider

    java - 动态创建和读取java类

    java - 从 JPA/EJB3 持久性上下文中分离实体

    java - 通过 XPath 仅选择叶 SPAN 元素

    c# - 无法在 C# 中检索 Active Directory 用户

    hadoop - 在 oozie Java Action 中传递 HBase 凭据