Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ldap/person.rb')
-rw-r--r--lib/gitlab/ldap/person.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/ldap/person.rb b/lib/gitlab/ldap/person.rb
new file mode 100644
index 00000000000..06b17c58f8c
--- /dev/null
+++ b/lib/gitlab/ldap/person.rb
@@ -0,0 +1,50 @@
+module Gitlab
+ module LDAP
+ class Person
+ def self.find_by_uid(uid, adapter=nil)
+ adapter ||= Gitlab::LDAP::Adapter.new
+ adapter.user(config.uid, uid)
+ end
+
+ def self.find_by_dn(dn, adapter=nil)
+ adapter ||= Gitlab::LDAP::Adapter.new
+ adapter.user('dn', dn)
+ end
+
+ def initialize(entry)
+ Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" }
+ @entry = entry
+ end
+
+ def name
+ entry.cn.first
+ end
+
+ def uid
+ entry.send(config.uid).first
+ end
+
+ def username
+ uid
+ end
+
+ def dn
+ entry.dn
+ end
+
+ private
+
+ def entry
+ @entry
+ end
+
+ def adapter
+ @adapter ||= Gitlab::LDAP::Adapter.new
+ end
+
+ def config
+ @config ||= Gitlab.config.ldap
+ end
+ end
+ end
+end