【问题标题】:How to retrieve all LDAP attributes definition on LDAP database?如何检索 LDAP 数据库上的所有 LDAP 属性定义?
【发布时间】:2021-10-19 12:04:36
【问题描述】:

我正在使用 ldap 并希望检索在 Ldap 服务器上定义的所有 Ldap 属性字段。我只需要属性字段列表而不是值。结果应该是这样的列表:

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

有没有办法做到这一点?

【问题讨论】:

  • 是的,有办法,我们的 IT 使用 java API 以某种方式做到这一点。

标签: java ldap


【解决方案1】:

您可以使用 getSchema() 并获取 LDAP 的树根 Schema

DirContext schema = yourLDAPctx.getSchema("");

那么你也可以从Schema中选择你想要的类的所有属性

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

你可以参考这个链接。它会告诉你更详细的

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

【讨论】:

    【解决方案2】:

    根据 LDAP 服务器实现,包含所有定义的属性(和 ObjectClasses)的 LDAP 模式可以使用如下所述的几种方法获得:http://ldapwiki.com/wiki/LDAP%20Query%20For%20Schema

    如果你只想要属性。尝试类似:

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

    【讨论】:

      【解决方案3】:

      建议不要让 LDAP 为您返回所有属性,而是通过 SearchControl 设置您感兴趣的属性数组。

      【讨论】:

      • 我们如何确保 ldap 服务器具有我们正在寻找的确切属性?如果有多个ldap服务器并且属性不一样?
      • 您可以维护您感兴趣的每个 LDAP 服务器的属性列表并进行相应设置。
      • 不是所要求的。
      【解决方案4】:

      您可以枚举特定对象的所有属性(即您的情况下的用户)并将它们添加到列表中

      // 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()); 
      }
      

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

      【讨论】:

      • 不是所要求的。
      猜你喜欢
      • 2011-10-04
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      相关资源
      最近更新 更多