Class: Treequel::Directory
- Inherits:
-
Object
- Object
- Treequel::Directory
- Extends:
- Delegation
- Includes:
- Constants, HashUtilities, Loggable
- Defined in:
- lib/treequel/directory.rb
Overview
The object in Treequel that represents a connection to a directory, the binding to that directory, and the base from which all DNs start.
Constant Summary
- DEFAULT_OPTIONS =
The default directory options
{ :host => 'localhost', :port => LDAP::LDAP_PORT, :connect_type => :tls, :base_dn => nil, :bind_dn => nil, :pass => nil }
- DEFAULT_SYNTAX_MAPPING =
Default mapping of SYNTAX OIDs to conversions. See #add_syntax_mapping for more information on what a valid conversion is.
{ OIDS::BIT_STRING_SYNTAX => lambda {|bs| bs[0..-1].to_i(2) }, OIDS::BOOLEAN_SYNTAX => { 'TRUE' => true, 'FALSE' => false }, OIDS::GENERALIZED_TIME_SYNTAX => lambda {|string| Time.parse(string) }, OIDS::UTC_TIME_SYNTAX => lambda {|string| Time.parse(string) }, OIDS::INTEGER_SYNTAX => lambda {|string| Integer(string) }, }
- SEARCH_PARAMETER_ORDER =
The order in which hash arguments should be extracted from Hash parameters to #search
[ :selectattrs, :attrsonly, :server_controls, :client_controls, :timeout_s, :timeout_us, :limit, :sort_attribute, :sort_func, ].freeze
- SEARCH_DEFAULTS =
Default values to pass to LDAP::Conn#search_ext2; they’ll be passed in the order specified by SEARCH_PARAMETER_ORDER.
{ :selectattrs => ['*'], :attrsonly => false, :server_controls => nil, :client_controls => nil, :timeout => 0, :limit => 0, :sortby => nil, }.freeze
- DELEGATED_BRANCH_METHODS =
The methods that get delegated to the directory’s #base branch.
Treequel::Branch.instance_methods(false).collect {
Constants included from Loggable
Constants included from Constants
CONTROL_NAMES, CONTROL_OIDS, EXTENSION_NAMES, EXTENSION_OIDS, FEATURE_NAMES, FEATURE_OIDS, SCOPE, SCOPE_NAME
Instance Attribute Summary
-
- (String) base_dn
The base DN of the directory.
-
- (String) bound_user
readonly
The DN of the user the directory is bound as.
-
- (Symbol) connect_type
The type of connection to establish.
-
- (String) host
The host to connect to.
-
- (Fixnum) port
The port to connect to.
-
- (Array<Module>) registered_controls
readonly
The control modules that are registered with the directory.
Instance Method Summary
-
- (Object) add_syntax_mapping(oid, conversion = nil)
Add conversion mapping for the specified oid.
-
- (Treequel::Branch) base
Fetch the Branch for the base node of the directory.
-
- (void) bind(user_dn, password)
(also: #bind_as)
Bind as the specified user_dn and password.
- - (Object) bind_as
-
- (Boolean) bound?
(also: #is_bound?)
Returns true if the directory’s connection is already bound to the directory.
- - (Object) bound_as(user_dn, password)
-
- (LDAP::Conn, LDAP::SSLConn) conn
Return the LDAP::Conn object associated with this directory, creating it with the current options if necessary.
-
- (Object) connect
protected
Create a new LDAP::Conn object with the current host, port, and connect_type and return it.
-
- (Object) convert_syntax_value(oid, value)
Map the specified value to its Ruby datatype if one is registered for the given syntax oid.
-
- (Object) create(branch, newattrs = {})
Create the entry for the given branch, setting its attributes to newattrs.
-
- (Object) delete(branch)
Delete the entry specified by the given branch.
-
- (Object) get_default_base_dn
protected
Fetch the default base dn for the server from the server’s Root DSE.
-
- (Object) get_entry(branch)
Given a Treequel::Branch object, find its corresponding LDAP::Entry and return it.
-
- (Object) get_extended_entry(branch)
Given a Treequel::Branch object, find its corresponding LDAP::Entry and return it with its operational attributes (tools.ietf.org/html/rfc4512#section-3.4) included.
-
- (Directory) initialize(options = {})
constructor
Create a new Treequel::Directory with the given options.
-
- (String) inspect
Return a human-readable representation of the object suitable for debugging.
- - (Object) is_bound?
-
- (Object) method_missing(attribute, *args)
protected
Delegate attribute/value calls on the directory itself to the directory’s #base Branch.
-
- (Object) modify(branch, mods)
Modify the entry specified by the given dn with the specified mods, which can be either an Array of LDAP::Mod objects or a Hash of attribute/value pairs.
-
- (Object) move(branch, newdn)
Move the entry from the specified branch to the new entry specified by newdn.
-
- (Object) normalize_attributes(hash)
protected
Normalize the attributes in hash to be of the form expected by the LDAP library (i.e., keys as Strings, values as Arrays of Strings).
-
- (Object) normalize_search_parameters(base, scope, filter, parameters)
protected
Normalize the parameters to the #search method into the format expected by the LDAP::Conn#Search_ext2 method and return them as a Hash.
-
- (Object) rdn_to(dn)
Return the RDN string to the given dn from the base of the directory.
-
- (Object) register_controls(*modules)
Register the specified modules.
-
- (Object) schema
Fetch the schema from the server.
-
- (Array) search(base, scope = :subtree, filter = '(objectClass=*)', options = {}) {|branch| ... }
Perform a scope search at base using the specified filter.
-
- (Object) supported_control_oids
Return an Array of OID strings representing the controls supported by the Directory, as listed in the directory’s root DSE.
-
- (Object) supported_controls
Return an Array of Symbols for the controls supported by the Directory, as listed in the directory’s root DSE.
-
- (Object) supported_extension_oids
Return an Array of OID strings representing the extensions supported by the Directory, as listed in the directory’s root DSE.
-
- (Object) supported_extensions
Return an Array of Symbols for the extensions supported by the Directory, as listed in the directory’s root DSE.
-
- (Object) supported_feature_oids
Return an Array of OID strings representing the features supported by the Directory, as listed in the directory’s root DSE.
-
- (Object) supported_features
Return an Array of Symbols for the features supported by the Directory, as listed in the directory’s root DSE.
-
- (String) to_s
Returns a string that describes the directory.
-
- (void) unbind
Ensure that the the receiver’s connection is unbound.
-
- (URI::LDAP) uri
Return the URI object that corresponds to the directory.
-
- (Object) with_duplicate_conn
protected
Execute a block with a copy of the current connection, restoring the original after the block returns.
Methods included from Delegation
def_ivar_delegators, def_method_delegators
Methods included from Loggable
#initialize_copy, #log, #log_debug
Methods included from HashUtilities
#internify_keys, #merge_recursively, #stringify_keys, #symbolify_keys
Constructor Details
- (Directory) initialize(options = {})
Create a new Treequel::Directory with the given options. Options is a hash with one or more of the following key-value pairs:
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/treequel/directory.rb', line 105 def initialize( ={} ) = DEFAULT_OPTIONS.merge( ) @host = [:host] @port = [:port] @connect_type = [:connect_type] @conn = nil @bound_user = nil @base_dn = [:base_dn] || self.get_default_base_dn @base = nil @syntax_mapping = DEFAULT_SYNTAX_MAPPING.dup @registered_controls = [] # Immediately bind if credentials are passed to the initializer. if ( [:bind_dn] && [:pass] ) self.bind( [:bind_dn], [:pass] ) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(attribute, *args) (protected)
Delegate attribute/value calls on the directory itself to the directory’s #base Branch.
591 592 593 |
# File 'lib/treequel/directory.rb', line 591 def method_missing( attribute, *args ) return self.base.send( attribute, *args ) end |
Instance Attribute Details
- (String) base_dn
The base DN of the directory
154 155 156 |
# File 'lib/treequel/directory.rb', line 154 def base_dn @base_dn end |
- (String) bound_user (readonly)
The DN of the user the directory is bound as
162 163 164 |
# File 'lib/treequel/directory.rb', line 162 def bound_user @bound_user end |
- (Symbol) connect_type
The type of connection to establish
150 151 152 |
# File 'lib/treequel/directory.rb', line 150 def connect_type @connect_type end |
- (String) host
The host to connect to.
142 143 144 |
# File 'lib/treequel/directory.rb', line 142 def host @host end |
- (Fixnum) port
The port to connect to.
146 147 148 |
# File 'lib/treequel/directory.rb', line 146 def port @port end |
- (Array<Module>) registered_controls (readonly)
The control modules that are registered with the directory
158 159 160 |
# File 'lib/treequel/directory.rb', line 158 def registered_controls @registered_controls end |
Instance Method Details
- (Object) add_syntax_mapping(oid, conversion = nil)
Add conversion mapping for the specified oid. A conversion is any object that responds to #[] with a String argument(e.g., Proc, Method, Hash); the argument is the raw value String returned from the LDAP entry, and it should return the converted value. Adding a mapping with a nil conversion effectively clears it.
502 503 504 505 |
# File 'lib/treequel/directory.rb', line 502 def add_syntax_mapping( oid, conversion=nil ) conversion = Proc.new if block_given? @syntax_mapping[ oid ] = conversion end |
- (Treequel::Branch) base
Fetch the Branch for the base node of the directory.
167 168 169 |
# File 'lib/treequel/directory.rb', line 167 def base return @base ||= Treequel::Branch.new( self, self.base_dn ) end |
- (void) bind(user_dn, password) Also known as: bind_as
This method returns an undefined value.
Bind as the specified user_dn and password.
229 230 231 232 233 234 235 |
# File 'lib/treequel/directory.rb', line 229 def bind( user_dn, password ) user_dn = user_dn.dn if user_dn.respond_to?( :dn ) self.log.info "Binding with connection %p as: %s" % [ self.conn, user_dn ] self.conn.bind( user_dn.to_s, password ) @bound_user = user_dn.to_s end |
- (Object) bind_as
236 237 238 239 240 241 242 |
# File 'lib/treequel/directory.rb', line 236 def bind( user_dn, password ) user_dn = user_dn.dn if user_dn.respond_to?( :dn ) self.log.info "Binding with connection %p as: %s" % [ self.conn, user_dn ] self.conn.bind( user_dn.to_s, password ) @bound_user = user_dn.to_s end |
- (Boolean) bound? Also known as: is_bound?
Returns true if the directory’s connection is already bound to the directory.
259 260 261 |
# File 'lib/treequel/directory.rb', line 259 def bound? return self.conn.bound? end |
- (Object) bound_as(user_dn, password)
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/treequel/directory.rb', line 245 def bound_as( user_dn, password ) raise LocalJumpError, "no block given" unless block_given? previous_bind_dn = @bound_user self.with_duplicate_conn do self.bind( user_dn, password ) yield end ensure @bound_user = previous_bind_dn end |
- (LDAP::Conn, LDAP::SSLConn) conn
Return the LDAP::Conn object associated with this directory, creating it with the current options if necessary.
204 205 206 |
# File 'lib/treequel/directory.rb', line 204 def conn return @conn ||= self.connect end |
- (Object) connect (protected)
Create a new LDAP::Conn object with the current host, port, and connect_type and return it.
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/treequel/directory.rb', line 598 def connect conn = nil case @connect_type when :tls self.log.debug "Connecting using TLS to %s:%d" % [ @host, @port ] conn = LDAP::SSLConn.new( @host, @port, true ) when :ssl self.log.debug "Connecting using SSL to %s:%d" % [ @host, @port ] conn = LDAP::SSLConn.new( @host, @port ) else self.log.debug "Connecting using an unencrypted connection to %s:%d" % [ @host, @port ] conn = LDAP::Conn.new( @host, @port ) end conn.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 ) conn.set_option( LDAP::LDAP_OPT_REFERRALS, LDAP::LDAP_OPT_OFF ) return conn end |
- (Object) convert_syntax_value(oid, value)
Map the specified value to its Ruby datatype if one is registered for the given syntax oid. If there is no conversion registered, just return the value as-is.
529 530 531 532 533 534 535 536 537 538 |
# File 'lib/treequel/directory.rb', line 529 def convert_syntax_value( oid, value ) self.log.debug "Converting value %p using the syntax rule for %p" % [ value, oid ] unless conversion = @syntax_mapping[ oid ] self.log.debug " ...no conversion, returning it as-is." return value end self.log.debug " ...found conversion: %p" % [ conversion ] return conversion[ value ] end |
- (Object) create(branch, newattrs = {})
Create the entry for the given branch, setting its attributes to newattrs.
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/treequel/directory.rb', line 448 def create( branch, newattrs={} ) newdn = branch.dn schema = self.schema # Merge RDN attributes with existing ones, combining any that exist in both self.log.debug "Smushing rdn attributes %p into %p" % [ branch.rdn_attributes, newdn ] newattrs.merge!( branch.rdn_attributes ) do |key, *values| values.flatten.uniq end normattrs = self.normalize_attributes( newattrs ) raise ArgumentError, "Can't create an entry with no objectClasses" unless normattrs.key?( 'objectClass' ) normattrs['objectClass'].each do |oc| raise ArgumentError, "No such objectClass #{oc.inspect}" unless schema.object_classes.key?(oc.to_sym) end raise ArgumentError, "Can't create an entry with no structural objectClass" unless normattrs['objectClass'].any? {|oc| schema.object_classes[oc.to_sym].structural? } self.log.debug "Creating an entry at %s with the attributes: %p" % [ newdn, normattrs ] self.conn.add( newdn, normattrs ) return true end |
- (Object) delete(branch)
Delete the entry specified by the given branch.
441 442 443 444 |
# File 'lib/treequel/directory.rb', line 441 def delete( branch ) self.log.info "Deleting %s from the directory." % [ branch ] self.conn.delete( branch.dn ) end |
- (Object) get_default_base_dn (protected)
Fetch the default base dn for the server from the server’s Root DSE.
621 622 623 624 625 |
# File 'lib/treequel/directory.rb', line 621 def get_default_base_dn dse = self.conn.root_dse return '' if dse.nil? || dse.empty? return dse.first['namingContexts'].first end |
- (Object) get_entry(branch)
Given a Treequel::Branch object, find its corresponding LDAP::Entry and return it.
288 289 290 291 292 293 294 |
# File 'lib/treequel/directory.rb', line 288 def get_entry( branch ) self.log.debug "Looking up entry for %p" % [ branch.dn ] return self.conn.search_ext2( branch.dn, SCOPE[:base], '(objectClass=*)' ).first rescue LDAP::ResultError => err self.log.info " search for %p failed: %s" % [ branch.dn, err. ] return nil end |
- (Object) get_extended_entry(branch)
Given a Treequel::Branch object, find its corresponding LDAP::Entry and return it with its operational attributes (tools.ietf.org/html/rfc4512#section-3.4) included.
302 303 304 305 306 307 308 |
# File 'lib/treequel/directory.rb', line 302 def get_extended_entry( branch ) self.log.debug "Looking up entry (with operational attributes) for %p" % [ branch.dn ] return self.conn.search_ext2( branch.dn, SCOPE[:base], '(objectClass=*)', %w[* +] ).first rescue LDAP::ResultError => err self.log.info " search for %p failed: %s" % [ branch.dn, err. ] return nil end |
- (String) inspect
Return a human-readable representation of the object suitable for debugging
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/treequel/directory.rb', line 187 def inspect return %{#<%s:0x%0x %s:%d (%s) base_dn=%p, bound as=%s, schema=%s>} % [ self.class.name, self.object_id / 2, self.host, self.port, @conn ? "connected" : "not connected", self.base_dn, @bound_user ? @bound_user.dump : "anonymous", @schema ? @schema.inspect : "(schema not loaded)", ] end |
- (Object) is_bound?
262 263 264 |
# File 'lib/treequel/directory.rb', line 262 def bound? return self.conn.bound? end |
- (Object) modify(branch, mods)
Modify the entry specified by the given dn with the specified mods, which can be either an Array of LDAP::Mod objects or a Hash of attribute/value pairs.
428 429 430 431 432 433 434 435 436 437 |
# File 'lib/treequel/directory.rb', line 428 def modify( branch, mods ) if mods.first.respond_to?( :mod_op ) self.log.debug "Modifying %s with LDAP mod objects: %p" % [ branch.dn, mods ] self.conn.modify( branch.dn, mods ) else normattrs = self.normalize_attributes( mods ) self.log.debug "Modifying %s with: %p" % [ branch.dn, normattrs ] self.conn.modify( branch.dn, normattrs ) end end |
- (Object) move(branch, newdn)
Move the entry from the specified branch to the new entry specified by newdn. Returns the (moved) branch object.
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/treequel/directory.rb', line 477 def move( branch, newdn ) source_rdn, source_parent_dn = branch.split_dn( 2 ) new_rdn, new_parent_dn = newdn.split( /\s*,\s*/, 2 ) if new_parent_dn.nil? new_parent_dn = source_parent_dn newdn = [new_rdn, new_parent_dn].join(',') end if new_parent_dn != source_parent_dn raise Treequel::Error, "can't (yet) move an entry to a new parent" end self.log.debug "Modrdn (move): %p -> %p within %p" % [ source_rdn, new_rdn, source_parent_dn ] self.conn.modrdn( branch.dn, new_rdn, true ) branch.dn = newdn end |
- (Object) normalize_attributes(hash) (protected)
Normalize the attributes in hash to be of the form expected by the LDAP library (i.e., keys as Strings, values as Arrays of Strings)
643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/treequel/directory.rb', line 643 def normalize_attributes( hash ) normhash = {} hash.each do |key,val| val = [ val ] unless val.is_a?( Array ) val.collect! {|obj| obj.to_s } normhash[ key.to_s ] = val end normhash.delete( 'dn' ) return normhash end |
- (Object) normalize_search_parameters(base, scope, filter, parameters) (protected)
Normalize the parameters to the #search method into the format expected by the LDAP::Conn#Search_ext2 method and return them as a Hash.
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'lib/treequel/directory.rb', line 660 def normalize_search_parameters( base, scope, filter, parameters ) search_paramhash = SEARCH_DEFAULTS.merge( parameters ) # Use the DN of the base object if it's an object that knows what a DN is base = base.dn if base.respond_to?( :dn ) scope = SCOPE[scope.to_sym] if scope.respond_to?( :to_sym ) && SCOPE.key?( scope.to_sym ) filter = filter.to_s # Split seconds and microseconds from the timeout value, convert the # fractional part to µsec timeout = search_paramhash.delete( :timeout ) || 0 search_paramhash[:timeout_s] = timeout.truncate search_paramhash[:timeout_us] = Integer((timeout - timeout.truncate) * 1_000_000) ### Sorting in Ruby-LDAP is not significantly more useful than just sorting ### the returned entries from Ruby, as it happens client-side anyway (i.e., entries ### are still returned from the server in arbitrary/insertion order, and then the client ### sorts those search_paramhash[:sort_func] = nil search_paramhash[:sort_attribute] = '' return base, scope, filter, search_paramhash end |
- (Object) rdn_to(dn)
Return the RDN string to the given dn from the base of the directory.
278 279 280 281 |
# File 'lib/treequel/directory.rb', line 278 def rdn_to( dn ) base_re = Regexp.new( ',' + Regexp.quote(self.base_dn) + '$' ) return dn.to_s.sub( base_re, '' ) end |
- (Object) register_controls(*modules)
Register the specified modules
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/treequel/directory.rb', line 509 def register_controls( *modules ) dse = self.conn.root_dse.first supported_controls = dse['supportedControl'] modules.each do |mod| oid = mod.const_get( :OID ) if mod.const_defined?( :OID ) raise NotImplementedError, "%s doesn't define an OID" % [ mod.name ] if oid.nil? if supported_controls.include?( oid ) @registered_controls << mod else raise Treequel::UnsupportedControl, "%s is not supported by %s" % [ mod.name, self.uri ] end end end |
- (Object) schema
Fetch the schema from the server.
312 313 314 315 316 317 318 319 |
# File 'lib/treequel/directory.rb', line 312 def schema unless @schema schemahash = self.conn.schema @schema = Treequel::Schema.new( schemahash ) end return @schema end |
- (Array) search(base, scope = :subtree, filter = '(objectClass=*)', options = {}) {|branch| ... }
Perform a scope search at base using the specified filter.
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/treequel/directory.rb', line 367 def search( base, scope=:subtree, filter='(objectClass=*)', ={} ) collectclass = nil # If the base argument is an object whose class knows how to create instances of itself # from an LDAP::Entry, use it instead of Treequel::Branch to wrap results if .key?( :results_class ) collectclass = .delete( :results_class ) else collectclass = base.class.respond_to?( :new_from_entry ) ? base.class : Treequel::Branch end # Format the arguments in the way #search_ext2 expects them base_dn, scope, filter, searchopts = self.normalize_search_parameters( base, scope, filter, ) # Unwrap the search options from the hash in the correct order self.log.debug { attrlist = SEARCH_PARAMETER_ORDER.inject([]) do |list, param| list << "%s: %p" % [ param, searchopts[param] ] end "searching with base: %p, scope: %p, filter: %p, %s" % [ base_dn, scope, filter, attrlist.join(', ') ] } parameters = searchopts.values_at( *SEARCH_PARAMETER_ORDER ) # Wrap each result in the class derived from the 'base' argument self.log.debug "Searching via search_ext2 with arguments: %p" % [[ base_dn, scope, filter, *parameters ]] results = [] self.conn.search_ext2( base_dn, scope, filter, *parameters ).each do |entry| branch = collectclass.new_from_entry( entry, self ) branch.include_operational_attrs = base.include_operational_attrs? if base.respond_to?( :include_operational_attrs? ) if block_given? results << yield( branch ) else results << branch end end return results rescue RuntimeError => err conn = self.conn # The LDAP library raises a plain RuntimeError with an incorrect message if the # connection goes away, so it's caught here to rewrap it case err. when /no result returned by search/i raise LDAP::ResultError.new( LDAP.err2string(conn.err) ) else raise end end |
- (Object) supported_control_oids
Return an Array of OID strings representing the controls supported by the Directory, as listed in the directory’s root DSE.
551 552 553 |
# File 'lib/treequel/directory.rb', line 551 def supported_control_oids return self.conn.root_dse.first['supportedControl'] end |
- (Object) supported_controls
Return an Array of Symbols for the controls supported by the Directory, as listed in the directory’s root DSE. Any controls which aren’t known (i.e., don’t have an entry in Treequel::Constants::CONTROL_NAMES), the numeric OID will be returned as-is.
544 545 546 |
# File 'lib/treequel/directory.rb', line 544 def supported_controls return self.supported_control_oids.collect {|oid| CONTROL_NAMES[oid] || oid } end |
- (Object) supported_extension_oids
Return an Array of OID strings representing the extensions supported by the Directory, as listed in the directory’s root DSE.
566 567 568 |
# File 'lib/treequel/directory.rb', line 566 def supported_extension_oids return self.conn.root_dse.first['supportedExtension'] end |
- (Object) supported_extensions
Return an Array of Symbols for the extensions supported by the Directory, as listed in the directory’s root DSE. Any extensions which aren’t known (i.e., don’t have an entry in Treequel::Constants::EXTENSION_NAMES), the numeric OID will be returned as-is.
559 560 561 |
# File 'lib/treequel/directory.rb', line 559 def supported_extensions return self.supported_extension_oids.collect {|oid| EXTENSION_NAMES[oid] || oid } end |
- (Object) supported_feature_oids
Return an Array of OID strings representing the features supported by the Directory, as listed in the directory’s root DSE.
581 582 583 |
# File 'lib/treequel/directory.rb', line 581 def supported_feature_oids return self.conn.root_dse.first['supportedFeatures'] end |
- (Object) supported_features
Return an Array of Symbols for the features supported by the Directory, as listed in the directory’s root DSE. Any features which aren’t known (i.e., don’t have an entry in Treequel::Constants::FEATURE_NAMES), the numeric OID will be returned as-is.
574 575 576 |
# File 'lib/treequel/directory.rb', line 574 def supported_features return self.supported_feature_oids.collect {|oid| FEATURE_NAMES[oid] || oid } end |
- (String) to_s
Returns a string that describes the directory
174 175 176 177 178 179 180 181 182 |
# File 'lib/treequel/directory.rb', line 174 def to_s return "%s:%d (%s, %s, %s)" % [ self.host, self.port, self.base_dn, self.connect_type, self.bound? ? @bound_user : 'anonymous' ] end |
- (void) unbind
This method returns an undefined value.
Ensure that the the receiver’s connection is unbound.
267 268 269 270 271 272 273 |
# File 'lib/treequel/directory.rb', line 267 def unbind if @conn.bound? old_conn = @conn @conn = old_conn.dup old_conn.unbind end end |
- (URI::LDAP) uri
Return the URI object that corresponds to the directory.
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/treequel/directory.rb', line 211 def uri uri_parts = { :scheme => self.connect_type == :ssl ? 'ldaps' : 'ldap', :host => self.host, :port => self.port, :dn => '/' + self.base_dn } return URI::LDAP.build( uri_parts ) end |
- (Object) with_duplicate_conn (protected)
Execute a block with a copy of the current connection, restoring the original after the block returns.
630 631 632 633 634 635 636 637 638 |
# File 'lib/treequel/directory.rb', line 630 def with_duplicate_conn original_conn = self.conn @conn = original_conn.dup self.log.info "Executing with %p, a copy of connection %p" % [ @conn, original_conn ] yield ensure self.log.info " restoring original connection %p." % [ original_conn ] @conn = original_conn end |