Class ActiveLdap::Adapter::JndiConnection
In: lib/active_ldap/adapter/jndi_connection.rb
Parent: Object
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired AdapterNotFound TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError ConnectionNotSetup DistinguishedNameInvalid Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update Normalizable GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport Xml JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/xml.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb Compatible ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/jndi.rb Adapter Helper GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_46_0.png

Methods

Classes and Modules

Module ActiveLdap::Adapter::JndiConnection::Scope
Class ActiveLdap::Adapter::JndiConnection::ModifyRecord

Constants

HashTable = java.util.Hashtable
InitialDirContext = directory.InitialDirContext
InitialLdapContext = ldap.InitialLdapContext
SearchControls = directory.SearchControls
ModificationItem = directory.ModificationItem
BasicAttributes = directory.BasicAttributes
Context = naming.Context
StartTlsRequest = ldap.StartTlsRequest
Control = ldap.Control
NamingException = naming.NamingException
NameNotFoundException = naming.NameNotFoundException

Public Class methods

[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

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 130
130:       def add(dn, records)
131:         attributes = BasicAttributes.new
132:         records.each do |record|
133:           attributes.put(record.to_java_attribute)
134:         end
135:         @context.create_subcontext(dn, attributes)
136:       end

[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

[Source]

    # File lib/active_ldap/adapter/jndi_connection.rb, line 89
89:       def bound?
90:         not @context.nil?
91:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 152
152:       def delete(dn)
153:         @context.destroy_subcontext(dn)
154:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 138
138:       def modify(dn, records)
139:         items = records.collect(&:to_java_modification_item)
140:         @context.modify_attributes(dn, items.to_java(ModificationItem))
141:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 143
143:       def modify_rdn(dn, new_rdn, delete_old_rdn)
144:         # should use mutex
145:         delete_rdn_key = "java.naming.ldap.deleteRDN"
146:         @context.add_to_environment(delete_rdn_key, delete_old_rdn.to_s)
147:         @context.rename(dn, new_rdn)
148:       ensure
149:         @context.remove_from_environment(delete_rdn_key)
150:       end

[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

[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:         unless attrs.blank?
113:           controls.returning_attributes = attrs.to_java(:string)
114:         end
115: 
116:         i = 0
117:         @context.search(base, filter, controls).each do |result|
118:           i += 1
119:           attributes = {}
120:           result.attributes.get_all.each do |attribute|
121:             attributes[attribute.get_id] = attribute.get_all.collect do |value|
122:               value.is_a?(String) ? value : String.from_java_bytes(value)
123:             end
124:           end
125:           callback.call([result.name_in_namespace, attributes], block)
126:           break if limit and limit <= i
127:         end
128:       end

[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

[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

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 181
181:       def ldap_uri
182:         protocol = @method == :ssl ? "ldaps" : "ldap"
183:         "#{protocol}://#{@host}:#{@port}/"
184:       end

[Source]

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

[Validate]