【问题标题】:Ldap template authentication with user group使用用户组的 LDAP 模板身份验证
【发布时间】:2018-07-25 11:12:33
【问题描述】:

我坚持使用 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

")); System.out.println(andfilter); if (!ldapTemplate.authenticate(base, andfilter.encode(), password, new AuthenticationErrorCallback() { 公共无效执行(异常e){ System.out.println("异常"); } })) { System.out.println("False\n"); } 别的 { System.out.println("成功"); }

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

如下所示的错误信息。

2018 年 2 月 15 日 12:32:52 AM org.springframework.ldap.core.LdapTemplate 认证 信息:未找到搜索结果,基础: CN=Jirra-Acdolite-DG,OU=Jira Security Group,OU=Apps Security Group,OU=Security Groups,OU=Global,OU=BT,DC=barcadero,DC=com

【问题讨论】:

    标签: spring ldap


    【解决方案1】:

    如果您尝试对特定组下的用户进行身份验证,请尝试获取该组下的所有用户并在其中进行搜索(我就是这样做的)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-04
      • 2012-11-28
      • 1970-01-01
      • 2012-09-01
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多