authpds 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +54 -9
- data/lib/authpds/controllers/{authpds_user_sessions_controller.rb → authpds_sessions_controller.rb} +3 -10
- data/lib/authpds/session.rb +29 -87
- data/lib/authpds/version.rb +1 -1
- data/lib/authpds.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/user_session_test.rb +0 -14
- metadata +9 -9
data/README.rdoc
CHANGED
@@ -1,29 +1,74 @@
|
|
1
1
|
= Authpds
|
2
2
|
|
3
|
-
This
|
3
|
+
This gem provides a mechanism for authenticating via Ex Libris' Patron Directory Services (PDS) and provides hooks for making authorization decisions based on the user information provided by PDS. It leverages the authlogic gem and depends on a User-like model.
|
4
4
|
|
5
|
-
|
6
|
-
Generate User-like model:
|
5
|
+
== Basics
|
6
|
+
=== Generate User-like model:
|
7
7
|
rails generate model User username:string email:string firstname:string \
|
8
8
|
lastname:string mobile_phone:string crypted_password:string password_salt:string \
|
9
|
-
session_id:string persistence_token:string login_count:
|
9
|
+
session_id:string persistence_token:string login_count:integer last_request_at:string \
|
10
10
|
current_login_at:string last_login_at:string last_login_ip:string current_login_ip:string \
|
11
11
|
user_attributes:text refreshed_at:datetime
|
12
12
|
|
13
|
-
Generate UserSession model
|
13
|
+
=== Generate UserSession model
|
14
14
|
rails generate authlogic:session user_session
|
15
15
|
|
16
|
-
Create UserSessions controller
|
16
|
+
=== Create UserSessions controller
|
17
17
|
rails generate controller UserSessions --no-assets --no-helper
|
18
18
|
|
19
|
-
Mixin authpds methods into UserSessionsController
|
19
|
+
=== Mixin authpds methods into UserSessionsController
|
20
20
|
class UserSessionsController < ApplicationController
|
21
|
-
|
21
|
+
require 'authpds'
|
22
|
+
include Authpds::Controllers::AuthpdsSessionsController
|
22
23
|
end
|
23
24
|
|
24
|
-
Mixin authpds methods into ApplicationController
|
25
|
+
=== Mixin authpds methods into ApplicationController
|
25
26
|
class ApplicationController < ActionController::Base
|
26
27
|
protect_from_forgery
|
27
28
|
require 'authpds'
|
28
29
|
include Authpds::Controllers::AuthpdsController
|
29
30
|
end
|
31
|
+
|
32
|
+
== Overview
|
33
|
+
The Authpds gem mixes in callbacks to Authlogic for persisting
|
34
|
+
sessions based on a valid PDS handle.
|
35
|
+
The module extends Authlogic and should be compatible with Authlogic configuation.
|
36
|
+
It also provides hooks for custom functionality.
|
37
|
+
The documentation below describes the hooks available for overriding, PDS config methods
|
38
|
+
and further details about the module.
|
39
|
+
|
40
|
+
== Config Options Available
|
41
|
+
:pds_url:: Base pds url
|
42
|
+
:calling_system:: Name of the system
|
43
|
+
:anonymous:: Does the system allow anonymous access?
|
44
|
+
:pds_attributes:: Mapping of PDS attributes to record attributes
|
45
|
+
:redirect_logout_url:: Custom redirect logout url
|
46
|
+
:login_inaccessible_url:: Custom url to redirect to in case of system outage
|
47
|
+
:pds_record_identifier:: PDS user method to call to identify record
|
48
|
+
:institution_param_key:: Querystring parameter key for the institution value in this system
|
49
|
+
:validate_url_name:: URL name for validation action in routes
|
50
|
+
|
51
|
+
== Hooks Available for Overriding
|
52
|
+
:pds_record_identifier:: Allows for more complex logic in determining what should be used as the record identifier.
|
53
|
+
Defaults to what was set in the pds_record_identifier config.
|
54
|
+
:valid_sso_session?:: If there is no PDS handle, can we redirect to PDS to establish a SSO session based on some other information?
|
55
|
+
:additional_authorization:: Allows for additions to the authorization decision
|
56
|
+
:additional_attributes:: Allows for additional attributes to be stored in the record
|
57
|
+
:expiration_date:: Indicates when the record information should be refreshed. Defaults to one week ago.
|
58
|
+
|
59
|
+
== Further Implementation Details
|
60
|
+
=== Persisting a Session in AuthLogic
|
61
|
+
When persisting a Session, Authlogic attempts to create the Session based on information available
|
62
|
+
without having to perform an actual login by calling the :persisting? method. Authologic provides several callbacks from the :persisting?
|
63
|
+
method, e.g. :before_persisting, :persist, :after_persisting. We're using the :persist callback and setting it to :persist_session.
|
64
|
+
|
65
|
+
=== Access to the controller in Session
|
66
|
+
The class that Session extends, Authologic::Session::Base, has an explicit handle to the current controller via the instance method
|
67
|
+
:controller. This gives our custom instance methods access to cookies, session information, loggers, etc. and also allows them to
|
68
|
+
perform redirects and renders.
|
69
|
+
|
70
|
+
=== :before_login vs. :login_url
|
71
|
+
:before_login allows for customized processing before the SessionController invokes a redirect or render to a /login page. It is
|
72
|
+
is fully generic and can be used for any custom purposes. :login_url is specific for the case of logging in from a remote sytem. The
|
73
|
+
two methods can be used in conjuction, but any redirects or renders performed in :before_login, will supercede a redirect to :login_url.
|
74
|
+
|
data/lib/authpds/controllers/{authpds_user_sessions_controller.rb → authpds_sessions_controller.rb}
RENAMED
@@ -1,26 +1,19 @@
|
|
1
1
|
module Authpds
|
2
2
|
module Controllers
|
3
|
-
module
|
3
|
+
module AuthpdsSessionsController
|
4
4
|
|
5
5
|
# GET /user_sessions/new
|
6
6
|
# GET /login
|
7
7
|
def new
|
8
8
|
@user_session = UserSession.new(params)
|
9
|
-
@user_session.before_login(params) and return if performed?
|
10
9
|
redirect_to @user_session.login_url(params) unless @user_session.login_url.nil?
|
11
10
|
raise RuntimeError.new( "Error in #{self.class}.\nNo login url defined") if @user_session.login_url.nil?
|
12
11
|
end
|
13
12
|
|
14
13
|
# GET /validate
|
15
14
|
def validate
|
16
|
-
@user_session = UserSession.
|
17
|
-
|
18
|
-
@user_session.errors.each {|error|
|
19
|
-
flash[:error] = "There was an error logging in. #{error}"
|
20
|
-
logger.error("Error in #{self.class} while saving user session. #{error}")
|
21
|
-
} unless result
|
22
|
-
redirect_to (params[:return_url].nil?) ? root_url : params[:return_url]
|
23
|
-
end
|
15
|
+
@user_session = UserSession.create(params[:user_session])
|
16
|
+
redirect_to (params[:return_url].nil?) ? root_url : params[:return_url]
|
24
17
|
end
|
25
18
|
|
26
19
|
# DELETE /user_sessions/1
|
data/lib/authpds/session.rb
CHANGED
@@ -1,80 +1,46 @@
|
|
1
1
|
module Authpds
|
2
2
|
# == Overview
|
3
|
-
# The
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# The
|
8
|
-
#
|
9
|
-
# available for use by custom implementations, instructions for mixing in custom implementations and
|
10
|
-
# further details about the module.
|
3
|
+
# The Authpds gem mixes in callbacks to Authlogic for persisting
|
4
|
+
# sessions based on a valid PDS handle.
|
5
|
+
# The module extends Authlogic and should be compatible with Authlogic configuation.
|
6
|
+
# It also provides hooks for custom functionality.
|
7
|
+
# The documentation below describes the hooks available for overriding, PDS config methods
|
8
|
+
# and further details about the module.
|
11
9
|
#
|
12
|
-
# ==
|
13
|
-
# :
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# :
|
18
|
-
#
|
19
|
-
# :
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# :validate_session:: Used for creating a UserSession after login credentials are provided. When overridden,
|
23
|
-
# custom implementations should update the UserSession User, via UserSession#get_user based
|
24
|
-
# on authentication/authorization criteria. Authlogic will take care of the rest
|
25
|
-
# by saving the User and creating the UserSession.
|
26
|
-
# :before_logout:: Allows for custom logic immediately before logout is performed
|
27
|
-
# :after_logout:: Allows for custom logic immediately after logout is performed
|
28
|
-
# :redirect_logout_url:: Should return a custom logout URL for redirection to after logout has been performed.
|
29
|
-
# Allows for single sign-out via a remote system.
|
30
|
-
#
|
31
|
-
# == Convenience Methods for Use by Custom Implementations
|
32
|
-
# UserSession#controller:: Returns the current controller. Used for accessing cookies and session information,
|
33
|
-
# performing redirects, etc.
|
34
|
-
# UserSession#get_user:: Returns the User for updating by :on_every_request and :after_login. Returns an existing User
|
35
|
-
# if she exists, otherwise creates a new User.
|
36
|
-
# UserSession#validate_url:: Returns the URL for validating a UserSession on return from a remote login system.
|
37
|
-
# User#expiration_period=:: Sets the expiration date for the User. Default is one week ago.
|
38
|
-
# User#refreshed_at=:: Sets the last time the User was refreshed and saves the value to the database.
|
39
|
-
# User#expired?:: Returns a boolean based on whether the User has been refreshed recently.
|
40
|
-
# If User#refreshed_at is older than User#expiration_date, the User is expired and the data
|
41
|
-
# may need to be refreshed.
|
42
|
-
# User#user_attributes=:: "Smart" updating of user_attributes. Maintains user_attributes that are not explicity overwritten.
|
10
|
+
# == Config Options Available
|
11
|
+
# :pds_url:: Base pds url
|
12
|
+
# :calling_system:: Name of the system
|
13
|
+
# :anonymous:: Does the system allow anonymous access?
|
14
|
+
# :pds_attributes:: Mapping of PDS attributes to record attributes
|
15
|
+
# :redirect_logout_url:: Custom redirect logout url
|
16
|
+
# :login_inaccessible_url:: Custom url to redirect to in case of system outage
|
17
|
+
# :pds_record_identifier:: PDS user method to call to identify record
|
18
|
+
# :institution_param_key:: Querystring parameter key for the institution value in this system
|
19
|
+
# :validate_url_name:: URL name for validation action in routes
|
43
20
|
#
|
44
|
-
# ==
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
21
|
+
# == Hooks Available for Overriding
|
22
|
+
# :pds_record_identifier:: Allows for more complex logic in determining what should be used as the record identifier.
|
23
|
+
# Defaults to what was set in the pds_record_identifier config.
|
24
|
+
# :valid_sso_session?:: If there is no PDS handle, can we redirect to PDS to establish a SSO session based on some other information?
|
25
|
+
# :additional_authorization:: Allows for additions to the authorization decision
|
26
|
+
# :additional_attributes:: Allows for additional attributes to be stored in the record
|
27
|
+
# :expiration_date:: Indicates when the record information should be refreshed. Defaults to one week ago.
|
51
28
|
#
|
52
29
|
# == Further Implementation Details
|
53
|
-
# === Persisting a
|
54
|
-
# When persisting a
|
30
|
+
# === Persisting a Session in AuthLogic
|
31
|
+
# When persisting a Session, Authlogic attempts to create the Session based on information available
|
55
32
|
# without having to perform an actual login by calling the :persisting? method. Authologic provides several callbacks from the :persisting?
|
56
33
|
# method, e.g. :before_persisting, :persist, :after_persisting. We're using the :persist callback and setting it to :persist_session.
|
57
34
|
#
|
58
|
-
# ===
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# method, e.g. :before_validation, :validate, :after_validation. We're using the :validate callback and setting it to :validate_session.
|
62
|
-
#
|
63
|
-
# === Access to the controller in UserSession
|
64
|
-
# The class that UserSession extends, Authologic::Session::Base, has an explicit handle to the current controller via the instance method
|
65
|
-
# :controller. This gives our custom instance methods the access to cookies, session information, loggers, etc. and also allows them to
|
35
|
+
# === Access to the controller in Session
|
36
|
+
# The class that Session extends, Authologic::Session::Base, has an explicit handle to the current controller via the instance method
|
37
|
+
# :controller. This gives our custom instance methods access to cookies, session information, loggers, etc. and also allows them to
|
66
38
|
# perform redirects and renders.
|
67
39
|
#
|
68
40
|
# === :before_login vs. :login_url
|
69
|
-
# :before_login allows for customized processing before the
|
41
|
+
# :before_login allows for customized processing before the SessionController invokes a redirect or render to a /login page. It is
|
70
42
|
# is fully generic and can be used for any custom purposes. :login_url is specific for the case of logging in from a remote sytem. The
|
71
43
|
# two methods can be used in conjuction, but any redirects or renders performed in :before_login, will supercede a redirect to :login_url.
|
72
|
-
#
|
73
|
-
# === UserSession#get_user vs. UserSession#attempted_record
|
74
|
-
# Both UserSession#get_user and UserSession#attempted_record provide access to the instance variable @attempted_record, but
|
75
|
-
# UserSession#get_user set the instance variable to either an existing User (based on the username parameter), or creates a new User
|
76
|
-
# for use by implementing systems. If custom implementations want to interact directly with UserSession#attempted_record and
|
77
|
-
# @attempted_record, they are welcome to do so.
|
78
44
|
module Session
|
79
45
|
def self.included(klass)
|
80
46
|
klass.class_eval do
|
@@ -83,9 +49,6 @@ module Authpds
|
|
83
49
|
include InstanceMethods
|
84
50
|
include AuthlogicCallbackMethods
|
85
51
|
persist :persist_session
|
86
|
-
validate :validate_session
|
87
|
-
before_destroy :before_logout
|
88
|
-
after_destroy :after_logout
|
89
52
|
end
|
90
53
|
end
|
91
54
|
|
@@ -182,11 +145,6 @@ module Authpds
|
|
182
145
|
end
|
183
146
|
end
|
184
147
|
|
185
|
-
# Called by the user session controller login is initiated.
|
186
|
-
# Precedes :login_url
|
187
|
-
def before_login(params={})
|
188
|
-
end
|
189
|
-
|
190
148
|
# URL to redirect to for login.
|
191
149
|
# Preceded by :before_login
|
192
150
|
def login_url(params={})
|
@@ -332,22 +290,6 @@ module Authpds
|
|
332
290
|
def persist_session
|
333
291
|
destroy unless (authenticated? and authorized?) or anonymous?
|
334
292
|
end
|
335
|
-
|
336
|
-
# Callback method from Authlogic.
|
337
|
-
# Called while validating on session save.
|
338
|
-
def validate_session
|
339
|
-
authenticated? and authorized?
|
340
|
-
end
|
341
|
-
|
342
|
-
# Callback method from Authlogic.
|
343
|
-
# Called before destroying UserSession.
|
344
|
-
def before_logout
|
345
|
-
end
|
346
|
-
|
347
|
-
# Callback method from Authlogic.
|
348
|
-
# Called after destroying UserSession.
|
349
|
-
def after_logout
|
350
|
-
end
|
351
293
|
end
|
352
294
|
end
|
353
295
|
end
|
data/lib/authpds/version.rb
CHANGED
data/lib/authpds.rb
CHANGED
@@ -8,7 +8,7 @@ AUTHPDS_PATH = File.dirname(__FILE__) + "/authpds/"
|
|
8
8
|
'institution_list',
|
9
9
|
'exlibris/pds',
|
10
10
|
'controllers/authpds_controller',
|
11
|
-
'controllers/
|
11
|
+
'controllers/authpds_sessions_controller'
|
12
12
|
].each do |library|
|
13
13
|
require AUTHPDS_PATH + library
|
14
14
|
end
|
data/test/test_helper.rb
CHANGED
@@ -78,20 +78,6 @@ class UserSessionTest < ActiveSupport::TestCase
|
|
78
78
|
assert_equal("N12162279", user_session.send(:attempted_record).username)
|
79
79
|
end
|
80
80
|
|
81
|
-
test "validate_session" do
|
82
|
-
user_session = UserSession.new
|
83
|
-
assert_nil(controller.session["auth_test_credentials"])
|
84
|
-
assert_nil(user_session.send(:attempted_record))
|
85
|
-
assert_nil(user_session.record)
|
86
|
-
assert_no_difference('User.count') {
|
87
|
-
user_session.send(:validate_session)
|
88
|
-
}
|
89
|
-
assert_nil(controller.session["auth_test_credentials"])
|
90
|
-
assert_not_nil(user_session.send(:attempted_record))
|
91
|
-
assert_nil(user_session.record)
|
92
|
-
assert_equal("N12162279", user_session.send(:attempted_record).username)
|
93
|
-
end
|
94
|
-
|
95
81
|
test "find" do
|
96
82
|
user_session = UserSession.new
|
97
83
|
assert_nil(controller.session["authpds_credentials"])
|
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.
|
4
|
+
version: 0.0.20
|
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-
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2151877620 !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: *
|
24
|
+
version_requirements: *2151877620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: authlogic
|
27
|
-
requirement: &
|
27
|
+
requirement: &2151876380 !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: *
|
35
|
+
version_requirements: *2151876380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &2151869980 !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: *
|
46
|
+
version_requirements: *2151869980
|
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:
|
@@ -54,7 +54,7 @@ extra_rdoc_files: []
|
|
54
54
|
files:
|
55
55
|
- lib/authpds/acts_as_authentic.rb
|
56
56
|
- lib/authpds/controllers/authpds_controller.rb
|
57
|
-
- lib/authpds/controllers/
|
57
|
+
- lib/authpds/controllers/authpds_sessions_controller.rb
|
58
58
|
- lib/authpds/exlibris/pds.rb
|
59
59
|
- lib/authpds/institution.rb
|
60
60
|
- lib/authpds/institution_list.rb
|