Class ActiveLdap::Adapter::JndiConnection
In: lib/active_ldap/adapter/jndi_connection.rb
Parent: Object
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid DistinguishedNameNotSetError EntryNotFound LdapError SaveError StrongAuthenticationRequired NotImplemented 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] Base DistinguishedName Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Normalizable Common Find LDIF Delete Update ActiveRecord::Callbacks GetText Parser 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 ActiveRecord::Validations 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 ClassMethods Normalizable Attributes Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Configuration ClassMethods ObjectClass ClassMethods Callbacks lib/active_ldap/get_text/parser.rb GetText lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb lib/active_ldap/adapter/jndi.rb Adapter Validations GetTextFallback Helper 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 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

[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 150
150:       def delete(dn)
151:         @context.destroy_subcontext(dn)
152:       end

[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

[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

[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:         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

[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 179
179:       def ldap_uri
180:         protocol = @method == :ssl ? "ldaps" : "ldap"
181:         "#{protocol}://#{@host}:#{@port}/"
182:       end

[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

[Validate]