Class: Chaltron::LDAP::Person

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#entryObject

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

Returns:

  • (Boolean)


8
9
10
# File 'lib/chaltron/ldap/person.rb', line 8

def self.valid_credentials?(, password)
  ldap.auth(, 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

#departmentObject



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

def department
  entry.send(Chaltron.ldap_field_mappings[:department]).first rescue nil
end

#dnObject



72
73
74
# File 'lib/chaltron/ldap/person.rb', line 72

def dn
  entry.dn
end

#emailObject



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_groupsObject



80
81
82
# File 'lib/chaltron/ldap/person.rb', line 80

def ldap_groups
  self.class.ldap.find_groups_by_member(self)
end

#nameObject



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

#providerObject



76
77
78
# File 'lib/chaltron/ldap/person.rb', line 76

def provider
  'ldap'
end

#uidObject



60
61
62
# File 'lib/chaltron/ldap/person.rb', line 60

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

#usernameObject



64
65
66
# File 'lib/chaltron/ldap/person.rb', line 64

def username
  uid
end