Class: FakeLDAP::Operation
- Inherits:
-
LDAP::Server::Operation
- Object
- LDAP::Server::Operation
- FakeLDAP::Operation
- Defined in:
- lib/fakeldap.rb
Instance Method Summary collapse
- #add(dn, attr) ⇒ Object
-
#del(*args) ⇒ Object
Some silly clients call delete del…
- #delete(*args) ⇒ Object
-
#initialize(connection, messageID, server) ⇒ Operation
constructor
A new instance of Operation.
- #modify(*args) ⇒ Object
- #search(basedn, scope, deref, filter, attrs = nil) ⇒ Object
- #simple_bind(version, dn, password) ⇒ Object
Constructor Details
#initialize(connection, messageID, server) ⇒ Operation
Returns a new instance of Operation.
120 121 122 123 |
# File 'lib/fakeldap.rb', line 120 def initialize(connection, , server) super(connection, ) @server = server end |
Instance Method Details
#add(dn, attr) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/fakeldap.rb', line 159 def add(dn, attr) # Barring rocket-science. Always, only one single add case attr['objectclass'][0] when 'inetOrgPerson' @server.add_user(dn, attr[:userPassword], attr[:mail]) when 'groupofnames' @server.add_to_group(dn, attr['member'][0]) end end |
#del(*args) ⇒ Object
Some silly clients call delete del…
180 181 182 |
# File 'lib/fakeldap.rb', line 180 def del(*args) delete(args) end |
#delete(*args) ⇒ Object
184 185 186 187 |
# File 'lib/fakeldap.rb', line 184 def delete(*args) dn = args[0] @server.delete_entry(dn) end |
#modify(*args) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/fakeldap.rb', line 169 def modify(*args) # A hash able to contain an array of arrays... LDAP nuttiness! dn = args[0] key = args[1].keys.first action = args[1][key][0] value = args[1][key][1] # Barring rocket-science. Always, only one single action. @server.modify_entry(dn, key, action, value) end |
#search(basedn, scope, deref, filter, attrs = nil) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/fakeldap.rb', line 137 def search(basedn, scope, deref, filter, attrs=nil) unless filter.first == :eq raise LDAP::ResultError::UnwillingToPerform, "Only equality matches are supported" end users = @server.find_users(basedn, filter) groups = @server.find_groups(basedn, filter) if users users.each do |dn| attributes = @server.user_attributes("#{dn}") || {} send_SearchResultEntry(dn, attributes) end end if groups groups.each do |dn| attributes = @server.group_attributes("#{dn}") || {} send_SearchResultEntry(dn, attributes) end end end |
#simple_bind(version, dn, password) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fakeldap.rb', line 125 def simple_bind(version, dn, password) unless dn raise LDAP::ResultError::InappropriateAuthentication, "This server does not support anonymous bind" end unless @server.valid_credentials?(dn, password) raise LDAP::ResultError::InvalidCredentials, "Invalid credentials" end end |