使用Java进行LDAP身份验证,需要解释

使用Java进行LDAP身份验证,需要解释,java,authentication,ldap,Java,Authentication,Ldap,如果您能向我解释一下我不太理解的以下代码,我将不胜感激: 过滤器字段中的(&(cn=*)({0}={1}))是什么意思 我知道cn意味着搜索cn属性,然后将结果添加到({0}={1}) ({0}={1})的含义是什么 代码如下: try { // Create initial context ctx = new InitialDirContext(env); Attributes matchAttrs = new BasicAttributes(true);

如果您能向我解释一下我不太理解的以下代码,我将不胜感激:

过滤器字段中的
(&(cn=*)({0}={1}))
是什么意思

我知道
cn
意味着搜索
cn
属性,然后将结果添加到
({0}={1})

({0}={1})
的含义是什么

代码如下:

try {
     // Create initial context
     ctx = new InitialDirContext(env);
     Attributes matchAttrs = new BasicAttributes(true);
     matchAttrs.put(new BasicAttribute(ldap_id_field, netid));

     String attlist[] = {ldap_email_field, ldap_givenname_field, 
            ldap_surname_field, ldap_phone_field};

    // look up attributes
      try {
      SearchControls ctls = new SearchControls();
     ctls.setReturningAttributes(attlist);
     NamingEnumeration answer = 
     ctx.search(ldap_search_context, "(&(cn=*)({0}={1}))", new Object[]  {ldap_id_field,netid},ctls);
     }
...

在我看来这是不对的。过滤器所做的只是分别在ldap_id_字段和netid中查找具有任何CN且与指定为搜索参数的属性名称/值对匹配的条目。没有“添加”:表示两个筛选器表达式必须匹配。

是的,我看你是对的。因此,如果ldap_id_字段是say uid,netid是user123,那么搜索将查找属性cn=*并匹配uid和user123的{0}={1}(即uid=user123)。这对吗?我现在知道了。塔克斯。你帮我理解了。接受你的回答