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 ConnectionNotEstablished TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError DistinguishedNameInvalid 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 Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb 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_44_0.png

Methods

Classes and Modules

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 68
68:       def initialize(host, port, method)
69:         @host = host
70:         @port = port
71:         @method = method
72:         @context = nil
73:         @tls = nil
74:       end

Public Instance methods

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 124
124:       def add(dn, records)
125:         attributes = BasicAttributes.new
126:         records.each do |record|
127:           attributes.put(record.to_java_attribute)
128:         end
129:         @context.create_subcontext(dn, attributes)
130:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 97
 97:       def bind_as_anonymous
 98:         setup_context(nil, nil, "none")
 99:         bound?
100:       end

[Source]

    # File lib/active_ldap/adapter/jndi_connection.rb, line 83
83:       def bound?
84:         not @context.nil?
85:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 146
146:       def delete(dn)
147:         @context.destroy_subcontext(dn)
148:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 132
132:       def modify(dn, records)
133:         items = records.collect(&:to_java_modification_item)
134:         @context.modify_attributes(dn, items.to_java(ModificationItem))
135:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 137
137:       def modify_rdn(dn, new_rdn, delete_old_rdn)
138:         # should use mutex
139:         delete_rdn_key = "java.naming.ldap.deleteRDN"
140:         @context.add_to_environment(delete_rdn_key, delete_old_rdn.to_s)
141:         @context.rename(dn, new_rdn)
142:       ensure
143:         @context.remove_from_environment(delete_rdn_key)
144:       end

[Source]

    # File lib/active_ldap/adapter/jndi_connection.rb, line 87
87:       def sasl_bind(bind_dn, mechanism, quiet)
88:         setup_context(bind_dn, password, mechanism)
89:         bound?
90:       end

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 102
102:       def search(base, scope, filter, attrs, limit, callback, &block)
103:         controls = SearchControls.new
104:         controls.search_scope = scope
105: 
106:         unless attrs.blank?
107:           controls.returning_attributes = attrs.to_java(:string)
108:         end
109: 
110:         i = 0
111:         @context.search(base, filter, controls).each do |result|
112:           i += 1
113:           attributes = {}
114:           result.attributes.get_all.each do |attribute|
115:             attributes[attribute.get_id] = attribute.get_all.collect do |value|
116:               value.is_a?(String) ? value : String.from_java_bytes(value)
117:             end
118:           end
119:           callback.call([result.name_in_namespace, attributes], block)
120:           break if limit and limit <= i
121:         end
122:       end

[Source]

    # File lib/active_ldap/adapter/jndi_connection.rb, line 92
92:       def simple_bind(bind_dn, password)
93:         setup_context(bind_dn, password, "simple")
94:         bound?
95:       end

[Source]

    # File lib/active_ldap/adapter/jndi_connection.rb, line 76
76:       def unbind
77:         @tls.close if @tls
78:         @tls = nil
79:         @context.close if @context
80:         @context = nil
81:       end

Private Instance methods

[Source]

     # File lib/active_ldap/adapter/jndi_connection.rb, line 175
175:       def ldap_uri
176:         protocol = @method == :ssl ? "ldaps" : "ldap"
177:         "#{protocol}://#{@host}:#{@port}/"
178:       end

[Source]

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

[Validate]