ucb_ldap 2.0.0.pre1 → 2.0.0.pre3

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/CHANGELOG +137 -135
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/{README → README.md} +82 -80
  7. data/Rakefile +38 -20
  8. data/lib/ucb_ldap.rb +238 -204
  9. data/lib/{ucb_ldap_address.rb → ucb_ldap/address.rb} +106 -106
  10. data/lib/{ucb_ldap_affiliation.rb → ucb_ldap/affiliation.rb} +16 -16
  11. data/lib/{ucb_ldap_entry.rb → ucb_ldap/entry.rb} +455 -448
  12. data/lib/{ucb_ldap_person_job_appointment.rb → ucb_ldap/job_appointment.rb} +77 -79
  13. data/lib/{ucb_ldap_namespace.rb → ucb_ldap/namespace.rb} +40 -50
  14. data/lib/{ucb_ldap_org.rb → ucb_ldap/org.rb} +427 -429
  15. data/lib/{ucb_ldap_person.rb → ucb_ldap/person.rb} +157 -148
  16. data/lib/{person → ucb_ldap/person}/affiliation_methods.rb +23 -22
  17. data/lib/ucb_ldap/person/common_attributes.rb +63 -0
  18. data/lib/{ucb_ldap_schema.rb → ucb_ldap/schema.rb} +28 -28
  19. data/lib/{ucb_ldap_schema_attribute.rb → ucb_ldap/schema_attribute.rb} +152 -153
  20. data/lib/{ucb_ldap_service.rb → ucb_ldap/service.rb} +17 -19
  21. data/lib/{ucb_ldap_student_term.rb → ucb_ldap/student_term.rb} +29 -31
  22. data/lib/ucb_ldap/version.rb +3 -0
  23. data/spec/rails_binds.yml +9 -0
  24. data/spec/spec_helper.rb +43 -0
  25. data/spec/ucb_ldap/address_spec.rb +54 -0
  26. data/spec/ucb_ldap/affiliation_spec.rb +85 -0
  27. data/spec/ucb_ldap/entry_spec.rb +241 -0
  28. data/spec/ucb_ldap/job_appointment_spec.rb +65 -0
  29. data/spec/ucb_ldap/namespace_spec.rb +72 -0
  30. data/spec/ucb_ldap/org_spec.rb +217 -0
  31. data/spec/ucb_ldap/person_spec.rb +225 -0
  32. data/spec/ucb_ldap/schema_attribute_spec.rb +122 -0
  33. data/spec/ucb_ldap/schema_spec.rb +104 -0
  34. data/spec/ucb_ldap/service_spec.rb +127 -0
  35. data/spec/ucb_ldap/student_term_spec.rb +121 -0
  36. data/spec/ucb_ldap_spec.rb +182 -0
  37. data/ucb_ldap.gemspec +20 -27
  38. metadata +113 -64
  39. data/Manifest +0 -23
  40. data/TODO +0 -2
  41. data/lib/person/adv_con_person.rb +0 -0
  42. data/lib/person/generic_attributes.rb +0 -68
  43. data/lib/ucb_ldap_exceptions.rb +0 -27
  44. data/version.yml +0 -1
@@ -11,7 +11,7 @@ module UCB #:nodoc:
11
11
  # entities. Attributes are modeled as instances of UCB::LDAP::Schema::Attribute.
12
12
  #
13
13
  # Each entity (Person, Org, etc.) has a Hash of attributes where the keys are
14
- # canonical (see Entry.canonical) attribute/alias names
14
+ # canonical (see Entry.canonical) attribute/alias names
15
15
  # and the values are Schema::Attribute's.
16
16
  #
17
17
  # You don't have to explicitly load schema information; the UCB::LDAP module
@@ -20,64 +20,64 @@ module UCB #:nodoc:
20
20
  #
21
21
  # == Schema Source
22
22
  #
23
- # Schema information is loaded from a url defined by the
23
+ # Schema information is loaded from a url defined by the
24
24
  # SCHEMA_* constants. A version of the file is distributed
25
25
  # with this Gem and is used in case the web version is not accessible.
26
26
  #
27
27
  module Schema
28
-
28
+
29
29
  SCHEMA_BASE_URL = 'calnet.berkeley.edu'
30
30
  SCHEMA_CONTENT_PATH = '/developers/developerResources/yaml/schema/schema.yaml'
31
- SCHEMA_FILE = "#{File.dirname(__FILE__)}/../schema/schema.yml"
32
-
31
+ SCHEMA_FILE = "#{File.dirname(__FILE__)}/../../schema/schema.yml"
32
+
33
33
  class << self
34
-
35
- # Returns a hash of all attributes for all entities. Keys are
34
+
35
+ # Returns a hash of all attributes for all entities. Keys are
36
36
  # entity names, values hash of attributes for given entity.
37
37
  def schema_hash()
38
38
  @schema_hash ||= load_attributes
39
39
  end
40
-
40
+
41
41
  # Returns schema base url. Defaults to SCHEMA_BASE_URL constant.
42
- def schema_base_url()
42
+ def schema_base_url
43
43
  @schema_base_url || SCHEMA_BASE_URL
44
44
  end
45
-
45
+
46
46
  # Setter for schema_base_url(). Use this to override url of LDAP
47
47
  # schema information.
48
48
  def schema_base_url=(base_url)
49
49
  @schema_base_url = base_url
50
50
  end
51
-
51
+
52
52
  # Returns schema content path. Defaults to SCHEMA_CONTENT_PATH constant.
53
- def schema_content_path()
53
+ def schema_content_path
54
54
  @schema_content_path || SCHEMA_CONTENT_PATH
55
55
  end
56
-
56
+
57
57
  # Setter for schema_content_path(). Use this to override content path of LDAP
58
58
  # schema information.
59
59
  def schema_content_path=(content_path)
60
60
  @schema_content_path = content_path
61
61
  end
62
-
62
+
63
63
  # Returns schema file. Defaults fo SCHEMA_FILE constant.
64
- def schema_file()
64
+ def schema_file
65
65
  @schema_file || SCHEMA_FILE
66
66
  end
67
-
67
+
68
68
  # Setter for schema_file(). Use this to override location of
69
69
  # local schema file.
70
70
  def schema_file=(file)
71
71
  @schema_file = file
72
72
  end
73
-
73
+
74
74
  #private unless $TESTING
75
-
75
+
76
76
  # Setter for schema_hash()
77
77
  def schema_hash=(h) #:nodoc:
78
78
  @schema_hash = h
79
79
  end
80
-
80
+
81
81
  # Load attributes from URL or file
82
82
  def load_attributes #:nodoc:
83
83
  load_attributes_from_url
@@ -85,30 +85,30 @@ module UCB #:nodoc:
85
85
  puts "Warning: schema loading from file"
86
86
  load_attributes_from_file
87
87
  end
88
-
89
- def load_attributes_from_url() #:nodoc:
88
+
89
+ def load_attributes_from_url #:nodoc:
90
90
  self.schema_hash = YAML.load(yaml_from_url)
91
91
  end
92
-
93
- def yaml_from_url() #:nodoc:
92
+
93
+ def yaml_from_url #:nodoc:
94
94
  http = Net::HTTP.new(SCHEMA_BASE_URL, 443)
95
95
  http.use_ssl = true
96
96
  http.get(SCHEMA_CONTENT_PATH).body
97
97
  end
98
-
99
- def load_attributes_from_file() #:nodoc:
98
+
99
+ def load_attributes_from_file #:nodoc:
100
100
  self.schema_hash = YAML.load(yaml_from_file)
101
101
  end
102
102
 
103
103
  def yaml_from_file #:nodoc:
104
104
  IO.read(schema_file)
105
105
  end
106
-
106
+
107
107
  # Get instance variable w/o loading -- for testing purposes.
108
- def schema_hash_i() #:nodoc:
108
+ def schema_hash_i #:nodoc:
109
109
  @schema_hash
110
110
  end
111
-
111
+
112
112
  end
113
113
  end
114
114
  end
@@ -1,153 +1,152 @@
1
-
2
- module UCB
3
- module LDAP
4
- module Schema
5
- # = UCB::LDAP::SchemaAttribute
6
- #
7
- # This class models <em>schema</em> information about an LDAP attribute.
8
- #
9
- # This class is used internally by various UCB::LDAP classes.
10
- # Users of UCB::LDAP probably won't need to interact with this
11
- # class directly.
12
- #
13
- # The LDAP entity classes have access to their Attribute's.
14
- #
15
- # uid_attr = UCB::LDAP::Person.attribute(:uid) # :symbol ok as attribute name
16
- #
17
- # uid_attr.name #=> 'uid'
18
- # uid_attr.aliases #=> ['userid']
19
- # uid_attr.description #=> 'Standard LDAP attribute type'
20
- # uid_attr.multi_valued? #=> true
21
- # uid_attr.required? #=> true
22
- # uid_attr.type #=> 'string'
23
- #
24
- # uas_attr = UCB::LDAP::Person.attribute('berkeleyEduUasEligFlag') # case doesn't matter
25
- #
26
- # uas_attr.name #=> 'berkeleyEduUasEligFlag'
27
- # uas_attr.aliases #=> ['ucbvalidflag']
28
- # uas_attr.description #=> 'UAS Eligibility Flag'
29
- # uas_attr.multi_valued? #=> false
30
- # uas_attr.required? #=> false
31
- # uas_attr.type #=> 'boolean'
32
- #
33
- class Attribute
34
-
35
- # Constructor called by UCB::LDAP::Entry.set_schema_attributes().
36
- def initialize(args) #:nodoc:
37
- @name = args["name"]
38
- @type = args["syntax"]
39
- @aliases = args["aliases"] || []
40
- @description = args["description"]
41
- @required = args["required"]
42
- @multi_valued = args["multi"]
43
- end
44
-
45
- # Returns attribute name as found in the schema
46
- def name
47
- @name
48
- end
49
-
50
- # Returns Array of aliases as found in schema. Returns empty
51
- # Array ([]) if no aliases.
52
- #
53
- def aliases
54
- @aliases
55
- end
56
-
57
- # Returns (data) type. Used by get_value() to cast value to correct Ruby type.
58
- #
59
- # Supported types and corresponding Ruby type:
60
- #
61
- # * string String
62
- # * integer Fixnum
63
- # * boolean TrueClass / FalseClass
64
- # * timestamp DateTime (convenience methods may return Date if attribute's semantics don't include time)
65
- #
66
- def type
67
- @type
68
- end
69
-
70
- # Returns attribute description. Of limited value since all
71
- # standard LDAP attributes have a description of
72
- # "Standard LDAP attribute type".
73
- def description
74
- @description
75
- end
76
-
77
- # Returns <tt>true</tt> if attribute is required, else <tt>false</tt>
78
- def required?
79
- @required
80
- end
81
-
82
- # Returns <tt>true</tt> if attribute is multi-valued, else <tt>false</tt>.
83
- # Multi-valued attribute values are returned as an Array.
84
- def multi_valued?
85
- @multi_valued
86
- end
87
-
88
- # Takes a value returned from an LDAP attribute (+Array+ of +String+)
89
- # and returns value with correct cardinality (array or scalar)
90
- # cast to correct #type.
91
- def get_value(array)
92
- if array.nil?
93
- return false if boolean?
94
- return [] if multi_valued?
95
- return nil
96
- end
97
- typed_array = apply_type_to_array(array)
98
- multi_valued? ? typed_array : typed_array.first
99
- end
100
-
101
- # Cast each element to correct type.
102
- def apply_type_to_array(array) #:nodoc:
103
- array.map{|scalar| apply_type_to_scalar scalar}
104
- end
105
-
106
- # Case element to correct type
107
- def apply_type_to_scalar(string) #:nodoc:
108
- return string if string?
109
- return string.to_i if integer?
110
- return %w{true 1}.include?(string) ? true : false if boolean?
111
- return UCB::LDAP.local_datetime_parse(string) if timestamp?
112
- raise "unknown type '#{type}' for attribute '#{name}'"
113
- end
114
-
115
- # Return <tt>true</tt> if attribute type is string.
116
- def string?
117
- type == "string"
118
- end
119
-
120
- # Return <tt>true</tt> if attribute type is integer.
121
- def integer?
122
- type == "integer"
123
- end
124
-
125
- # Return <tt>true</tt> if attribute type is boolean.
126
- def boolean?
127
- type == "boolean"
128
- end
129
-
130
- # Return <tt>true</tt> if attribute type is timestamp
131
- def timestamp?
132
- type == "timestamp"
133
- end
134
-
135
- # Returns a value in LDAP attribute value format (+Array+ of +String+).
136
- def ldap_value(value)
137
- return nil if value.nil?
138
- return value.map{|v| ldap_value_stripped(v)} if value.instance_of?(Array)
139
- return [ldap_value_stripped(value)]
140
- end
141
-
142
- private
143
-
144
- # Remove leading/trailing white-space and imbedded newlines.
145
- def ldap_value_stripped(s)
146
- s.to_s.strip.gsub(/\n/,"")
147
- end
148
-
149
- end
150
-
151
- end
152
- end
153
- end
1
+ module UCB
2
+ module LDAP
3
+ module Schema
4
+ # = UCB::LDAP::SchemaAttribute
5
+ #
6
+ # This class models <em>schema</em> information about an LDAP attribute.
7
+ #
8
+ # This class is used internally by various UCB::LDAP classes.
9
+ # Users of UCB::LDAP probably won't need to interact with this
10
+ # class directly.
11
+ #
12
+ # The LDAP entity classes have access to their Attribute's.
13
+ #
14
+ # uid_attr = UCB::LDAP::Person.attribute(:uid) # :symbol ok as attribute name
15
+ #
16
+ # uid_attr.name #=> 'uid'
17
+ # uid_attr.aliases #=> ['userid']
18
+ # uid_attr.description #=> 'Standard LDAP attribute type'
19
+ # uid_attr.multi_valued? #=> true
20
+ # uid_attr.required? #=> true
21
+ # uid_attr.type #=> 'string'
22
+ #
23
+ # uas_attr = UCB::LDAP::Person.attribute('berkeleyEduUasEligFlag') # case doesn't matter
24
+ #
25
+ # uas_attr.name #=> 'berkeleyEduUasEligFlag'
26
+ # uas_attr.aliases #=> ['ucbvalidflag']
27
+ # uas_attr.description #=> 'UAS Eligibility Flag'
28
+ # uas_attr.multi_valued? #=> false
29
+ # uas_attr.required? #=> false
30
+ # uas_attr.type #=> 'boolean'
31
+ #
32
+ class Attribute
33
+
34
+ # Constructor called by UCB::LDAP::Entry.set_schema_attributes().
35
+ def initialize(args) #:nodoc:
36
+ @name = args["name"]
37
+ @type = args["syntax"]
38
+ @aliases = args["aliases"] || []
39
+ @description = args["description"]
40
+ @required = args["required"]
41
+ @multi_valued = args["multi"]
42
+ end
43
+
44
+ # Returns attribute name as found in the schema
45
+ def name
46
+ @name
47
+ end
48
+
49
+ # Returns Array of aliases as found in schema. Returns empty
50
+ # Array ([]) if no aliases.
51
+ #
52
+ def aliases
53
+ @aliases
54
+ end
55
+
56
+ # Returns (data) type. Used by get_value() to cast value to correct Ruby type.
57
+ #
58
+ # Supported types and corresponding Ruby type:
59
+ #
60
+ # * string String
61
+ # * integer Fixnum
62
+ # * boolean TrueClass / FalseClass
63
+ # * timestamp DateTime (convenience methods may return Date if attribute's semantics don't include time)
64
+ #
65
+ def type
66
+ @type
67
+ end
68
+
69
+ # Returns attribute description. Of limited value since all
70
+ # standard LDAP attributes have a description of
71
+ # "Standard LDAP attribute type".
72
+ def description
73
+ @description
74
+ end
75
+
76
+ # Returns <tt>true</tt> if attribute is required, else <tt>false</tt>
77
+ def required?
78
+ @required
79
+ end
80
+
81
+ # Returns <tt>true</tt> if attribute is multi-valued, else <tt>false</tt>.
82
+ # Multi-valued attribute values are returned as an Array.
83
+ def multi_valued?
84
+ @multi_valued
85
+ end
86
+
87
+ # Takes a value returned from an LDAP attribute (+Array+ of +String+)
88
+ # and returns value with correct cardinality (array or scalar)
89
+ # cast to correct #type.
90
+ def get_value(array)
91
+ if array.nil?
92
+ return false if boolean?
93
+ return [] if multi_valued?
94
+ return nil
95
+ end
96
+ typed_array = apply_type_to_array(array)
97
+ multi_valued? ? typed_array : typed_array.first
98
+ end
99
+
100
+ # Cast each element to correct type.
101
+ def apply_type_to_array(array) #:nodoc:
102
+ array.map{|scalar| apply_type_to_scalar scalar}
103
+ end
104
+
105
+ # Case element to correct type
106
+ def apply_type_to_scalar(string) #:nodoc:
107
+ return string if string?
108
+ return string.to_i if integer?
109
+ return %w{true 1}.include?(string) ? true : false if boolean?
110
+ return UCB::LDAP.local_datetime_parse(string) if timestamp?
111
+ raise "unknown type '#{type}' for attribute '#{name}'"
112
+ end
113
+
114
+ # Return <tt>true</tt> if attribute type is string.
115
+ def string?
116
+ type == "string"
117
+ end
118
+
119
+ # Return <tt>true</tt> if attribute type is integer.
120
+ def integer?
121
+ type == "integer"
122
+ end
123
+
124
+ # Return <tt>true</tt> if attribute type is boolean.
125
+ def boolean?
126
+ type == "boolean"
127
+ end
128
+
129
+ # Return <tt>true</tt> if attribute type is timestamp
130
+ def timestamp?
131
+ type == "timestamp"
132
+ end
133
+
134
+ # Returns a value in LDAP attribute value format (+Array+ of +String+).
135
+ def ldap_value(value)
136
+ return nil if value.nil?
137
+ return value.map{|v| ldap_value_stripped(v)} if value.instance_of?(Array)
138
+ return [ldap_value_stripped(value)]
139
+ end
140
+
141
+ private
142
+
143
+ # Remove leading/trailing white-space and imbedded newlines.
144
+ def ldap_value_stripped(s)
145
+ s.to_s.strip.gsub(/\n/,"")
146
+ end
147
+
148
+ end
149
+
150
+ end
151
+ end
152
+ end
@@ -1,9 +1,8 @@
1
-
2
1
  module UCB
3
2
  module LDAP
4
3
  ##
5
4
  # = UCB::LDAP::Service
6
- #
5
+ #
7
6
  # This class models a person's service entries in the UCB LDAP directory.
8
7
  #
9
8
  # services = Services.find_by_uid("1234") #=> [#<UCB::LDAP::Service: ...>, ...]
@@ -14,14 +13,14 @@ module UCB
14
13
  # services = p.services #=> [#<UCB::LDAP::Service: ...>, ...]
15
14
  #
16
15
  # == Note on Binds
17
- #
16
+ #
18
17
  # You must have a privileged bind and pass your credentials to UCB::LDAP.authenticate()
19
18
  # before performing your Service search.
20
19
  #
21
20
  class Service < Entry
22
21
  @entity_name = 'personService'
23
22
  @tree_base = 'ou=services,dc=berkeley,dc=edu'
24
-
23
+
25
24
  def eligible_by
26
25
  berkeleyEduPersonServiceEligibleBy
27
26
  end
@@ -29,7 +28,7 @@ module UCB
29
28
  def eligible_date
30
29
  berkeleyEduPersonServiceEligibleDate
31
30
  end
32
-
31
+
33
32
  def ended_by
34
33
  berkeleyEduPersonServiceEndBy
35
34
  end
@@ -45,7 +44,7 @@ module UCB
45
44
  def entered_date
46
45
  berkeleyEduPersonServiceEnteredDate
47
46
  end
48
-
47
+
49
48
  def level
50
49
  berkeleyEduPersonServiceLevel
51
50
  end
@@ -77,7 +76,7 @@ module UCB
77
76
  def stop_date
78
77
  berkeleyEduPersonServiceStopDate
79
78
  end
80
-
79
+
81
80
  def value
82
81
  berkeleyEduPersonServiceValue
83
82
  end
@@ -93,19 +92,18 @@ module UCB
93
92
  def description
94
93
  super.first
95
94
  end
96
-
97
- class << self
98
- ##
99
- # Returns an Array of JobAppointment for <tt>uid</tt>, sorted by
100
- # record_number().
101
- # Returns an empty Array ([]) if nothing is found.
102
- #
103
- def find_by_uid(uid)
104
- base = "uid=#{uid},ou=people,dc=berkeley,dc=edu"
105
- filter = Net::LDAP::Filter.eq("objectclass", 'berkeleyEduPersonService')
106
- search(:base => base, :filter => filter)
107
- end
95
+
96
+ ##
97
+ # Returns an Array of JobAppointment for <tt>uid</tt>, sorted by
98
+ # record_number().
99
+ # Returns an empty Array ([]) if nothing is found.
100
+ #
101
+ def self.find_by_uid(uid)
102
+ base = "uid=#{uid},ou=people,dc=berkeley,dc=edu"
103
+ filter = Net::LDAP::Filter.eq("objectclass", 'berkeleyEduPersonService')
104
+ search(:base => base, :filter => filter)
108
105
  end
106
+
109
107
  end
110
108
  end
111
109
  end