Class: GitHub::Ldap::PosixGroup

Inherits:
Group
  • Object
show all
Defined in:
lib/github/ldap/posix_group.rb

Overview

This class represents a POSIX group.

To get a POSIX group, you’ll need to create a ‘Ldap` object and then call the method `group`. The parameter for `group` must be a dn to a group entry with `posixGroup` amongs the values for the attribute `objectClass`.

For example:

domain = GitHub::Ldap.new(options).group(“cn=enterprise,dc=github,dc=com”)

Constant Summary

Constants inherited from Group

Group::GROUP_CLASS_NAMES

Constants included from Filter

Filter::ALL_GROUPS_FILTER, Filter::MEMBERSHIP_NAMES

Instance Attribute Summary

Attributes inherited from Group

#entry, #ldap

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Group

#group?, group?, #group_and_member_entries, #groups_and_members, #initialize, #load_cache, #loop_cached_groups, #member_entries, #member_names

Methods included from Filter

#all_members_by_uid, #group_contains_filter, #group_filter, #login_filter, #member_filter, #members_of_group, #posix_member_filter, #subgroups_of_group

Constructor Details

This class inherits a constructor from GitHub::Ldap::Group

Class Method Details

.valid?(entry) ⇒ Boolean

Public - Check if an ldap entry is a valid posixGroup.

entry: is the ldap entry to check.

Returns true if the entry includes the objectClass ‘posixGroup`.

Returns:

  • (Boolean)


18
19
20
# File 'lib/github/ldap/posix_group.rb', line 18

def self.valid?(entry)
  entry[:objectClass].any? {|oc| oc.downcase == 'posixgroup'}
end

Instance Method Details

#combined_group?Boolean

Internal - Check if this posix group also includes ‘member` and `uniqueMember` entries.

Returns true if any of the membership names is include in this group entry.

Returns:

  • (Boolean)


65
66
67
# File 'lib/github/ldap/posix_group.rb', line 65

def combined_group?
  MEMBERSHIP_NAMES.any? {|name| !entry[name].empty? }
end

#is_member?(user_entry) ⇒ Boolean

Public - Overrides Group#is_member?

Chech if the user entry uid exists in the collection of ‘memberUid`. It calls `super` if the group entry includes `member` or `uniqueMember`.

Return true if the user is member if this group or any subgroup.

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/github/ldap/posix_group.rb', line 55

def is_member?(user_entry)
  entry_uids = user_entry[ldap.uid]
  return true if !(entry_uids & entry[:memberUid]).empty?

  super if combined_group?
end

#membersObject

Public - Overrides Group#members

Search the entries corresponding to the members in the ‘memberUid` attribute. It calls `super` if the group entry includes `member` or `uniqueMember`.

Returns an array with the members of this group and its submembers if there is any.



28
29
30
31
32
33
34
35
36
# File 'lib/github/ldap/posix_group.rb', line 28

def members
  return @all_posix_members if @all_posix_members

  @all_posix_members = search_members_by_uids
  @all_posix_members.concat super if combined_group?

  @all_posix_members.uniq! {|m| m.dn }
  @all_posix_members
end

#search_members_by_uidsObject

Internal - Search all members by uid.

Return an array of user entries.



72
73
74
75
76
77
78
# File 'lib/github/ldap/posix_group.rb', line 72

def search_members_by_uids
  member_uids = entry[:memberUid]
  return [] if member_uids.empty?

  filter = all_members_by_uid(member_uids, ldap.uid)
  ldap.search(filter: filter)
end

#subgroupsObject

Public - Overrides Group#subgroups

Prevent to call super when the group entry does not include ‘member` or `uniqueMember`.

Returns an array with the subgroups of this group.



43
44
45
46
47
# File 'lib/github/ldap/posix_group.rb', line 43

def subgroups
  return [] unless combined_group?

  super
end