简体   繁体   English

如何检索 LDAP 数据库上的所有 LDAP 属性定义?

[英]How to retrieve all LDAP attributes definition on LDAP database?

I'm working with ldap and want to retrieve all Ldap Attribute fields that defined on Ldap server.我正在使用 ldap 并希望检索在 Ldap 服务器上定义的所有 Ldap 属性字段。 I just need list of attribute field only not the value.我只需要属性字段列表而不是值。 The result should be a list like this:结果应该是这样的列表:

['mailNickname',
 'publicDelegatesBL',
 'logonCount',
 'cn',
 'countryCode',
 'dSCorePropagationData',
 'objectClass',
 # ...
'telephoneNumber',
'physicalDeliveryOfficeName',
'name',
'memberOf',
'codePage',
'userAccountControl',
'msExchMDBRulesQuota',
'lastLogon',
'protocolSettings',
'uSNChanged',
'sn',
'msExchVersion',
'mDBUseDefaults',
'givenName',
'msExchMailboxGuid',
'lastLogoff']

Is there way to do this?有没有办法做到这一点?

与其让 LDAP 为您返回所有属性,不如通过 SearchControl 设置您感兴趣的属性数组。

You can enumerate all attributes of specific object (ie user in your case) and add them into a list as您可以枚举特定对象(即您的案例中的用户)的所有属性并将它们添加到列表中

// Get all the attributes of named object
Attributes attrs = ctx.getAttributes("cn=User1,ou=People");
List<String> l = new ArrayList<String>();
for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {
    Attribute attr = (Attribute) ae.next();
    l.add(attr.getID()); 
}

Example: http://www.java2s.com/Code/Java/JNDI-LDAP/howtoretrieveallattributesofanamedobject.htm示例: http : //www.java2s.com/Code/Java/JNDI-LDAP/howtoretrieveallattributesofanamedobject.htm

Depending on the LDAP Server Implementation, the LDAP schema, which contains all the Attributes (and ObjectClasses) defined can be obtained using several methods as described at: http://ldapwiki.com/wiki/LDAP%20Query%20For%20Schema根据 LDAP 服务器实现,可以使用以下几种方法获取包含定义的所有属性(和对象类)的 LDAP 架构: http : //ldapwiki.com/wiki/LDAP%20Query%20For%20Schema

If you only wanted the Attributes.如果你只想要属性。 Try something like:尝试类似:

ldapsearch -h yourLDAPDNS  -b "cn=schema" -s base -D cn=admin,ou=...,dc=yourdomain,dc=com -w secretpassword "(objectclass=*)" attributeTypes 

You can use the getSchema() and get the Schema of tree root of your LDAP您可以使用 getSchema() 并获取 LDAP 树根的架构

DirContext schema = yourLDAPctx.getSchema("");

then you can also choose which all attributes of a class you want from the Schema然后您还可以从架构中选择您想要的类的所有属性

DirContext personSchema = (DirContext)schema.lookup("ClassDefinition/<name of the objectClass>");

You can refer this link for it..It will tell you in more detail你可以参考这个链接..它会告诉你更详细的

http://www.cs.binghamton.edu/~steflik/cs328/jndi/tutorial/ldap/schema/object.html http://www.cs.binghamton.edu/~steflik/cs328/jndi/tutorial/ldap/schema/object.html

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

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