Class: Entitlements::Backend::LDAP::Provider
- Inherits:
-
Object
- Object
- Entitlements::Backend::LDAP::Provider
show all
- Includes:
- Contracts::Core
- Defined in:
- lib/entitlements/backend/ldap/provider.rb
Constant Summary
collapse
- C =
::Contracts
Instance Method Summary
collapse
common, extended, included
Constructor Details
#initialize(ldap:) ⇒ Provider
Returns a new instance of Provider.
16
17
18
19
20
21
22
23
24
|
# File 'lib/entitlements/backend/ldap/provider.rb', line 16
def initialize(ldap:)
@ldap = ldap
@groups_in_ou_cache = {}
Entitlements.cache[:ldap_cache] ||= {}
end
|
Instance Method Details
#delete(dn) ⇒ Object
86
87
88
89
|
# File 'lib/entitlements/backend/ldap/provider.rb', line 86
def delete(dn)
return if ldap.delete(dn)
raise "Unable to delete LDAP group #{dn.inspect}!"
end
|
#read_all(ou) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/entitlements/backend/ldap/provider.rb', line 56
def read_all(ou)
@groups_in_ou_cache[ou] ||= begin
Entitlements.logger.debug "Loading all groups for #{ou}"
raw = ldap.search(
base: ou,
filter: Net::LDAP::Filter.eq("cn", "*"),
scope: Net::LDAP::SearchScope_SingleLevel
)
result = Set.new
raw.each do |dn, entry|
Entitlements.cache[:ldap_cache][dn] = Entitlements::Service::LDAP.entry_to_group(entry)
result.add dn
end
result
end
end
|
#upsert(group, override = {}) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/entitlements/backend/ldap/provider.rb', line 98
def upsert(group, override = {})
members = group.member_strings.map { |ms| ldap.person_dn_format.gsub("%KEY%", ms) }
attributes = {
"uniqueMember" => members,
"description" => group.description || "",
"owner" => [ldap.binddn],
"objectClass" => ["groupOfUniqueNames"],
"cn" => group.cn
}.merge(override)
override.each { |key, val| attributes.delete(key) if val.nil? }
if group.member_strings.empty?
attributes["uniqueMember"] = [group.dn]
end
result = ldap.upsert(dn: group.dn, attributes: attributes)
return result if result == true
return false if result.nil?
raise "Unable to upsert LDAP group #{group.dn.inspect}!"
end
|