Class: SimpleAD::User

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_ad.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate(username, password, ad_options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_ad.rb', line 8

def self.authenticate(username, password, ad_options)
  return nil if username.empty? or password.empty?  # Nothing to see here. No username / password supplied.

  # Open a new LDAP connection with the specified options
  conn = Net::LDAP.new host: ad_options[:server],
                       port: ad_options[:port] || 389,
                       base: ad_options[:base],
                       auth: {  :username => "#{username}@#{ad_options[:domain]}",
                                :password => password,
                                :method => :simple  }

  # If we can authenticate successfully and find ourselves, we're in.
  if conn.bind and user = conn.search(:filter => "sAMAccountName=#{username}").first
    return self.new(user)
  else
    # Failed authentication
    return nil
  end

  rescue Net::LDAP::LdapError => e
    return nil
end

Instance Method Details

#member_of?(group) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


31
32
33
34
# File 'lib/simple_ad.rb', line 31

def member_of?(group)
  # TODO: Implement the member_of function to test against AD group membership
  raise NotImplementedError
end