Class: Wobaduser::User

Inherits:
Base
  • Object
show all
Defined in:
lib/wobaduser/user.rb

Constant Summary collapse

ATTR_SV =

ATTR_SV is for single valued attributes only. Generated readers will convert the value to a string before returning or calling your Proc.

{
  # method name         ldap attribute
  :username           => :userprincipalname,
  :userprincipalname  => :userprincipalname,
  :givenname          => :givenname,
  :sn                 => :sn,
  :cn                 => :cn,
  :dn                 => :dn,
  :displayname        => :displayname,
  :mail               => :mail,
  :title              => :title,
  :telephonenumber    => :telephonenumber,
  :facsimiletelephonenumber => :facsimiletelephonenumber,
  :mobile             => :mobile,
  :description        => :description,
  :department         => :department,
  :company            => :company,
  :postalcode         => :postalcode,
  :l                  => :l,
  :streetaddress      => :streetaddress,
  :samaccountname     => :samaccountname,
  :primarygroupid     => :primarygroupid,
  :guid               => [ :objectguid, Proc.new {|p| Base64.encode64(p).chomp } ],
  :useraccountcontrol => :useraccountcontrol,
  :is_valid? => [ :useraccountcontrol, Proc.new {|c| (c.to_i & 2) == 0 } ],
}
ATTR_MV =

ATTR_MV is for multi-valued attributes. Generated readers will always return an array.

{
  # method name         ldap attribute
  :members     => :member,
  :objectclass => :objectclass,
  :groups      => [ :memberof,
                  # Get the simplified name of first-level groups.
                  # TODO: Handle escaped special characters
                  Proc.new {|g| g.sub(/.*?CN=(.*?),.*/, '\1')} ],
  # :mailaliases => [ :proxyAddresses, Proc.new{|p| p.lowercase.gsub(/\Asmtp:/,'')}]
  :mailaliases => [ :proxyaddresses, Proc.new {|p|
                                       p = p.downcase
                                       next unless p=~ /\Asmtp:/
                                       p.gsub(/\Asmtp:/, '')
                                     }],
}

Constants inherited from Base

Base::SearchResult

Instance Attribute Summary

Attributes inherited from Base

#entry, #errors

Instance Method Summary collapse

Methods inherited from Base

filter, #initialize, search, #valid?

Constructor Details

This class inherits a constructor from Wobaduser::Base

Instance Method Details

#all_groupsObject



65
66
67
68
69
# File 'lib/wobaduser/user.rb', line 65

def all_groups
  filter = Net::LDAP::Filter.present("cn") & Net::LDAP::Filter.eq("objectClass", "group") &
     Net::LDAP::Filter.ex("member:1.2.840.113556.1.4.1941", @entry.dn)
  @ldap.search(filter: filter, attributes: ['cn']).map(&:cn).flatten.map(&:as_utf8)
end

#filter(valid = false) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/wobaduser/user.rb', line 56

def filter(valid = false)
  filter = Net::LDAP::Filter.eq('objectClass', 'user')
  if valid
    filter & ~(Net::LDAP::Filter.ex('UserAccountControl:1.2.840.113556.1.4.803', 2))
  else
    filter
  end
end