Package: bropen.toolkit.utils.security

[Groovy] Class LdapUtils

    • Methods Summary

        Methods 
        Type Name and description
        static org.springframework.ldap.core.LdapTemplate getLdapTemplate(String contextName)
        根据配置的 ldap 上下文名称,获得对应的 LdapTemplate
        static Map lookup(String contextName, Object dn, List<String> attributes)
        按照 dn 查找对象,并返回所需的属性
        static Object lookup(String contextName, Object dn, Closure mapper)
        按照 dn 查找对象,并返回闭包处理的结果
        static Object lookup(String contextName, Object dn, List<String> attributes, Closure mapper)
        按照dn查找对象,并返回闭包处理的结果
        static List<Map> search(String contextName, Object base, String filter, List<String> attributes, Map options = [:])
        按照dn查找对象,并返回所需的属性
        static List search(String contextName, Object base, String filter, Closure mapper, Map options = [:])
        根据过滤器搜索对象,使用闭包处理每个对象后返回
        static List search(String contextName, Object base, String filter, List<String> attributes, Closure mapper, Map options = [:])
        根据过滤器搜索对象,使用闭包处理每个对象后返回
    • Inherited Methods Summary

        Inherited Methods 
        Methods inherited from class Name
        class Object Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll()
    • Method Detail

      • static org.springframework.ldap.core.LdapTemplate getLdapTemplate(String contextName)

        根据配置的 ldap 上下文名称,获得对应的 LdapTemplate

        Parameters:
        contextName

      • static Map lookup(String contextName, Object dn, List<String> attributes)

        按照 dn 查找对象,并返回所需的属性

        Parameters:
        contextName - 配置中 ldap.context 中对应的上下文的名称,不能为空
        dn - 要查询对象的 dn(String 或 javax.naming.Name 对象,如 DistinguishedName),如果上下文中配置了 base,则实际查找的 dn 为:"dn, base"
        attributes - 需要查询、返回的属性列表,不能为空,如果属性名称有后缀“[]”,则表示返回数组,否则只返回第一个值

      • static Object lookup(String contextName, Object dn, Closure mapper)

        按照 dn 查找对象,并返回闭包处理的结果

        例:根据默认的 ldap.context 配置,查找 dn 为 "cn=test2,${ldap.context.base}" 的对象,并返回其 cn 属性。
        LdapUtils.lookup("", "cn=test2", {ctx-> return ctx.getStringAttribute("cn") })

        Parameters:
        contextName
        dn
        mapper - 用来转换查询结果对象的闭包,可接收参数 DirContextOperations ctx,有一系列取属性的方法,常用的如 getStringAttribute、getStringAttributes

      • static Object lookup(String contextName, Object dn, List<String> attributes, Closure mapper)

        按照dn查找对象,并返回闭包处理的结果

        Parameters:
        attributes - 查询结果仅返回对应属性,以供 mapper 使用,避免查询出所有属性后再处理,类似于 sql 的 "select xxx,xxx from..."

      • static List<Map> search(String contextName, Object base, String filter, List<String> attributes, Map options = [:])

        按照dn查找对象,并返回所需的属性

        Parameters:
        base - 查询的 baseDn
        filter - 过滤条件,如 "objectclass=person"
        attributes - 需要查询、返回的属性列表,不能为空,如果属性名称有后缀 “[]”,则表示返回数组,否则只返回第一个值
        options - 主要是设置 SearchControls 中的参数, 包括 searchScope(0=OBJECT_SCOPE、1=ONELEVEL_SCOPE、2=SUBTREE_SCOPE)、countLimit、timeLimit、derefLink,默认值分别为2、0、0、false。

      • static List search(String contextName, Object base, String filter, Closure mapper, Map options = [:])

        根据过滤器搜索对象,使用闭包处理每个对象后返回

        例:LdapUtils.search("", "", "(objectclass=person)", {ctx-> return ctx.getStringAttribute("cn")})

        params:
        options
        Parameters:
        contextName
        base
        filter
        mapper

      • static List search(String contextName, Object base, String filter, List<String> attributes, Closure mapper, Map options = [:])

        根据过滤器搜索对象,使用闭包处理每个对象后返回

        params:
        options
        Parameters:
        contextName
        base
        filter
        attributes
        mapper