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), Object#wait(long, int), 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:
        contextName
        dn
        attributes - 查询结果仅返回对应属性,以供mapper使用,避免查询出所有属性后再处理,类似于sql的 "select xxx,xxx from..."
        mapper

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

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

        Parameters:
        contextName
        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