ruby-activeldap-debug 0.5.9 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/activeldap/associations.rb +19 -13
- data/lib/activeldap/base.rb +56 -39
- data/lib/activeldap/configuration.rb +1 -1
- data/lib/activeldap.rb +1 -1
- metadata +2 -2
@@ -82,7 +82,11 @@ module ActiveLDAP
|
|
82
82
|
def #{association_id}(objects = true)
|
83
83
|
local_key = "#{local_key}"
|
84
84
|
local_key = dnattr() if local_key.empty?
|
85
|
-
|
85
|
+
results = []
|
86
|
+
#{klass}.find_all(:attribute => "#{key}", :value => send(local_key.to_sym), :objects => objects).each do |o|
|
87
|
+
results << o
|
88
|
+
end
|
89
|
+
return results
|
86
90
|
end
|
87
91
|
end_eval
|
88
92
|
end
|
@@ -110,18 +114,20 @@ module ActiveLDAP
|
|
110
114
|
foreign_key = dnattr()
|
111
115
|
end
|
112
116
|
results = []
|
113
|
-
@data["#{key}"].
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
117
|
+
unless @data["#{key}"].nil?
|
118
|
+
@data["#{key}"].each do |item|
|
119
|
+
fkey = ""
|
120
|
+
if foreign_key == "dn" and not item.empty?
|
121
|
+
fkey = item.split(',')[0].split('=')[0]
|
122
|
+
item = item.split(',')[0].split('=')[1]
|
123
|
+
end
|
124
|
+
# This will even yield entries that don't necessarily exist
|
125
|
+
if foreign_key != "dn"
|
126
|
+
fkey = foreign_key
|
127
|
+
end
|
128
|
+
#{klass}.find_all(:attribute => fkey, :value => item, :objects => objects).each do |match|
|
129
|
+
results << match
|
130
|
+
end
|
125
131
|
end
|
126
132
|
end
|
127
133
|
return results
|
data/lib/activeldap/base.rb
CHANGED
@@ -80,6 +80,13 @@ module ActiveLDAP
|
|
80
80
|
class ObjectClassError < RuntimeError
|
81
81
|
end
|
82
82
|
|
83
|
+
# AttributeAssignmentError
|
84
|
+
#
|
85
|
+
# An exception raised when there is an issue assigning a value to
|
86
|
+
# an attribute
|
87
|
+
class AttributeAssignmentError < RuntimeError
|
88
|
+
end
|
89
|
+
|
83
90
|
|
84
91
|
# Base
|
85
92
|
#
|
@@ -408,7 +415,8 @@ module ActiveLDAP
|
|
408
415
|
tries = 0
|
409
416
|
begin
|
410
417
|
# Get some attributes
|
411
|
-
@@conn.search(base(), LDAP::LDAP_SCOPE_ONELEVEL,
|
418
|
+
@@conn.search(base(), LDAP::LDAP_SCOPE_ONELEVEL,
|
419
|
+
"(#{attr}=#{val})") do |m|
|
412
420
|
# Extract the dnattr value
|
413
421
|
dnval = m.dn.split(/,/)[0].split(/=/)[1]
|
414
422
|
|
@@ -488,7 +496,8 @@ module ActiveLDAP
|
|
488
496
|
# val can be a dn attribute value, a full DN, or a LDAP::Entry. The use
|
489
497
|
# with a LDAP::Entry is primarily meant for internal use by find and
|
490
498
|
# find_all.
|
491
|
-
def initialize(val
|
499
|
+
def initialize(val)
|
500
|
+
@exists = false
|
492
501
|
# Try a default connection if none made explicitly
|
493
502
|
unless Base.connection
|
494
503
|
# Use @@config if it has been prepopulated and the conn is down.
|
@@ -526,17 +535,19 @@ module ActiveLDAP
|
|
526
535
|
end
|
527
536
|
|
528
537
|
# Do a search - if it exists, pull all data and parse schema, if not, just set the hierarchical data
|
529
|
-
if val.empty?
|
530
|
-
|
531
|
-
|
538
|
+
if val.class != String or val.empty?
|
539
|
+
raise TypeError, 'a dn attribute String must be supplied ' +
|
540
|
+
'on initialization'
|
541
|
+
else
|
542
|
+
# Create what should be the authoritative DN
|
532
543
|
@dn = "#{dnattr()}=#{val},#{base()}"
|
533
|
-
|
534
|
-
else # do a search then
|
544
|
+
|
535
545
|
# Search for the existing entry
|
536
546
|
tries = 0
|
537
547
|
begin
|
538
548
|
# Get some attributes
|
539
549
|
Base.connection.search(base(), LDAP::LDAP_SCOPE_ONELEVEL, "(#{dnattr()}=#{val})") do |m|
|
550
|
+
@exists = true
|
540
551
|
# Save DN
|
541
552
|
@dn = m.dn
|
542
553
|
# Load up data into tmp
|
@@ -556,44 +567,42 @@ module ActiveLDAP
|
|
556
567
|
end
|
557
568
|
end
|
558
569
|
end
|
559
|
-
@exists = true
|
560
|
-
# Populate schema data
|
561
|
-
send(:apply_objectclass, @ldap_data['objectClass'])
|
562
|
-
|
563
|
-
# Populate real data now that we have the schema with aliases
|
564
|
-
@ldap_data.each do |pair|
|
565
|
-
send(:attribute_method=, pair[0], pair[1].dup)
|
566
|
-
end
|
567
570
|
rescue RuntimeError => detail
|
568
571
|
#todo# check for 'no message' when retrying
|
569
572
|
# the connection may have gone stale. let's reconnect and retry.
|
570
|
-
if tries
|
571
|
-
|
572
|
-
#
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
@@logger.debug("new: setting dnattr: #{dnattr()} = #{val}")
|
579
|
-
send(attr_sym, val)
|
573
|
+
if tries <= @@config[:retries]
|
574
|
+
tries += 1
|
575
|
+
# reconnect and rebind.
|
576
|
+
do_connect()
|
577
|
+
retry
|
578
|
+
else
|
579
|
+
@@logger.error('new: unable to search for entry')
|
580
|
+
raise detail
|
580
581
|
end
|
581
|
-
tries += 1
|
582
|
-
# reconnect and rebind.
|
583
|
-
do_connect()
|
584
|
-
retry
|
585
582
|
rescue LDAP::ResultError
|
586
|
-
@exists = false
|
587
|
-
# Create what should be the authoritative DN
|
588
|
-
@dn = "#{dnattr()}=#{val},#{base()}"
|
589
|
-
send(:apply_objectclass, required_classes())
|
590
|
-
|
591
|
-
# Setup dn attribute (later rdn too!)
|
592
|
-
attr_sym = "#{dnattr()}=".to_sym
|
593
|
-
@@logger.debug("new: setting dnattr: #{dnattr()} = #{val}")
|
594
|
-
send(attr_sym, val)
|
595
583
|
end
|
596
584
|
end
|
585
|
+
|
586
|
+
# Do the actual object setup work.
|
587
|
+
if @exists
|
588
|
+
# Populate schema data
|
589
|
+
send(:apply_objectclass, @ldap_data['objectClass'])
|
590
|
+
|
591
|
+
# Populate real data now that we have the schema with aliases
|
592
|
+
@ldap_data.each do |pair|
|
593
|
+
real_attr = @attr_methods[pair[0]]
|
594
|
+
@@logger.debug("new: #{pair[0].inspect} method maps to #{real_attr}")
|
595
|
+
@data[real_attr] = pair[1].dup
|
596
|
+
@@logger.debug("new: #{real_attr} set to #{pair[1]}")
|
597
|
+
end
|
598
|
+
else
|
599
|
+
send(:apply_objectclass, required_classes())
|
600
|
+
|
601
|
+
# Setup dn attribute (later rdn too!)
|
602
|
+
real_dnattr = @attr_methods[dnattr()]
|
603
|
+
@data[real_dnattr] = val
|
604
|
+
@@logger.debug("new: setting dnattr: #{real_dnattr} = #{val}")
|
605
|
+
end
|
597
606
|
end # initialize
|
598
607
|
|
599
608
|
# Hide new in Base
|
@@ -961,7 +970,10 @@ module ActiveLDAP
|
|
961
970
|
|
962
971
|
# Populate real data now that we have the schema with aliases
|
963
972
|
@ldap_data.each do |pair|
|
964
|
-
|
973
|
+
real_attr = @attr_methods[pair[0]]
|
974
|
+
@@logger.debug("new: #{pair[0].inspect} method maps to #{real_attr}")
|
975
|
+
@data[real_attr] = pair[1].dup
|
976
|
+
@@logger.debug("new: #{real_attr} set to #{pair[1]}")
|
965
977
|
end
|
966
978
|
end # import
|
967
979
|
|
@@ -1291,6 +1303,11 @@ module ActiveLDAP
|
|
1291
1303
|
attr = @attr_methods[method]
|
1292
1304
|
@@logger.debug("attribute_method=(#{method.inspect}, #{value.inspect}): method maps to #{attr}")
|
1293
1305
|
|
1306
|
+
# Check if it is the DN attribute
|
1307
|
+
if dnattr() == attr
|
1308
|
+
raise AttributeAssignmentError, 'cannot modify the DN attribute value'
|
1309
|
+
end
|
1310
|
+
|
1294
1311
|
# Assign the value
|
1295
1312
|
@data[attr] = value
|
1296
1313
|
|
data/lib/activeldap.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-activeldap-debug
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date:
|
6
|
+
version: 0.6.0
|
7
|
+
date: 2006-01-09
|
8
8
|
summary: Ruby/ActiveLDAP is a object-oriented API to LDAP
|
9
9
|
require_paths:
|
10
10
|
- lib
|