Class: LdapRails::LdapUser

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap-rails/ldap_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ LdapUser

Returns a new instance of LdapUser.



7
8
9
# File 'lib/ldap-rails/ldap_user.rb', line 7

def initialize hash
  @username = hash[:username]
end

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/ldap-rails/ldap_user.rb', line 5

def username
  @username
end

Class Method Details

.auth(username, password) ⇒ Object

Tries to authenticate using the given username and password. Returns an LdapUser is successful, nil if unsuccessful.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ldap-rails/ldap_user.rb', line 17

def self.auth username, password
  unless LdapRails.config
    raise NoConfigurationError.new("You must have a call to LdapRails.configure in an initializer.")
  end

  LdapRails.ldap.auth dn_for(username), password
  if LdapRails.ldap.bind
    return new(:username => username)
  else
    return nil
  end
end

Instance Method Details

#to_hashObject



11
12
13
# File 'lib/ldap-rails/ldap_user.rb', line 11

def to_hash
  {:username => @username}
end