简体   繁体   English

LDAP子查询以从CN获取SamAccountName

[英]LDAP Sub Query to fetch SamAccountName from CN

Currently I have this query as mentioned below which returns all users but each user has a parameter called manager which returns 目前,我有如下所述的查询,该查询返回所有用户,但是每个用户都有一个称为manager的参数,该参数返回

"CN=Peder Ellingsen,OU=Users,OU=NO,OU=Countries,DC=xds,DC=xxx,DC=com"

Need the samAccountName instead of the CN above, need help with LDAP Subquery which can help me to get the samAccountName directly by modifying the query mentioned below 需要samAccountName而不是上面的CN,需要LDAP子查询的帮助,可以通过修改下面提到的查询来帮助我直接获取samAccountName

Wanted to avoid double hits to LDAP server just to get the samAccountName . 希望避免仅获取samAccountName对LDAP服务器造成双重打击。

(&(objectCategory=person)(objectClass=user)(memberof=cn=MyCompass_NO,OU=Groups,OU=Common,OU=Applications,DC=xds,DC=xxx,DC=com))

Assuming that your filter is what you have written above try this 假设您的过滤器就是您上面编写的,请尝试以下操作

  (&(objectCategory=person)(objectClass=user)(sAMAccountName=*)(memberof=cn=MyCompass_NO,OU=Groups,OU=Common,OU=Applications,DC=xds,DC=xxx,DC=com))

This will give first parameter as SamAccountName=username 这将使第一个参数为SamAccountName = username

if you want only Samaccountname printed use this 如果您只想打印Samaccountname,请使用此

    Attributes attrs = result.getAttributes();
    Attribute attr = attrs.get(sAMAccountName);
    if(attr!=null)
    {
    NamingEnumeration e = attr.getAll();

    while (e.hasMore()) {
        String value = (String) e.next();
        System.out.println(value);
    }}

if you want to list down all the Samaccountname then use this 如果要列出所有Samaccount名称,请使用此名称

 (&(objectCategory=person)(sAMAccountName=*)) 

Filter by whatever you want, and get sAMAccountName, here is how I did in our servers: 按您想要的内容进行过滤,并获得sAMAccountName,这是我在服务器中所做的工作:

ldapsearch -h host -p port -b dc=organization.com -W -D cn=admin,dc=organization.com '(&(objectclass=person)(uid=someuid))' sAMAccountName

the interesting part is the filter 有趣的部分是过滤器

'(&(objectclass=person)(uid=someuid))' sAMAccountName

where you filter by objectclass and uid, and get sAMAccountName attribute. 您可以在其中按objectclass和uid进行过滤,并获取sAMAccountName属性。

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

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