Class: Adconnect::ActiveDirectoryUser

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

Constant Summary collapse

SERVER =

Active Directory server name or IP

'localhost'
PORT =

Active Directory server port (default 389)

389
BASE =

Base to search from

'DC=example,DC=com'
DOMAIN =

For simplified user@domain format login

'example.com'

Class Method Summary collapse

Class Method Details

.authenticate(username, password) ⇒ Object



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

def self.authenticate(username,password)
	@server  ||= SERVER
	@port    ||= PORT
	@base    ||= BASE
	@domain  ||= DOMAIN
	
	conn = Net::LDAP.new :host => @server,
		 :port => @port,
		 :base => @base,
		 :auth => {
			   :method => :simple,
			   :username => "#{username}@#{@domain}",
			   :password => password
		 }
		 
	if conn.bind && user = conn.search(:filter => "sAMAccountName=#{username}").first
	  user
	else
	  nil
	end
end

.base=(b) ⇒ Object



40
41
42
# File 'lib/adconnect.rb', line 40

def self.base=(b)
	@base = b
end

.domain=(d) ⇒ Object



44
45
46
# File 'lib/adconnect.rb', line 44

def self.domain=(d)
	@domain = d
end

.port=(p) ⇒ Object



36
37
38
# File 'lib/adconnect.rb', line 36

def self.port=(p)
	@port = p
end

.server=(s) ⇒ Object



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

def self.server=(s)
	@server = s
end