authpds 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- class Institution < Struct.new(:display_name, :name, :default_institution,
1
+ class Institution < Struct.new(:display_name, :name, :default,
2
2
  :application_layout, :ip_addresses, :parent_institution, :view_attributes, :login_attributes)
3
3
  require 'ipaddr'
4
4
 
@@ -7,7 +7,10 @@ class Institution < Struct.new(:display_name, :name, :default_institution,
7
7
  # not actual Services!
8
8
  def initialize(h={})
9
9
  members.each {|m| self.send( ("#{m}=").to_sym , (h.delete("#{m}".to_sym) || h.delete("#{m}"))) }
10
- default_institution = false unless default_institution
10
+ # If the institution is named default, take that as an
11
+ # indication that it's the default institution
12
+ default = true if name.eql?("default") or name.eql?("DEFAULT")
13
+ default = false unless default
11
14
  # Log the fact that there are left overs in the hash
12
15
  # Rails.logger.warn("The following institution settings were ignored: #{h.inspect}.") unless h.empty?
13
16
  end
@@ -10,7 +10,7 @@ module Authpds
10
10
  # further details about the module.
11
11
  #
12
12
  # == Methods Available for Overriding
13
- # :on_every_request:: Used for creating a UserSession without the User having to explicitly login, thereby supporting single sign-on.
13
+ # :persist_session:: Used for creating a UserSession without the User having to explicitly login, thereby supporting single sign-on.
14
14
  # When overridden, implementations should update the UserSession User, via UserSession#get_user based
15
15
  # on custom authentication/authorization criteria. Authlogic will take care of the rest by saving the User
16
16
  # and creating the UserSession.
@@ -19,7 +19,7 @@ module Authpds
19
19
  # :login_url:: Should return a custom login URL for redirection to when logging in via a remote system.
20
20
  # If undefined, /login will go to the UserSession login view,
21
21
  # default user_session/new). Preceded by :before_login.
22
- # :after_login:: Used for creating a UserSession after login credentials are provided. When overridden,
22
+ # :validate_session:: Used for creating a UserSession after login credentials are provided. When overridden,
23
23
  # custom implementations should update the UserSession User, via UserSession#get_user based
24
24
  # on authentication/authorization criteria. Authlogic will take care of the rest
25
25
  # by saving the User and creating the UserSession.
@@ -53,12 +53,12 @@ module Authpds
53
53
  # === Persisting a UserSession in AuthLogic
54
54
  # When persisting a UserSession, Authlogic attempts to create the UserSession based on information available
55
55
  # without having to perform an actual login by calling the :persisting? method. Authologic provides several callbacks from the :persisting?
56
- # method, e.g. :before_persisting, :persist, :after_persisting. We're using the :persist callback and setting it to :on_every_request.
56
+ # method, e.g. :before_persisting, :persist, :after_persisting. We're using the :persist callback and setting it to :persist_session.
57
57
  #
58
58
  # === Validating a UserSession in AuthLogic
59
59
  # When validating a UserSession, Authlogic attempts to create the UserSession based on information available
60
60
  # from login by calling the :valid? method. Authologic provides several callbacks from the :valid?
61
- # method, e.g. :before_validation, :validate, :after_validation. We're using the :validate callback and setting it to :after_login.
61
+ # method, e.g. :before_validation, :validate, :after_validation. We're using the :validate callback and setting it to :validate_session.
62
62
  #
63
63
  # === Access to the controller in UserSession
64
64
  # The class that UserSession extends, Authologic::Session::Base, has an explicit handle to the current controller via the instance method
@@ -83,7 +83,7 @@ module Authpds
83
83
  include InstanceMethods
84
84
  include AuthlogicCallbackMethods
85
85
  persist :persist_session
86
- validate :after_login
86
+ validate :validate_session
87
87
  before_destroy :before_logout
88
88
  after_destroy :after_logout
89
89
  end
@@ -143,6 +143,12 @@ module Authpds
143
143
  rw_config(:institution_param_key, value, "institute")
144
144
  end
145
145
  alias_method :institution_param_key=, :institution_param_key
146
+
147
+ # URL name for validation action
148
+ def validate_url_name(value = nil)
149
+ rw_config(:validate_url_name, value, "validate_url")
150
+ end
151
+ alias_method :validate_url_name=, :validate_url_name
146
152
  end
147
153
 
148
154
  module AuthpdsCallbackMethods
@@ -270,7 +276,7 @@ module Authpds
270
276
 
271
277
  # Returns the URL for validating a UserSession on return from a remote login system.
272
278
  def validate_url(params={})
273
- url = controller.validate_url(:return_url => controller.user_session_redirect_url(params[:return_url]))
279
+ url = controller.send(validate_url_name, :return_url => controller.user_session_redirect_url(params[:return_url]))
274
280
  return url if params.nil? or params.empty?
275
281
  url << "?" if url.match('\?').nil?
276
282
  params.each do |key, value|
@@ -279,6 +285,10 @@ module Authpds
279
285
  end
280
286
  return url
281
287
  end
288
+
289
+ def validate_url_name
290
+ @validate_url_name ||= self.class.validate_url_name
291
+ end
282
292
 
283
293
  def institution_attributes
284
294
  @institution_attributes =
@@ -333,7 +343,7 @@ module Authpds
333
343
 
334
344
  # Callback method from Authlogic.
335
345
  # Called while validating on session save.
336
- def after_login
346
+ def validate_session
337
347
  authenticated? and authorized?
338
348
  end
339
349
 
@@ -1,3 +1,3 @@
1
1
  module Authpds
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -41,7 +41,7 @@ require File.dirname(__FILE__) + '/../lib/authpds' unless defined?(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 = '5320129121113834981331135143'
44
+ VALID_PDS_HANDLE_FOR_NYU = '73201295126115517644686139782'
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,10 @@ class Authlogic::TestCase::MockController
69
69
  def root_url
70
70
  end
71
71
 
72
+ def validate_url(options={})
73
+ return "http://railsapp.library.nyu.edu/validate?return_url=#{options[:return_url]}"
74
+ end
75
+
72
76
  def performed?
73
77
  false
74
78
  end
@@ -78,13 +78,13 @@ class UserSessionTest < ActiveSupport::TestCase
78
78
  assert_equal("N12162279", user_session.send(:attempted_record).username)
79
79
  end
80
80
 
81
- test "after_login" do
81
+ test "validate_session" do
82
82
  user_session = UserSession.new
83
83
  assert_nil(controller.session["auth_test_credentials"])
84
84
  assert_nil(user_session.send(:attempted_record))
85
85
  assert_nil(user_session.record)
86
86
  assert_no_difference('User.count') {
87
- user_session.send(:after_login)
87
+ user_session.send(:validate_session)
88
88
  }
89
89
  assert_nil(controller.session["auth_test_credentials"])
90
90
  assert_not_nil(user_session.send(:attempted_record))
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.13
4
+ version: 0.0.14
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-05 00:00:00.000000000 Z
12
+ date: 2012-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2151878220 !ruby/object:Gem::Requirement
16
+ requirement: &2151878120 !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: *2151878220
24
+ version_requirements: *2151878120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: authlogic
27
- requirement: &2151876820 !ruby/object:Gem::Requirement
27
+ requirement: &2151876600 !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: *2151876820
35
+ version_requirements: *2151876600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &2151872060 !ruby/object:Gem::Requirement
38
+ requirement: &2151871520 !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: *2151872060
46
+ version_requirements: *2151871520
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: