Class: RubySync::Connectors::LdapConnector
Instance Attribute Summary
#is_vault, #name, #once_only, #pipeline
Class Method Summary
collapse
Instance Method Summary
collapse
#association_context, #association_for, #can_act_as_vault?, #clean, #create_operations_for, #entry_for_own_association_key, event_method, #find_associated, #has_entry_for_key?, #is_delete_echo?, #is_echo?, #is_vault?, #own_association_key_for, #path_for_own_association_key, #start, #stop, #stopped, #sync_started, #sync_stopped, target_transform, #test_delete, #test_modify, track_associations_with, track_changes_with
#associated_path, #clean, #delete_from_mirror, #perform_add, #perform_delete, #perform_modify, #process, #update_mirror
Methods included from Utilities
#as_array, #call_if_exists, #class_called, #class_for_name, #class_name_for, #connector_called, #dump_after, #dump_before, #effective_operations, #ensure_dir_exists, #get_preference, #get_preference_file_path, #include_in_search_path, #log_progress, #perform_operations, #perform_transform, #pipeline_called, #set_preference, #something_called, #with_rescue
Constructor Details
#initialize(options = {}) ⇒ LdapConnector
Returns a new instance of LdapConnector.
60
61
62
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 60
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
82
83
84
85
86
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 82
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 90
def self.sample_config
return <<END
# Using :memory is ok for testing.
# For production, you will need to change to a persistent form of tracking
# such as :dbm or :ldap.
track_changes_with :memory
track_associations_with :memory
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
#Uncomment the following for LDAPS. If you do, make sure that
#you're using the LDAPS port (probably 636) and be aware that
#the server's certificate WON'T be checked for validity.
#encryption :simple_tls
END
end
|
Instance Method Details
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 140
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|
name = name.to_s.downcase
answer[name] = result[0][name] unless name == 'dn'
end
answer
end
end
|
#add(path, operations) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 116
def add(path, operations)
result = nil
with_ldap do |ldap|
attributes = perform_operations(operations)
attributes['objectclass'] || log.warn("Add without objectclass attribute is unlikely to work.")
result = ldap.add :dn=>path, :attributes=>attributes
end
log.debug("ldap.add returned '#{result}'")
return result
rescue Exception
log.warn "Exception occurred while adding LDAP record"
log.debug $!
false
end
|
#delete(path) ⇒ Object
136
137
138
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 136
def delete(path)
with_ldap {|ldap| ldap.delete :dn=>path }
end
|
#each_entry ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 72
def each_entry
Net::LDAP.open(:host=>host, :port=>port, :auth=>auth) do |ldap|
ldap.search :base => search_base, :filter => search_filter, :return_result => false do |ldap_entry|
yield ldap_entry.dn, to_entry(ldap_entry)
end
end
end
|
#modify(path, operations) ⇒ Object
131
132
133
134
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 131
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
|
65
66
67
68
69
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 65
def started
@connections = []
@connection_index = 0
end
|
159
160
161
162
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 159
def target_transform event
end
|
#test_add(id, details) ⇒ Object
Called by unit tests to inject data
154
155
156
157
|
# File 'lib/ruby_sync/connectors/ldap_connector.rb', line 154
def test_add id, details
details << RubySync::Operation.new(:add, "objectclass", ['inetOrgPerson'])
add id, details
end
|