Class: Adauth::AdObjects::Group

Inherits:
Adauth::AdObject show all
Defined in:
lib/adauth/ad_objects/group.rb

Overview

Active Directory Group Object

Inherits from Adauth::AdObject

Constant Summary collapse

Fields =

Field mapping

Maps methods to LDAP fields e.g.

:foo => :bar

Becomes

Computer.name

Which calls .name on the LDAP object

{
    :name => :samaccountname,
    :cn_members => [ :member,
        Proc.new {|g| g.sub(/.*?CN=(.*?),.*/, '\1').to_s} ],
    :memberof => :member
}
ObjectFilter =

Object Net::LDAP filter

Used to restrict searches’ to just this object

Net::LDAP::Filter.eq("objectClass", "group")

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Adauth::AdObject

add_object_filter, all, #cn_groups_nested, #delete, #dn_ous, filter, #groups, #handle_field, #initialize, #is_a_member?, #ldap_object, #method_missing, method_missing, #modify, #ous, reverse_field, where

Constructor Details

This class inherits a constructor from Adauth::AdObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Adauth::AdObject

Class Method Details

.new_group(name, parent) ⇒ Object

Create a new Group



31
32
33
34
35
36
37
38
39
# File 'lib/adauth/ad_objects/group.rb', line 31

def self.new_group(name, parent)
  expects parent, [Adauth::AdObjects::OU, Adauth::AdObjects::Folder]
  attributes = {
    cn: name,
    objectclass: ["top", "group"]
  }
  Adauth.connection.add(dn: "CN=#{name},#{parent.ldap_object.dn}", attributes: attributes )
  return Adauth::AdObjects::Group.where('name', name).first
end

Instance Method Details

#cn_groupsObject



50
51
52
53
54
55
56
# File 'lib/adauth/ad_objects/group.rb', line 50

def cn_groups
  if memberof.nil?
    []
  else
    memberof.split(/.*?CN=(.*?),.*/)
  end
end

#membersObject

Returns all the objects which are members of this group



42
43
44
45
46
47
48
# File 'lib/adauth/ad_objects/group.rb', line 42

def members
    Adauth.logger.info(self.class.inspect) { "Getting group members for #{self.name}" }
    unless @members
        @members = convert_to_objects(cn_members)
    end
    @members
end