Class: Gitlab::LDAP::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ldap/person.rb

Constant Summary collapse

AD_USER_DISABLED =

Active Directory-specific LDAP filter that checks if bit 2 of the userAccountControl attribute is set. Source: ctogonewild.com/2009/09/03/bitmask-searches-in-ldap/

Net::LDAP::Filter.ex("userAccountControl:1.2.840.113556.1.4.803", "2")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, provider) ⇒ Person

Returns a new instance of Person


24
25
26
27
28
# File 'lib/gitlab/ldap/person.rb', line 24

def initialize(entry, provider)
  Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
  @entry = entry
  @provider = provider
end

Instance Attribute Details

#entry=(value) ⇒ Object

Sets the attribute entry

Parameters:

  • value

    the value to set the attribute entry to.


9
10
11
# File 'lib/gitlab/ldap/person.rb', line 9

def entry=(value)
  @entry = value
end

#providerObject

Returns the value of attribute provider


9
10
11
# File 'lib/gitlab/ldap/person.rb', line 9

def provider
  @provider
end

Class Method Details

.disabled_via_active_directory?(dn, adapter) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/gitlab/ldap/person.rb', line 20

def self.disabled_via_active_directory?(dn, adapter)
  adapter.dn_matches_filter?(dn, AD_USER_DISABLED)
end

.find_by_dn(dn, adapter) ⇒ Object


16
17
18
# File 'lib/gitlab/ldap/person.rb', line 16

def self.find_by_dn(dn, adapter)
  adapter.user('dn', dn)
end

.find_by_uid(uid, adapter) ⇒ Object


11
12
13
14
# File 'lib/gitlab/ldap/person.rb', line 11

def self.find_by_uid(uid, adapter)
  uid = Net::LDAP::Filter.escape(uid)
  adapter.user(adapter.config.uid, uid)
end

Instance Method Details

#dnObject


46
47
48
# File 'lib/gitlab/ldap/person.rb', line 46

def dn
  entry.dn
end

#emailObject


42
43
44
# File 'lib/gitlab/ldap/person.rb', line 42

def email
  entry.try(:mail)
end

#nameObject


30
31
32
# File 'lib/gitlab/ldap/person.rb', line 30

def name
  entry.cn.first
end

#uidObject


34
35
36
# File 'lib/gitlab/ldap/person.rb', line 34

def uid
  entry.send(config.uid).first
end

#usernameObject


38
39
40
# File 'lib/gitlab/ldap/person.rb', line 38

def username
  uid
end