简体   繁体   English

如何访问此 LDAP object 的属性?

[英]How can I access the attributes of this LDAP object?

I'm hoping someone can help me understand how to work with the object returned by a call to DirContext.lookup.我希望有人可以帮助我了解如何使用调用 DirContext.lookup 返回的 object。

The following code snippet works and returns an object.以下代码片段有效并返回 object。 I just can't figure out how to get the attributes from the object.我只是不知道如何从 object 中获取属性。

javax.naming.directory.DirContext ctx =
    javax.naming.directory.getContext(false);
Object o = ctx.lookup(rdn); 

Any help would be much appreciated.任何帮助将非常感激。

Attributes attrs = ctx.getAttributes(dn);属性 attrs = ctx.getAttributes(dn); will retrieve the user attributes assuming the entry asking for the arrtibute values has proper rights.假设请求 arrtibute 值的条目具有适当的权限,将检索用户属性。

However, best practice is you only query for the attributes you need.但是,最佳实践是您只查询您需要的属性。

If you wish to see all attributes, you should query the objectclass attribute values and then query the schema to obtain "all" the attributes assigned and decide which attributes you need to retrieve.如果您希望查看所有属性,您应该查询 objectclass 属性值,然后查询模式以获取“所有”分配的属性并决定您需要检索哪些属性。

-jim -吉姆

You should know what object you are expecting to receive from the lookup() , explicitly cast to it, and then do whatever you want with it.您应该知道您希望从lookup()收到什么 object ,显式转换为它,然后用它做任何你想做的事情。

In the end you should have something like this:最后你应该有这样的东西:

InitialContext iCtx = new InitialContext();
// load the iCtx with environment variables if necessary
Object o = iCtx.lookup("objectNameOrString");
ExpectedObjectType eot = (ExpectedObjectType) o;
eot.doWhatever();

In an LDAP directory, you would do:在 LDAP 目录中,您将执行以下操作:

Attributes attrs = ctx.getAttributes(dn);属性 attrs = ctx.getAttributes(dn);

To obtain the attributes of the object获取object的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM