Class: ActiveDirectory::User
Class Method Summary
collapse
Instance Method Summary
collapse
#create, #delete, #initialize, #rename, #update
Class Method Details
.add(dn, attrs = {}) ⇒ Object
28
29
30
|
# File 'lib/active_directory/user.rb', line 28
def self.add(dn, attrs = {})
end
|
.fields ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/active_directory/user.rb', line 66
def self.fields
{
mail: "email",
title: "title",
sn: "last_name",
givenName: "first_name",
department: "department",
employeeType: "employee_type",
sAMAccountName: "username",
l: "location",
dn: "dn"
}
end
|
.find_by_email(email, treebase = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/active_directory/user.rb', line 56
def self.find_by_email(email, treebase=nil)
filter = "(&(objectCategory=person)(objectClass=user)(mail=#{email}))"
results = Client.search(filter, self.fields.keys, treebase).first
if results
self.new(results)
else
false
end
end
|
.find_by_username(username, treebase = nil) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/active_directory/user.rb', line 46
def self.find_by_username(username, treebase=nil)
filter = "(&(objectCategory=person)(objectClass=user)(samaccountname=#{username}))"
results = Client.search(filter, self.fields.keys, treebase).first
if results
self.new(results)
else
false
end
end
|
Instance Method Details
#add_to_group(group_dn) ⇒ Object
24
25
26
|
# File 'lib/active_directory/user.rb', line 24
def add_to_group(group_dn)
Client.add_attribute(group_dn, :member, @dn)
end
|
#change_password(old_password, new_password) ⇒ Object
#groups ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/active_directory/user.rb', line 32
def groups
groups = []
filter = "(&(objectClass=group)(member:1.2.840.113556.1.4.1941:=#{@dn}))"
results = Client.search(filter, Group.fields.keys)
if results
results.each do |r|
groups << Group.new(r)
end
groups
else
false
end
end
|
#password(new_password) ⇒ Object
#remove_from_group(group_dn) ⇒ Object
20
21
22
|
# File 'lib/active_directory/user.rb', line 20
def remove_from_group(group_dn)
Client.modify(group_dn.to_s, [[:delete, :member, @dn]])
end
|