shibboleth-rails 0.3.7 → 0.3.8
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.
- data/app/views/user_sessions/new.html.erb +3 -3
- data/config/routes.rb +3 -3
- data/lib/shibboleth-rails/controller_additions.rb +40 -40
- data/lib/shibboleth-rails/engine.rb +2 -2
- data/lib/shibboleth-rails/user_model_additions.rb +41 -41
- data/lib/shibboleth-rails/version.rb +1 -1
- data/spec/controllers/user_sessions_controller_spec.rb +26 -26
- metadata +4 -4
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= form_tag user_session_path do %>
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
Login as:
|
3
|
+
<%= select_tag :user_id, options_from_collection_for_select(@users, :id, :name_n) %>
|
4
|
+
<%= submit_tag "Login" %>
|
5
5
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
module Shibboleth::Rails
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
3
|
+
module ControllerAdditions
|
4
|
+
private
|
5
|
+
|
6
|
+
def authenticated?
|
7
|
+
request.env['employeeNumber'].present?
|
8
|
+
end
|
9
|
+
|
10
|
+
def shibboleth
|
11
|
+
{:emplid => request.env['employeeNumber'],
|
12
|
+
:name_n => request.env['REMOTE_USER'].chomp("@osu.edu"),
|
13
|
+
:affiliations => request.env['affiliation']}
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
return @current_user if defined?(@current_user)
|
18
|
+
@current_user = if session[:simulate_id].present?
|
19
|
+
User.find(session[:simulate_id])
|
20
|
+
elsif authenticated?
|
21
|
+
User.find_or_create_from_shibboleth(shibboleth)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def require_shibboleth
|
26
|
+
if current_user
|
27
|
+
current_user.update_usage_stats(request, :login => session['new'])
|
28
|
+
session.delete('new')
|
29
|
+
else
|
30
|
+
session['new'] = true
|
31
|
+
if Rails.env.production?
|
32
|
+
redirect_to [request.protocol, request.host,
|
33
|
+
'/Shibboleth.sso/Login?target=', CGI.escape(requested_url)].join
|
34
|
+
else
|
35
|
+
session['target'] = requested_url
|
36
|
+
redirect_to new_user_session_url, :notice => 'Login first, please.'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
40
|
|
41
41
|
def requested_url
|
42
42
|
if request.respond_to?(:url)
|
@@ -45,11 +45,11 @@ module Shibboleth::Rails
|
|
45
45
|
request.protocol + request.host + request.request_uri
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
end
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
52
|
ActionController::Base.class_eval do
|
53
|
-
|
54
|
-
|
53
|
+
include Shibboleth::Rails::ControllerAdditions
|
54
|
+
helper_method :current_user
|
55
55
|
end
|
@@ -1,50 +1,50 @@
|
|
1
1
|
module Shibboleth::Rails
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module ModelAdditions
|
4
|
+
def authenticated_by_shibboleth
|
5
|
+
extend ClassMethods
|
6
|
+
include InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def find_or_create_from_shibboleth(identity)
|
11
11
|
affiliations = identity.delete(:affiliations)
|
12
12
|
|
13
|
-
|
13
|
+
user = find_or_create_by_emplid(identity)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
# names change due to marriage, etc.
|
16
|
+
# update_attribute is a NOOP if not different
|
17
|
+
user.update_attribute(:name_n, identity[:name_n])
|
18
18
|
user.update_role(affiliations) if user.respond_to?(:update_role)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
19
|
+
user
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module InstanceMethods
|
24
|
+
def update_usage_stats(request, args = {})
|
25
|
+
if args[:login]
|
26
|
+
if self.respond_to?(:login_count)
|
27
|
+
self.login_count ||= 0
|
28
|
+
self.login_count += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
if self.respond_to?(:current_login_at)
|
32
|
+
self.last_login_at = self.current_login_at if self.respond_to?(:last_login_at)
|
33
|
+
self.current_login_at = Time.now
|
34
|
+
end
|
35
|
+
|
36
|
+
if self.respond_to?(:current_login_ip)
|
37
|
+
self.last_login_ip = self.current_login_ip if self.respond_to?(:last_login_ip)
|
38
|
+
self.current_login_ip = request.remote_ip
|
39
|
+
end
|
40
|
+
end
|
41
|
+
self.last_request_at = Time.now if self.respond_to?(:last_request_at)
|
42
|
+
|
43
|
+
save(:validate => false)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
50
|
::ActiveRecord::Base.send :extend, Shibboleth::Rails::ModelAdditions
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
3
|
describe UserSessionsController do
|
4
|
-
|
4
|
+
before { @user = Factory(:user) }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
describe 'loading the login page' do
|
7
|
+
before { get :new }
|
8
|
+
it { should respond_with(:success) }
|
9
|
+
it { should assign_to(:user_session) }
|
10
|
+
it { should assign_to(:users), :with => [@user] }
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
describe 'loggin in' do
|
14
|
+
before { post :create, :user_id => @user.id }
|
15
|
+
it 'should login the user' do
|
16
|
+
UserSession.find.user.should == @user
|
17
|
+
end
|
18
|
+
it { should respond_with(:redirect), :to => root_url }
|
19
|
+
it { should set_the_flash.to("You are now logged in as #{@user.name_n}.") }
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
describe 'logging out' do
|
23
|
+
before do
|
24
|
+
UserSession.create(@user)
|
25
|
+
delete :destroy
|
26
|
+
end
|
27
|
+
it 'should log out the user' do
|
28
|
+
UserSession.find.should be_nil
|
29
|
+
end
|
30
|
+
it { should respond_with(:redirect), :to => new_user_session_url }
|
31
|
+
it { should set_the_flash.to('Logout successful!') }
|
32
|
+
end
|
33
33
|
|
34
34
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shibboleth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 8
|
10
|
+
version: 0.3.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mikegee
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01
|
18
|
+
date: 2012-02-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|