Class: ActiveDirectory::Client
- Inherits:
-
Object
- Object
- ActiveDirectory::Client
- Defined in:
- lib/active_directory/client.rb
Class Method Summary collapse
- .add(dn, attrs) ⇒ Object
- .add_attribute(dn, field, value) ⇒ Object
- .connection ⇒ Object
- .delete(dn) ⇒ Object
- .delete_attribute(dn, field) ⇒ Object
- .modify(dn, operations) ⇒ Object
- .modify_unicode_pwd(dn, old_password, new_password) ⇒ Object
- .rename(old_dn, new_dn) ⇒ Object
- .search(filter, attrs, treebase = nil) ⇒ Object
- .update_attribute(dn, field, value) ⇒ Object
Class Method Details
.add(dn, attrs) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/active_directory/client.rb', line 78 def self.add(dn, attrs) puts dn puts attrs result = connection.add(:dn => dn, :attributes => attrs) if result = "LDAP-Object #{dn} was created" return result, else mesage = "LDAP-Object #{dn} was not created. \ Error: #{connection.get_operation_result}" return result, end # DirectoryUser.add( # "CN=Test Dude,OU=Testing,OU=Accounts,DC=synapsedev,DC=com", # { # name: "Test dude", # samaccountname: "test_dude_123", # objectclass:["top", "user"], # sn: "Dude", # cn: "Test Dude", # givenname: "Test" # } # ) end |
.add_attribute(dn, field, value) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/active_directory/client.rb', line 69 def self.add_attribute(dn, field, value) if connection.add_attribute(dn, field, value) true else raise StandardError, "LDAP-Attribute (#{field}) wasnt added for \ #{dn}. Error: #{connection.get_operation_result}" end end |
.connection ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/active_directory/client.rb', line 3 def self.connection ldap = Net::LDAP.new( host: ActiveDirectory::Configuration.ldap_host, port: ActiveDirectory::Configuration.ldap_port, encryption: :simple_tls ) ldap.authenticate( ActiveDirectory::Configuration.username, ActiveDirectory::Configuration.password ) ldap end |
.delete(dn) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/active_directory/client.rb', line 104 def self.delete(dn) if connection.delete(dn: dn) true else raise StandardError, "LDAP-Object #{dn} was not deleted. Error: #{connection.get_operation_result}" end end |
.delete_attribute(dn, field) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/active_directory/client.rb', line 47 def self.delete_attribute(dn, field) if connection.delete_attribute(dn, field.to_sym) # remove_instance_variable("@#{field}".to_sym) true else raise StandardError, "LDAP-Attribute #{field} was not deleted for [#{dn}]" end end |
.modify(dn, operations) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/active_directory/client.rb', line 30 def self.modify(dn, operations) if connection.modify(dn: dn, operations: operations) true else false end end |
.modify_unicode_pwd(dn, old_password, new_password) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_directory/client.rb', line 56 def self.modify_unicode_pwd(dn, old_password, new_password) ops = [ [:delete, :unicodePwd, old_password], [:add, :unicodePwd, new_password] ] if connection.modify(dn: dn, operations: ops) true else raise StandardError, "LDAP-Attribute password for #{dn} was not \ updated. Error: #{connection.get_operation_result}" end end |
.rename(old_dn, new_dn) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/active_directory/client.rb', line 38 def self.rename(old_dn, new_dn) connection.rename( olddn: old_dn, newrdn: new_dn, delete_attributes: true, new_superior: "OU=Automated Groups,OU=Groups,DC=synapsedev,DC=com" ) end |
.search(filter, attrs, treebase = nil) ⇒ Object
16 17 18 19 |
# File 'lib/active_directory/client.rb', line 16 def self.search(filter, attrs, treebase = nil) treebase ||= ActiveDirectory::Configuration.ldap_treebase connection.search(base: treebase, filter: filter, attributes: attrs ) end |
.update_attribute(dn, field, value) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/active_directory/client.rb', line 21 def self.update_attribute(dn, field, value) if connection.replace_attribute(dn, field, value) true else raise StandardError, "LDAP-Attribute #{field} was not updated for \ [#{dn}]. Error #{connection.get_operation_result}" end end |