class IBMW3::Authenticate
Public Class Methods
do(email, password)
click to toggle source
# File lib/ibm_w3.rb, line 11 def self.do(email, password) user = find_user_from_email(email) if user.nil? return false elsif self.authenticated?(user[:dn], password) return user else return false end end
Private Class Methods
authenticated?(dn, password)
click to toggle source
# File lib/ibm_w3.rb, line 56 def self.authenticated?(dn, password) connection = nil LDAP::SSLConn.new(@@host, @@port).bind do |conn| connection = conn end connection.bind(dn, password) return true if connection return false rescue LDAP::ResultError return false end
find_user_from_email(email)
click to toggle source
# File lib/ibm_w3.rb, line 37 def self.find_user_from_email(email) user, found = nil, false filter = "(&(objectclass=ibmPerson)(mail=#{email}))" searchAttributes = ['dn', 'mail', 'cn', 'c', 'notesshortname', 'uid'] LDAP::SSLConn.new(@@host, @@port).bind do |conn| conn.search(@@base, LDAP::LDAP_SCOPE_SUBTREE, filter, searchAttributes) do |entry| found = true user = self.map_entry_to_user(entry) end end return nil unless found return user rescue LDAP::ResultError puts "DN NOT FOUND" return nil end
map_entry_to_user(entry)
click to toggle source
# File lib/ibm_w3.rb, line 25 def self.map_entry_to_user(entry) entry = entry.to_hash() { dn: entry['dn'][0], email: entry['mail'][0], country: entry['c'][0], shortname: entry['notesshortname'][0], name: entry['cn'][0], uid: entry['uid'][0] } end