Class: Warden::Ldap::Connection
- Inherits:
-
Object
- Object
- Warden::Ldap::Connection
- Defined in:
- lib/warden/ldap/connection.rb
Instance Attribute Summary collapse
-
#ldap ⇒ Object
readonly
Returns the value of attribute ldap.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #authorized? ⇒ Boolean
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #ldap_param_value(param) ⇒ Object
- #logger ⇒ Object
- #valid_login? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/warden/ldap/connection.rb', line 11 def initialize(= {}) @login = .delete(:username) @password = .delete(:password) [:encryption] = config["ssl"].to_sym if config["ssl"] @ldap = Net::LDAP.new() @ldap.host = config["host"] @ldap.port = config["port"] @ldap.base = config["base"] @generic_credentials = config["generic_credentials"] @attribute = [config["attributes"]].flatten end |
Instance Attribute Details
#ldap ⇒ Object (readonly)
Returns the value of attribute ldap.
6 7 8 |
# File 'lib/warden/ldap/connection.rb', line 6 def ldap @ldap end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
6 7 8 |
# File 'lib/warden/ldap/connection.rb', line 6 def login @login end |
Instance Method Details
#authenticate! ⇒ Object
45 46 47 48 49 50 |
# File 'lib/warden/ldap/connection.rb', line 45 def authenticate! if @password @ldap.auth(dn, @password) @ldap.bind end end |
#authenticated? ⇒ Boolean
52 53 54 |
# File 'lib/warden/ldap/connection.rb', line 52 def authenticated? authenticate! end |
#authorized? ⇒ Boolean
56 57 58 59 |
# File 'lib/warden/ldap/connection.rb', line 56 def logger.info("Authorizing user #{dn}") authenticated? end |
#ldap_param_value(param) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/warden/ldap/connection.rb', line 26 def ldap_param_value(param) ldap_entry = nil @ldap.search(:filter => ldap_username_filter) {|entry| ldap_entry = entry} if ldap_entry if ldap_entry[param] logger.info("Requested param #{param} has value #{ldap_entry.send(param)}") value = ldap_entry.send(param) value = value.first if value.is_a?(Array) and value.count == 1 else logger.error("Requested param #{param} does not exist") value = nil end else logger.error("Requested ldap entry does not exist") value = nil end end |
#logger ⇒ Object
7 8 9 |
# File 'lib/warden/ldap/connection.rb', line 7 def logger Warden::Ldap.logger end |
#valid_login? ⇒ Boolean
61 62 63 |
# File 'lib/warden/ldap/connection.rb', line 61 def valid_login? !search_for_login.nil? end |