【问题标题】:java get Active Directory RootDSEjava 获取 Active Directory RootDSE
【发布时间】:2018-08-19 16:13:30
【问题描述】:

我正在尝试使用 java 获取 Active Directory rootDSE。到目前为止,这是我尝试过的:

public class RootDSE {

    public DirContext context;
    public Attributes attributes;
    public NamingEnumeration enumerations;

    public RootDSE()
    {
        try {
            this.context = new InitialDirContext();
            this.attributes = context.getAttributes(
                "ldap://192.168.122.115", new String[]{"*"}
            );
            this.enumerations = this.attributes.getIDs();
            while(this.enumerations != null && this.enumerations.hasMore()) {
                String nextAttribute = (String)this.enumerations.next();
                System.out.println(attributes.get(nextAttribute));
            }
            context.close();
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}

(我评论了imports 以使阅读更容易。 我通过创建 RootDSE 对象来启动代码:

RootDSE dse = new RootDSE();
javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C090728, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580

我已经执行了经过身份验证的 ldap 请求,因此授予了网络连接和对目录服务的访问权限。此外,rootDSE 请求应该是匿名的?不需要执行“successful bind”来获取它吗?

谁能解释我为什么会收到这个错误,以及如何解决它?

非常感谢!

【问题讨论】:

标签: java active-directory


【解决方案1】:

这是一个特定于 AD 的问题,并且与 Java 的 JNDI LDAP 实现发生冲突,默认情况下假设 LDAPv3 服务器支持 RFC3296,但 AD 不支持。这会导致来自 AD 的报告(可能不是那么直观)错误消息。

解决方案:根据this answer,您需要在上下文中设置Context.REFERRAL 属性。

因此,像这样初始化你的上下文:

Properties props = new Properties();
props.setProperty(Context.REFERRAL, "throw");  // any other allowed value than the default ('ignore') will do
this.context = new InitialDirContext(props);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-14
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多