使用用户组进行Ldap模板身份验证

时间:2018-02-14 19:18:51

标签: spring ldap

我坚持使用spring ldaptemplate身份验证方法,在使用组字符串时返回零计数,字符串如下所示。

CN = Jirra-Acdolite-DG,OU = Jira Security Group,OU = Apps Security Group,OU = Security Groups,OU = Global,OU = BT,DC = barcadero,DC = com

我们正在尝试使用以下代码的ldap用户组。

    try {
        LdapContextSource ctxSrc = new LdapContextSource();

        ctxSrc.setUrl(url);
        // ctxSrc.setBase(base);
        ctxSrc.setUserDn(ManagerDn);
        ctxSrc.setPassword(ManagerPassword);

        ctxSrc.setReferral("follow");

        ctxSrc.afterPropertiesSet();

        LdapTemplate ldapTemplate = new LdapTemplate(ctxSrc);

        System.out.println("50");
        ldapTemplate.afterPropertiesSet();
        AndFilter andfilter = new AndFilter().and(new EqualsFilter("objectCategory", "person"))
                .and(new EqualsFilter("objectClass", "user")).and(new EqualsFilter(SearchAttributes, userDn))
                .and(new EqualsFilter("memberOf:1.2.840.113556.1.4.1941:",
                        "CN=Jirra-Acdolite-DG,OU=Jira Security Group,OU=Apps Security Group,OU=Security Groups,OU=Global,OU=BT,DC=barcadero,DC=com

&#34));             的System.out.println(andfilter);             if(!ldapTemplate.authenticate(base,andfilter.encode(),password,new AuthenticationErrorCallback(){                 public void execute(Exception e){                     的System.out.println("例外&#34);                 }             })){                 的System.out.println("假\ n&#34);             } else {                 的System.out.println("成功&#34);             }

但我们总是得到False值和Group字符串。如有任何帮助,谢谢。

如下所示的错误消息。

2018年2月15日上午12:32:52 org.springframework.ldap.core.LdapTemplate authenticate 信息:找不到搜索结果,基数: CN = Jirra-Acdolite-DG,OU = Jira Security Group,OU = Apps Security Group,OU =安全组,OU = Global,OU = BT,DC = barcadero,DC = com

1 个答案:

答案 0 :(得分:0)

如果您尝试对特定群组下的用户进行身份验证,请尝试让该群组下的所有用户进行搜索(我这样做)

AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("memberOf:1.2.840.113556.1.4.1941:", groupDN));
filter.and(new EqualsFilter("objectClass", "user"));

return ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), new ContractAttributeMapperJSON());
}
相关问题