Parent

Class Index [+]

Quicksearch

ActiveLdap::Adapter::JndiConnection

Constants

HashTable
InitialDirContext
InitialLdapContext
SearchControls
ModificationItem
BasicAttributes
Context
StartTlsRequest
Control
NamingException
NameNotFoundException

Public Class Methods

new(host, port, method) click to toggle source
    # File lib/active_ldap/adapter/jndi_connection.rb, line 74
74:       def initialize(host, port, method)
75:         @host = host
76:         @port = port
77:         @method = method
78:         @context = nil
79:         @tls = nil
80:       end

Public Instance Methods

add(dn, records) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 128
128:       def add(dn, records)
129:         attributes = BasicAttributes.new
130:         records.each do |record|
131:           attributes.put(record.to_java_attribute)
132:         end
133:         @context.create_subcontext(dn, attributes)
134:       end
bind_as_anonymous() click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 103
103:       def bind_as_anonymous
104:         setup_context(nil, nil, "none")
105:         bound?
106:       end
bound?() click to toggle source
    # File lib/active_ldap/adapter/jndi_connection.rb, line 89
89:       def bound?
90:         not @context.nil?
91:       end
delete(dn) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 150
150:       def delete(dn)
151:         @context.destroy_subcontext(dn)
152:       end
modify(dn, records) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 136
136:       def modify(dn, records)
137:         items = records.collect(&:to_java_modification_item)
138:         @context.modify_attributes(dn, items.to_java(ModificationItem))
139:       end
modify_rdn(dn, new_rdn, delete_old_rdn) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 141
141:       def modify_rdn(dn, new_rdn, delete_old_rdn)
142:         # should use mutex
143:         delete_rdn_key = "java.naming.ldap.deleteRDN"
144:         @context.add_to_environment(delete_rdn_key, delete_old_rdn.to_s)
145:         @context.rename(dn, new_rdn)
146:       ensure
147:         @context.remove_from_environment(delete_rdn_key)
148:       end
sasl_bind(bind_dn, mechanism, quiet) click to toggle source
    # File lib/active_ldap/adapter/jndi_connection.rb, line 93
93:       def sasl_bind(bind_dn, mechanism, quiet)
94:         setup_context(bind_dn, password, mechanism)
95:         bound?
96:       end
search(base, scope, filter, attrs, limit, callback, &block) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 108
108:       def search(base, scope, filter, attrs, limit, callback, &block)
109:         controls = SearchControls.new
110:         controls.search_scope = scope
111: 
112:         controls.count_limit = limit if limit
113:         unless attrs.blank?
114:           controls.returning_attributes = attrs.to_java(:string)
115:         end
116: 
117:         @context.search(base, filter, controls).each do |result|
118:           attributes = {}
119:           result.attributes.get_all.each do |attribute|
120:             attributes[attribute.get_id] = attribute.get_all.collect do |value|
121:               value.is_a?(String) ? value : String.from_java_bytes(value)
122:             end
123:           end
124:           callback.call([result.name_in_namespace, attributes], block)
125:         end
126:       end
simple_bind(bind_dn, password) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 98
 98:       def simple_bind(bind_dn, password)
 99:         setup_context(bind_dn, password, "simple")
100:         bound?
101:       end
unbind() click to toggle source
    # File lib/active_ldap/adapter/jndi_connection.rb, line 82
82:       def unbind
83:         @tls.close if @tls
84:         @tls = nil
85:         @context.close if @context
86:         @context = nil
87:       end

Private Instance Methods

ldap_uri() click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 179
179:       def ldap_uri
180:         protocol = @method == :ssl ? "ldaps" : "ldap"
181:         "#{protocol}://#{@host}:#{@port}/"
182:       end
setup_context(bind_dn, password, authentication) click to toggle source
     # File lib/active_ldap/adapter/jndi_connection.rb, line 155
155:       def setup_context(bind_dn, password, authentication)
156:         unbind
157:         environment = {
158:           Context::INITIAL_CONTEXT_FACTORY => "com.sun.jndi.ldap.LdapCtxFactory",
159:           Context::PROVIDER_URL => ldap_uri,
160:         }
161:         environment = HashTable.new(environment)
162:         context = InitialLdapContext.new(environment, nil)
163:         if @method == :start_tls
164:           @tls = context.extended_operation(StartTlsRequest.new)
165:           @tls.negotiate
166:         end
167:         context.add_to_environment(Context::SECURITY_AUTHENTICATION,
168:                                    authentication)
169:         if bind_dn
170:           context.add_to_environment(Context::SECURITY_PRINCIPAL, bind_dn)
171:         end
172:         if password
173:           context.add_to_environment(Context::SECURITY_CREDENTIALS, password)
174:         end
175:         context.reconnect(nil)
176:         @context = context
177:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.