shibboleth-rails 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  <%= form_tag user_session_path do %>
2
- Login as:
3
- <%= select_tag :user_id, options_from_collection_for_select(@users, :id, :name_n) %>
4
- <%= submit_tag "Login" %>
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,5 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- unless Rails.env.production?
3
- resource :user_session, :only => [:new, :create, :destroy]
4
- end
2
+ unless Rails.env.production?
3
+ resource :user_session, :only => [:new, :create, :destroy]
4
+ end
5
5
  end
@@ -1,42 +1,42 @@
1
1
  module Shibboleth::Rails
2
2
 
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
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
- end
48
+ end
49
49
 
50
50
  end
51
51
 
52
52
  ActionController::Base.class_eval do
53
- include Shibboleth::Rails::ControllerAdditions
54
- helper_method :current_user
53
+ include Shibboleth::Rails::ControllerAdditions
54
+ helper_method :current_user
55
55
  end
@@ -1,6 +1,6 @@
1
1
  module Shibboleth::Rails
2
2
 
3
- class Engine < ::Rails::Engine
4
- end
3
+ class Engine < ::Rails::Engine
4
+ end
5
5
 
6
6
  end
@@ -1,50 +1,50 @@
1
1
  module Shibboleth::Rails
2
2
 
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)
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
- user = find_or_create_by_emplid(identity)
13
+ user = find_or_create_by_emplid(identity)
14
14
 
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])
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
- 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
44
- end
45
- end
46
-
47
- end
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,5 +1,5 @@
1
1
  module Shibboleth
2
2
  module Rails
3
- VERSION = "0.3.7"
3
+ VERSION = "0.3.8"
4
4
  end
5
5
  end
@@ -1,34 +1,34 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe UserSessionsController do
4
- before { @user = Factory(:user) }
4
+ before { @user = Factory(:user) }
5
5
 
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
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
- 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
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
- 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
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: 29
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
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-12 00:00:00 Z
18
+ date: 2012-02-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails