2014-09-02 18:07:02 +05:30
|
|
|
module Gitlab
|
|
|
|
module LDAP
|
|
|
|
class Person
|
|
|
|
# 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/
|
|
|
|
AD_USER_DISABLED = Net::LDAP::Filter.ex("userAccountControl:1.2.840.113556.1.4.803", "2")
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
attr_accessor :entry, :provider
|
|
|
|
|
|
|
|
def self.find_by_uid(uid, adapter)
|
|
|
|
uid = Net::LDAP::Filter.escape(uid)
|
|
|
|
adapter.user(adapter.config.uid, uid)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def self.find_by_dn(dn, adapter)
|
2014-09-02 18:07:02 +05:30
|
|
|
adapter.user('dn', dn)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def self.disabled_via_active_directory?(dn, adapter)
|
2014-09-02 18:07:02 +05:30
|
|
|
adapter.dn_matches_filter?(dn, AD_USER_DISABLED)
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def initialize(entry, provider)
|
2014-09-02 18:07:02 +05:30
|
|
|
Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
|
|
|
|
@entry = entry
|
2015-04-26 12:48:37 +05:30
|
|
|
@provider = provider
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
entry.cn.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def uid
|
|
|
|
entry.send(config.uid).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
uid
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def email
|
|
|
|
entry.try(:mail)
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def dn
|
|
|
|
entry.dn
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def entry
|
|
|
|
@entry
|
|
|
|
end
|
|
|
|
|
|
|
|
def config
|
2015-04-26 12:48:37 +05:30
|
|
|
@config ||= Gitlab::LDAP::Config.new(provider)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|