2014-03-10 08:48:08 -04:00
|
|
|
module Gitlab
|
|
|
|
module LDAP
|
|
|
|
class Person
|
2014-05-14 13:08:42 -04:00
|
|
|
# Active Directory-specific LDAP filter that checks if bit 2 of the
|
|
|
|
# userAccountControl attribute is set.
|
|
|
|
# Source: http://ctogonewild.com/2009/09/03/bitmask-searches-in-ldap/
|
2014-05-14 12:54:05 -04:00
|
|
|
AD_USER_DISABLED = Net::LDAP::Filter.ex("userAccountControl:1.2.840.113556.1.4.803", "2")
|
2014-05-14 12:26:58 -04:00
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
attr_accessor :entry, :provider
|
|
|
|
|
|
|
|
def self.find_by_uid(uid, adapter)
|
2015-03-06 07:26:33 -05:00
|
|
|
uid = Net::LDAP::Filter.escape(uid)
|
2014-10-14 04:54:43 -04:00
|
|
|
adapter.user(adapter.config.uid, uid)
|
2014-03-10 08:48:08 -04:00
|
|
|
end
|
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
def self.find_by_dn(dn, adapter)
|
2014-03-14 03:52:57 -04:00
|
|
|
adapter.user('dn', dn)
|
2014-03-10 08:48:08 -04:00
|
|
|
end
|
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
def self.disabled_via_active_directory?(dn, adapter)
|
2014-05-14 12:26:58 -04:00
|
|
|
adapter.dn_matches_filter?(dn, AD_USER_DISABLED)
|
|
|
|
end
|
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
def initialize(entry, provider)
|
2014-03-10 08:48:08 -04:00
|
|
|
Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
|
|
|
|
@entry = entry
|
2014-10-13 11:24:05 -04:00
|
|
|
@provider = provider
|
2014-03-10 08:48:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
entry.cn.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def uid
|
|
|
|
entry.send(config.uid).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
uid
|
|
|
|
end
|
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
def email
|
|
|
|
entry.try(:mail)
|
|
|
|
end
|
|
|
|
|
2014-03-10 08:48:08 -04:00
|
|
|
def dn
|
|
|
|
entry.dn
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def entry
|
|
|
|
@entry
|
|
|
|
end
|
|
|
|
|
|
|
|
def config
|
2014-10-13 11:24:05 -04:00
|
|
|
@config ||= Gitlab::LDAP::Config.new(provider)
|
2014-03-10 08:48:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|