Sha256: 07a5d7a9424234b4fe76be81367020eef6aae1f358e4429c8c3ea715756fbc98

Contents?: true

Size: 959 Bytes

Versions: 5

Compression:

Stored size: 959 Bytes

Contents

module GitHub
  class Ldap
    module Filter
      # Filter to get the configured groups in the ldap server.
      # Takes the list of the group names and generate a filter for the groups
      # with cn that match and also include members:
      #
      # group_names: is an array of group CNs.
      # user_dn: is an optional member to scope the search to.
      #
      # Returns a Net::LDAP::Filter.
      def group_filter(group_names, user_dn = nil)
        or_filters = group_names.map {|g| Net::LDAP::Filter.eq("cn", g)}.reduce(:|)
        member_filter(user_dn) & or_filters
      end

      # Filter to check a group membership.
      #
      # user_dn: is an optional user_dn to scope the search to.
      #
      # Returns a Net::LDAP::Filter.
      def member_filter(user_dn = nil)
        if user_dn
          Net::LDAP::Filter.eq("member", user_dn)
        else
          Net::LDAP::Filter.pres("member")
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
github-ldap-1.0.15 lib/github/ldap/filter.rb
github-ldap-1.0.13 lib/github/ldap/filter.rb
github-ldap-1.0.12 lib/github/ldap/filter.rb
github-ldap-1.0.11 lib/github/ldap/filter.rb
github-ldap-1.0.10 lib/github/ldap/filter.rb