ucb_ldap 2.0.0.pre1 → 2.0.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/CHANGELOG +137 -135
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/{README → README.md} +82 -80
- data/Rakefile +38 -20
- data/lib/ucb_ldap.rb +238 -204
- data/lib/{ucb_ldap_address.rb → ucb_ldap/address.rb} +106 -106
- data/lib/{ucb_ldap_affiliation.rb → ucb_ldap/affiliation.rb} +16 -16
- data/lib/{ucb_ldap_entry.rb → ucb_ldap/entry.rb} +455 -448
- data/lib/{ucb_ldap_person_job_appointment.rb → ucb_ldap/job_appointment.rb} +77 -79
- data/lib/{ucb_ldap_namespace.rb → ucb_ldap/namespace.rb} +40 -50
- data/lib/{ucb_ldap_org.rb → ucb_ldap/org.rb} +427 -429
- data/lib/{ucb_ldap_person.rb → ucb_ldap/person.rb} +157 -148
- data/lib/{person → ucb_ldap/person}/affiliation_methods.rb +23 -22
- data/lib/ucb_ldap/person/common_attributes.rb +63 -0
- data/lib/{ucb_ldap_schema.rb → ucb_ldap/schema.rb} +28 -28
- data/lib/{ucb_ldap_schema_attribute.rb → ucb_ldap/schema_attribute.rb} +152 -153
- data/lib/{ucb_ldap_service.rb → ucb_ldap/service.rb} +17 -19
- data/lib/{ucb_ldap_student_term.rb → ucb_ldap/student_term.rb} +29 -31
- data/lib/ucb_ldap/version.rb +3 -0
- data/spec/rails_binds.yml +9 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/ucb_ldap/address_spec.rb +54 -0
- data/spec/ucb_ldap/affiliation_spec.rb +85 -0
- data/spec/ucb_ldap/entry_spec.rb +241 -0
- data/spec/ucb_ldap/job_appointment_spec.rb +65 -0
- data/spec/ucb_ldap/namespace_spec.rb +72 -0
- data/spec/ucb_ldap/org_spec.rb +217 -0
- data/spec/ucb_ldap/person_spec.rb +225 -0
- data/spec/ucb_ldap/schema_attribute_spec.rb +122 -0
- data/spec/ucb_ldap/schema_spec.rb +104 -0
- data/spec/ucb_ldap/service_spec.rb +127 -0
- data/spec/ucb_ldap/student_term_spec.rb +121 -0
- data/spec/ucb_ldap_spec.rb +182 -0
- data/ucb_ldap.gemspec +20 -27
- metadata +113 -64
- data/Manifest +0 -23
- data/TODO +0 -2
- data/lib/person/adv_con_person.rb +0 -0
- data/lib/person/generic_attributes.rb +0 -68
- data/lib/ucb_ldap_exceptions.rb +0 -27
- 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__)}
|
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
|
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
|
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
|
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
|
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
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# uid_attr.
|
18
|
-
# uid_attr.
|
19
|
-
# uid_attr.
|
20
|
-
# uid_attr.
|
21
|
-
# uid_attr.
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# uas_attr.
|
27
|
-
# uas_attr.
|
28
|
-
# uas_attr.
|
29
|
-
# uas_attr.
|
30
|
-
# uas_attr.
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# *
|
62
|
-
# *
|
63
|
-
# *
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
#
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
return
|
94
|
-
return
|
95
|
-
|
96
|
-
|
97
|
-
typed_array
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
return string if
|
109
|
-
return string
|
110
|
-
return
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
return
|
138
|
-
return
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|