Class: ActiveLdap::Adapter::JndiConnection
- Inherits:
-
Object
- Object
- ActiveLdap::Adapter::JndiConnection
show all
- Defined in:
- lib/active_ldap/adapter/jndi_connection.rb
Defined Under Namespace
Modules: Scope
Classes: ModifyRecord
Constant Summary
- 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
- CommunicationException =
naming.CommunicationException
- ServiceUnavailableException =
naming.ServiceUnavailableException
- NamingException =
naming.NamingException
- NameNotFoundException =
naming.NameNotFoundException
Instance Method Summary
collapse
-
#add(dn, records) ⇒ Object
-
#bind_as_anonymous ⇒ Object
-
#bound? ⇒ Boolean
-
#delete(dn) ⇒ Object
-
#initialize(host, port, method, timeout) ⇒ JndiConnection
constructor
A new instance of JndiConnection.
-
#modify(dn, records) ⇒ Object
-
#modify_rdn(dn, new_rdn, delete_old_rdn) ⇒ Object
-
#sasl_bind(bind_dn, mechanism, quiet) ⇒ Object
-
#search(base, scope, filter, attrs, limit) ⇒ Object
-
#simple_bind(bind_dn, password) ⇒ Object
-
#unbind ⇒ Object
Constructor Details
#initialize(host, port, method, timeout) ⇒ JndiConnection
Returns a new instance of JndiConnection
76
77
78
79
80
81
82
83
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 76
def initialize(host, port, method, timeout)
@host = host
@port = port
@method = method
@timeout = timeout
@context = nil
@tls = nil
end
|
Instance Method Details
#add(dn, records) ⇒ Object
131
132
133
134
135
136
137
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 131
def add(dn, records)
attributes = BasicAttributes.new
records.each do |record|
attributes.put(record.to_java_attribute)
end
@context.create_subcontext(dn, attributes)
end
|
#bind_as_anonymous ⇒ Object
106
107
108
109
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 106
def bind_as_anonymous
setup_context(nil, nil, "none")
bound?
end
|
#bound? ⇒ Boolean
92
93
94
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 92
def bound?
not @context.nil?
end
|
#delete(dn) ⇒ Object
153
154
155
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 153
def delete(dn)
@context.destroy_subcontext(dn)
end
|
#modify(dn, records) ⇒ Object
139
140
141
142
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 139
def modify(dn, records)
items = records.collect(&:to_java_modification_item)
@context.modify_attributes(dn, items.to_java(ModificationItem))
end
|
#modify_rdn(dn, new_rdn, delete_old_rdn) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 144
def modify_rdn(dn, new_rdn, delete_old_rdn)
delete_rdn_key = "java.naming.ldap.deleteRDN"
@context.add_to_environment(delete_rdn_key, delete_old_rdn.to_s)
@context.rename(dn, new_rdn)
ensure
@context.remove_from_environment(delete_rdn_key)
end
|
#sasl_bind(bind_dn, mechanism, quiet) ⇒ Object
96
97
98
99
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 96
def sasl_bind(bind_dn, mechanism, quiet)
setup_context(bind_dn, password, mechanism)
bound?
end
|
#search(base, scope, filter, attrs, limit) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 111
def search(base, scope, filter, attrs, limit)
controls = SearchControls.new
controls.search_scope = scope
controls.count_limit = limit if limit
unless attrs.blank?
controls.returning_attributes = attrs.to_java(:string)
end
@context.search(base, filter, controls).each do |result|
attributes = {}
result.attributes.get_all.each do |attribute|
attributes[attribute.get_id] = attribute.get_all.collect do |value|
value.is_a?(String) ? value : String.from_java_bytes(value)
end
end
yield([result.name_in_namespace, attributes])
end
end
|
#simple_bind(bind_dn, password) ⇒ Object
101
102
103
104
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 101
def simple_bind(bind_dn, password)
setup_context(bind_dn, password, "simple")
bound?
end
|
#unbind ⇒ Object
85
86
87
88
89
90
|
# File 'lib/active_ldap/adapter/jndi_connection.rb', line 85
def unbind
@tls.close if @tls
@tls = nil
@context.close if @context
@context = nil
end
|