Class: Chaltron::LDAP::Person
- Inherits:
-
Object
- Object
- Chaltron::LDAP::Person
- Defined in:
- lib/chaltron/ldap/person.rb
Instance Attribute Summary collapse
-
#entry ⇒ Object
Returns the value of attribute entry.
Class Method Summary collapse
- .find_by_field(field, value) ⇒ Object
- .find_by_fields(fields = {}) ⇒ Object
- .find_by_uid(uid) ⇒ Object
- .valid_credentials?(login, password) ⇒ Boolean
Instance Method Summary collapse
- #create_user(roles = []) ⇒ Object
- #department ⇒ Object
- #dn ⇒ Object
- #email ⇒ Object
-
#initialize(entry, uid) ⇒ Person
constructor
A new instance of Person.
- #ldap_groups ⇒ Object
- #name ⇒ Object
- #provider ⇒ Object
- #uid ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(entry, uid) ⇒ Person
Returns a new instance of Person.
24 25 26 27 28 |
# File 'lib/chaltron/ldap/person.rb', line 24 def initialize(entry, uid) # Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" } @entry = entry @uid = uid end |
Instance Attribute Details
#entry ⇒ Object
Returns the value of attribute entry.
6 7 8 |
# File 'lib/chaltron/ldap/person.rb', line 6 def entry @entry end |
Class Method Details
.find_by_field(field, value) ⇒ Object
12 13 14 |
# File 'lib/chaltron/ldap/person.rb', line 12 def self.find_by_field(field, value) ldap.find_users(field.to_sym => value) end |
.find_by_fields(fields = {}) ⇒ Object
16 17 18 |
# File 'lib/chaltron/ldap/person.rb', line 16 def self.find_by_fields(fields = {}) ldap.find_users(fields) end |
.find_by_uid(uid) ⇒ Object
20 21 22 |
# File 'lib/chaltron/ldap/person.rb', line 20 def self.find_by_uid(uid) ldap.find_by_uid(uid) end |
.valid_credentials?(login, password) ⇒ Boolean
8 9 10 |
# File 'lib/chaltron/ldap/person.rb', line 8 def self.valid_credentials?(login, password) ldap.auth(login, password) end |
Instance Method Details
#create_user(roles = []) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chaltron/ldap/person.rb', line 30 def create_user(roles = []) password = Devise.friendly_token[0, 8].downcase user = ::User.new(extern_uid: dn, provider: provider, fullname: name, username: username, email: email, password: password, password_confirmation: password, department: department ) user.roles = roles user.save user end |
#department ⇒ Object
46 47 48 |
# File 'lib/chaltron/ldap/person.rb', line 46 def department entry.send(Chaltron.ldap_field_mappings[:department]).first rescue nil end |
#dn ⇒ Object
72 73 74 |
# File 'lib/chaltron/ldap/person.rb', line 72 def dn entry.dn end |
#email ⇒ Object
68 69 70 |
# File 'lib/chaltron/ldap/person.rb', line 68 def email entry.send(Chaltron.ldap_field_mappings[:email]).first rescue nil end |
#ldap_groups ⇒ Object
80 81 82 |
# File 'lib/chaltron/ldap/person.rb', line 80 def ldap_groups self.class.ldap.find_groups_by_member(self) end |
#name ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/chaltron/ldap/person.rb', line 50 def name if Chaltron.ldap_field_mappings[:full_name].nil? first_name = entry.send(Chaltron.ldap_field_mappings[:first_name]).first last_name = entry.send(Chaltron.ldap_field_mappings[:last_name]).first "#{first_name} #{last_name}" else entry.send(Chaltron.ldap_field_mappings[:full_name]).first end end |
#provider ⇒ Object
76 77 78 |
# File 'lib/chaltron/ldap/person.rb', line 76 def provider 'ldap' end |
#uid ⇒ Object
60 61 62 |
# File 'lib/chaltron/ldap/person.rb', line 60 def uid entry.send(@uid).first end |
#username ⇒ Object
64 65 66 |
# File 'lib/chaltron/ldap/person.rb', line 64 def username uid end |