authpds 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,16 +42,23 @@ module Authpds
42
42
  class BorInfo < GetAttribute
43
43
 
44
44
  protected
45
- def initialize(pds_url, calling_system, pds_handle, bor_info_attributes)
45
+ def initialize(pds_url, calling_system, pds_handle)
46
46
  super(pds_url, calling_system, pds_handle, "bor_info")
47
47
  raise RuntimeError.new(
48
48
  "Error in #{self.class}."+
49
49
  "Unrecognized response: #{@response}.") unless @response.root.name.eql?("bor-info") or @response.root.name.eql?("pds")
50
- bor_info_attributes.each { |local_attribute, xml_attribute|
51
- self.class.send(:attr_reader, local_attribute)
52
- instance_variable_set("@#{local_attribute}".to_sym,
53
- @response.at("#{xml_attribute}").inner_text) unless @response.at("//bor-info/#{xml_attribute}").nil?
50
+ return unless @response.root.name.eql?("bor-info")
51
+ bor_info = @response.root.children.each { |xml_element|
52
+ pds_attr = xml_element.name.gsub("-", "_")
53
+ self.class.send(:attr_reader, pds_attr)
54
+ instance_variable_set("@#{pds_attr}".to_sym, xml_element.inner_text) unless xml_element.inner_text.nil?
54
55
  }
56
+ # bor_info_attributes.each_value { |xml_element|
57
+ # pds_attr = xml_element.gsub("-", "_")
58
+ # self.class.send(:attr_reader, pds_attr)
59
+ # instance_variable_set("@#{pds_attr}".to_sym,
60
+ # @response.at("#{xml_element}").inner_text) unless @response.at("//bor-info/#{xml_element}").nil?
61
+ # }
55
62
  end
56
63
  end
57
64
  end
@@ -110,7 +110,8 @@ module Authpds
110
110
 
111
111
  # Mapping of PDS attributes
112
112
  def pds_attributes(value = nil)
113
- rw_config(:pds_attributes, value, {:id => "id", :email => "email", :firstname => "name", :lastname => "name" })
113
+ value.each_value { |pds_attr| pds_attr.gsub!("-", "_") } unless value.nil?
114
+ rw_config(:pds_attributes, value, {:email => "email", :firstname => "name", :lastname => "name", :primary_institution => "institute" })
114
115
  end
115
116
  alias_method :pds_attributes=, :pds_attributes
116
117
 
@@ -132,12 +133,6 @@ module Authpds
132
133
  end
133
134
  alias_method :pds_record_identifier=, :pds_record_identifier
134
135
 
135
- # PDS user method to call to get users primary institution
136
- def pds_record_primary_institution(value = nil)
137
- rw_config(:pds_record_primary_institution, value, :institute)
138
- end
139
- alias_method :pds_record_primary_institution=, :pds_record_primary_institution
140
-
141
136
  # Querystring parameter key for the institution value
142
137
  def institution_param_key(value = nil)
143
138
  rw_config(:institution_param_key, value, "institute")
@@ -154,12 +149,7 @@ module Authpds
154
149
  module AuthpdsCallbackMethods
155
150
  # Hook for more complicated logic to determine PDS user record identifier
156
151
  def pds_record_identifier
157
- self.class.pds_record_identifier
158
- end
159
-
160
- # Hook for more complicated logic to determine PDS user primary institution
161
- def pds_record_primary_institution
162
- self.class.pds_record_primary_institution
152
+ @pds_record_identifier ||= self.class.pds_record_identifier
163
153
  end
164
154
 
165
155
  # Hook to determine if we should set up an SSO session
@@ -215,7 +205,7 @@ module Authpds
215
205
 
216
206
  def pds_user
217
207
  begin
218
- @pds_user ||= Authpds::Exlibris::Pds::BorInfo.new(self.class.pds_url, self.class.calling_system, pds_handle, pds_attributes) unless pds_handle.nil?
208
+ @pds_user ||= Authpds::Exlibris::Pds::BorInfo.new(self.class.pds_url, self.class.calling_system, pds_handle) unless pds_handle.nil?
219
209
  return @pds_user unless @pds_user.nil? or @pds_user.error
220
210
  rescue Exception => e
221
211
  # Delete the PDS_HANDLE, since this isn't working.
@@ -252,9 +242,9 @@ module Authpds
252
242
  end
253
243
 
254
244
  # Get the record associated with this PDS user.
255
- def get_record(username)
256
- record = klass.send(:find_by_username, username)
257
- record = klass.new :username => username if record.nil?
245
+ def get_record(login)
246
+ record = klass.find_by_smart_case_login_field(login)
247
+ record = klass.new login_field => login if record.nil?
258
248
  return record
259
249
  end
260
250
 
@@ -264,12 +254,14 @@ module Authpds
264
254
  self.attempted_record.expiration_date = expiration_date
265
255
  # Do this part only if user data has expired.
266
256
  if self.attempted_record.expired?
267
- self.attempted_record.primary_institution= pds_user.send(pds_record_primary_institution)
268
- pds_attributes.each_key { |user_attr|
269
- self.attempted_record.send("#{user_attr}=".to_sym,
270
- pds_user.send(user_attr.to_sym)) if self.attempted_record.respond_to?("#{user_attr}=".to_sym)
257
+ pds_attributes.each do |record_attr, pds_attr|
258
+ self.attempted_record.send("#{record_attr}=".to_sym,
259
+ pds_user.send(pds_attr.to_sym)) if self.attempted_record.respond_to?("#{record_attr}=".to_sym)
260
+ end
261
+ pds_user.class.public_instance_methods(false).each do |pds_attr_reader|
271
262
  self.attempted_record.user_attributes = {
272
- user_attr.to_sym => pds_user.send(user_attr.to_sym) }}
263
+ pds_attr_reader.to_sym => pds_user.send(pds_attr_reader.to_sym) }
264
+ end
273
265
  end
274
266
  self.attempted_record.user_attributes= additional_attributes
275
267
  end
@@ -1,3 +1,3 @@
1
1
  module Authpds
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
@@ -7,16 +7,7 @@ class UserSession < Authlogic::Session::Base
7
7
  httponly true
8
8
  secure true
9
9
  login_inaccessible_url "http://library.nyu.edu/errors/bobcat-library-nyu-edu/"
10
- pds_attributes :id => "id", :uid => "uid",
11
- :opensso => "opensso", :name => "name", :firstname => "givenname",
12
- :lastname => "sn", :commonname => "cn", :email => "email",
13
- :nyuidn => "nyuidn", :verification => "verification", :institute => "institute",
14
- :bor_status => "bor-status", :bor_type => "bor-type",
15
- :college_code => "college_code", :college_name => "college_name",
16
- :dept_name => "dept_name", :dept_code => "dept_code",
17
- :major_code => "major_code", :major => "major", :ill_permission => "ill-permission",
18
- :newschool_ldap => "newschool_ldap"
19
-
10
+ pds_attributes :firstname => "givenname", :lastname => "sn", :email => "email", :primary_institution => "institute"
20
11
  def expiration_date
21
12
  1.day.ago
22
13
  end
data/test/test_helper.rb CHANGED
@@ -41,7 +41,7 @@ require File.dirname(__FILE__) + '/../lib/authpds'
41
41
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
42
42
 
43
43
  class ActiveSupport::TestCase
44
- VALID_PDS_HANDLE_FOR_NYU = '732012103839115682024010207789'
44
+ VALID_PDS_HANDLE_FOR_NYU = '83201295456116368349190324314'
45
45
  VALID_PDS_HANDLE_FOR_NEWSCHOOL = '272201212284614806184193096120278'
46
46
  VALID_PDS_HANDLE_FOR_COOPER = '272201212284614806184193096120278'
47
47
  INVALID_PDS_HANDLE = "Invalid"
@@ -69,6 +69,9 @@ class Authlogic::TestCase::MockController
69
69
  def root_url
70
70
  end
71
71
 
72
+ def redirect_to(*args)
73
+ end
74
+
72
75
  def validate_url(options={})
73
76
  return "http://railsapp.library.nyu.edu/validate?return_url=#{options[:return_url]}"
74
77
  end
@@ -38,7 +38,7 @@ class PdsTest < ActiveSupport::TestCase
38
38
  end
39
39
 
40
40
  test "bor_info_valid_nyu" do
41
- nyu = Authpds::Exlibris::Pds::BorInfo.new(@pds_url, @calling_system, @valid_pds_handle_for_nyu, @bor_info_attributes)
41
+ nyu = Authpds::Exlibris::Pds::BorInfo.new(@pds_url, @calling_system, @valid_pds_handle_for_nyu)
42
42
  assert_equal("N12162279", nyu.id)
43
43
  assert_equal("std5", nyu.uid)
44
44
  assert_equal("N12162279", nyu.nyuidn)
@@ -46,8 +46,8 @@ class PdsTest < ActiveSupport::TestCase
46
46
  assert_equal("CB", nyu.bor_type)
47
47
  assert_equal("true", nyu.opensso)
48
48
  assert_equal("Scot Thomas", nyu.name)
49
- assert_equal("Scot Thomas", nyu.firstname)
50
- assert_equal("Dalton", nyu.lastname)
49
+ assert_equal("Scot Thomas", nyu.givenname)
50
+ assert_equal("Dalton", nyu.sn)
51
51
  assert_equal("Y", nyu.ill_permission)
52
52
  assert_equal("GA", nyu.college_code)
53
53
  assert_equal("CSCI", nyu.dept_code)
@@ -55,7 +55,7 @@ class PdsTest < ActiveSupport::TestCase
55
55
  end
56
56
 
57
57
  test "bor_info_valid_newschool" do
58
- newschool = Authpds::Exlibris::Pds::BorInfo.new(@pds_url, @calling_system, @valid_pds_handle_for_newschool, @bor_info_attributes)
58
+ newschool = Authpds::Exlibris::Pds::BorInfo.new(@pds_url, @calling_system, @valid_pds_handle_for_newschool)
59
59
  assert_equal("N00206454", newschool.id)
60
60
  assert_equal("314519567249252", newschool.uid)
61
61
  assert_equal("N00206454", newschool.nyuidn)
@@ -63,13 +63,13 @@ class PdsTest < ActiveSupport::TestCase
63
63
  assert_equal("0", newschool.bor_type)
64
64
  assert_equal("true", newschool.newschool_ldap)
65
65
  assert_equal("Allen", newschool.name)
66
- assert_equal("Allen", newschool.firstname)
67
- assert_equal("Jones", newschool.lastname)
66
+ assert_equal("Allen", newschool.givenname)
67
+ assert_equal("Jones", newschool.sn)
68
68
  assert_equal("Y", newschool.ill_permission)
69
69
  end
70
70
 
71
71
  test "bor_info_invalid" do
72
- get_attribute = Authpds::Exlibris::Pds::BorInfo.new(@pds_url, @calling_system, @invalid_pds_handle, @bor_info_attributes)
72
+ get_attribute = Authpds::Exlibris::Pds::BorInfo.new(@pds_url, @calling_system, @invalid_pds_handle)
73
73
  assert_equal("Error User does not exist", get_attribute.error)
74
74
  end
75
75
  end
@@ -56,8 +56,8 @@ class UserSessionTest < ActiveSupport::TestCase
56
56
  assert_equal("CB", pds_user.bor_type)
57
57
  assert_equal("true", pds_user.opensso)
58
58
  assert_equal("Scot Thomas", pds_user.name)
59
- assert_equal("Scot Thomas", pds_user.firstname)
60
- assert_equal("Dalton", pds_user.lastname)
59
+ assert_equal("Scot Thomas", pds_user.givenname)
60
+ assert_equal("Dalton", pds_user.sn)
61
61
  assert_equal("Y", pds_user.ill_permission)
62
62
  assert_equal("GA", pds_user.college_code)
63
63
  assert_equal("CSCI", pds_user.dept_code)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authpds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2151877280 !ruby/object:Gem::Requirement
16
+ requirement: &2151878000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2151877280
24
+ version_requirements: *2151878000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: authlogic
27
- requirement: &2151876220 !ruby/object:Gem::Requirement
27
+ requirement: &2151876500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2151876220
35
+ version_requirements: *2151876500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &2151869780 !ruby/object:Gem::Requirement
38
+ requirement: &2151870800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2151869780
46
+ version_requirements: *2151870800
47
47
  description: Libraries that use Ex Libris products, can integrate Rails application
48
48
  with PDS to provide single sign-on across systems.
49
49
  email: