Class: RubySync::Connectors::LdapConnector
Instance Attribute Summary
#is_vault, #name, #once_only, #pipeline
Class Method Summary
collapse
Instance Method Summary
collapse
#associate, #association_context, #association_for, #association_key_for, #association_to_path_dbm_filename, #associations_for, #can_act_as_vault?, class_for, class_name_for, #clean, #create_operations_for, #dbm_path, #digest, #each_change, #entry_for_own_association_key, #find_associated, #has_entry_for_key?, #is_delete_echo?, #is_echo?, #is_vault?, #mirror_dbm_filename, #own_association_key_for, #path_for_association, #path_for_own_association_key, #path_to_association_dbm_filename, #remove_association, #remove_associations, #remove_mirror, #start, #stop, #stopped, #sync_started, #sync_stopped, #test_delete, #test_modify
Methods included from Utilities
#as_array, #base_path, #call_if_exists, #connector_called, #effective_operations, #ensure_dir_exists, #find_base_path, #get_preference, #get_preference_file_path, #include_in_search_path, #log_progress, #perform_operations, #pipeline_called, #set_preference, #something_called, #with_rescue
Constructor Details
#initialize(options = {}) ⇒ LdapConnector
Returns a new instance of LdapConnector.
51
52
53
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 51
def initialize options={}
super options
end
|
Class Method Details
Runs the query specified by the config, gets the objectclass of the first returned object and returns a list of its allowed attributes
71
72
73
74
75
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 71
def self.fields
log.warn "Fields method not yet implemented for LDAP - Sorry."
log.warn "Returning a likely sample set."
%w{ cn givenName sn }
end
|
.sample_config ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 79
def self.sample_config
return <<END
host 'localhost'
port 389
username 'cn=Manager,dc=my-domain,dc=com'
password 'secret'
search_filter "cn=*"
search_base "ou=users,o=my-organization,dc=my-domain,dc=com"
#:bind_method :simple
END
end
|
Instance Method Details
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 117
def [](path)
with_ldap do |ldap|
result = ldap.search :base=>path, :scope=>Net::LDAP::SearchScope_BaseObject, :filter=>'objectclass=*'
return nil if !result or result.size == 0
answer = {}
result[0].attribute_names.each do |name|
answer[name.to_s] = result[0][name]
end
answer
end
end
|
#add(path, operations) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 94
def add(path, operations)
result = nil
with_ldap do |ldap|
attributes = perform_operations(operations)
result = ldap.add :dn=>path, :attributes=>attributes
end
log.debug("ldap.add returned '#{result}'")
return true
rescue Exception
log.warn "Exception occurred while adding LDAP record"
log.debug $!
false
end
|
#delete(path) ⇒ Object
113
114
115
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 113
def delete(path)
with_ldap {|ldap| ldap.delete :dn=>path }
end
|
#each_entry ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 61
def each_entry
Net::LDAP.open(:host=>host, :port=>port, :auth=>auth) do |ldap|
ldap.search :base => search_base, :filter => search_filter do |ldap_entry|
yield ldap_entry.dn, to_entry(ldap_entry)
end
end
end
|
#modify(path, operations) ⇒ Object
108
109
110
111
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 108
def modify(path, operations)
log.debug "Modifying #{path} with the following operations:\n#{operations.inspect}"
with_ldap {|ldap| ldap.modify :dn=>path, :operations=>to_ldap_operations(operations) }
end
|
56
57
58
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 56
def started
end
|
135
136
137
138
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 135
def target_transform event
end
|
#test_add(id, details) ⇒ Object
Called by unit tests to inject data
130
131
132
133
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 130
def test_add id, details
details << RubySync::Operation.new(:add, "objectclass", ['inetOrgPerson'])
add id, details
end
|