devise_bushido_authenticatable 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +4 -20
  5. data/Gemfile.lock +151 -74
  6. data/README.md +4 -2
  7. data/Rakefile +1 -46
  8. data/app/controllers/devise/cas_sessions_controller.rb +59 -10
  9. data/app/views/devise/cas_sessions/unregistered.html.erb +150 -2
  10. data/app/views/devise/cas_sessions/unregistered.html.erb.old +2 -0
  11. data/devise_bushido_authenticatable.gemspec +28 -95
  12. data/lib/devise_bushido_authenticatable/version.rb +3 -0
  13. data/lib/devise_cas_authenticatable.rb +45 -3
  14. data/lib/devise_cas_authenticatable/missing_session_helpers.rb +9 -0
  15. data/lib/devise_cas_authenticatable/model.rb +5 -6
  16. data/lib/devise_cas_authenticatable/routes.rb +5 -3
  17. data/lib/devise_cas_authenticatable/single_sign_out.rb +22 -0
  18. data/lib/devise_cas_authenticatable/single_sign_out/session_store/active_record.rb +12 -0
  19. data/lib/devise_cas_authenticatable/single_sign_out/session_store/redis.rb +27 -0
  20. data/lib/devise_cas_authenticatable/single_sign_out/strategies.rb +58 -0
  21. data/lib/devise_cas_authenticatable/single_sign_out/strategies/base.rb +11 -0
  22. data/lib/devise_cas_authenticatable/single_sign_out/strategies/rails_cache.rb +31 -0
  23. data/lib/devise_cas_authenticatable/strategy.rb +15 -11
  24. data/spec/devise_cas_authenticatable/model_spec.rb +39 -0
  25. data/spec/routes_spec.rb +25 -7
  26. data/spec/scenario/app/models/user.rb +2 -2
  27. data/spec/scenario/config/environments/development.rb +0 -1
  28. data/spec/scenario/config/initializers/castronaut.rb +1 -0
  29. data/spec/scenario/config/initializers/session_store.rb +2 -2
  30. data/spec/scenario/db/migrate/20100401102949_create_tables.rb +3 -2
  31. data/spec/scenario/db/migrate/20111002012903_add_sessions_table.rb +16 -0
  32. data/spec/scenario/db/schema.rb +25 -0
  33. data/spec/spec_helper.rb +3 -2
  34. data/spec/strategy_spec.rb +20 -29
  35. metadata +118 -27
  36. data/VERSION +0 -1
  37. data/devise_cas_authenticatable.gemspec +0 -118
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7 # (current default)
3
+ - 1.9.2
4
+ gemfile:
5
+ - Gemfile
6
+ script: "bundle exec rake spec"
data/Gemfile CHANGED
@@ -1,26 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'devise'
4
-
5
- group :development do
6
- gem 'linecache', '0.43', :platforms => :mri_18
7
- gem 'ruby-debug', :platforms => :mri_18
8
- gem 'ruby-debug19', :platforms => :mri_19
9
- gem "jeweler"
10
- end
3
+ # Specify your gem's dependencies in devise_bushido_authenticatable.gemspec
4
+ gemspec
11
5
 
12
6
  group :test do
13
7
  gem "rails", ">= 2.3"
14
-
15
- # had to comment this out to use with rails 2.3
16
- # gem "rspec-rails", ">= 2.5.0"
17
- gem 'rspec'
18
-
19
- gem "mocha"
20
- gem "shoulda"
21
- gem "sqlite3-ruby"
22
- gem "sham_rack"
23
- gem "capybara"
24
- gem 'crypt-isaac'
25
- gem 'launchy'
8
+ gem "rspec-rails"
9
+ gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
26
10
  end
@@ -1,97 +1,175 @@
1
+ GIT
2
+ remote: https://github.com/nbudin/castronaut.git
3
+ revision: 61add645b9e6500a2afe7343ee74a83a06303c15
4
+ branch: dam5s-merge
5
+ specs:
6
+ castronaut (0.7.5)
7
+ activerecord (>= 2.0)
8
+ activesupport (>= 2.0)
9
+ builder (>= 2.0.0)
10
+ crypt-isaac (~> 0.9)
11
+ json (~> 1.5.1)
12
+ sinatra (>= 1.0)
13
+
14
+ PATH
15
+ remote: .
16
+ specs:
17
+ devise_bushido_authenticatable (1.0.1)
18
+ devise (>= 1.0.6)
19
+ rubycas-client (>= 2.2.1)
20
+
1
21
  GEM
2
22
  remote: http://rubygems.org/
3
23
  specs:
4
- actionmailer (2.3.2)
5
- actionpack (= 2.3.2)
6
- actionpack (2.3.2)
7
- activesupport (= 2.3.2)
8
- activerecord (2.3.2)
9
- activesupport (= 2.3.2)
10
- activeresource (2.3.2)
11
- activesupport (= 2.3.2)
12
- activesupport (2.3.2)
24
+ actionmailer (3.1.3)
25
+ actionpack (= 3.1.3)
26
+ mail (~> 2.3.0)
27
+ actionpack (3.1.3)
28
+ activemodel (= 3.1.3)
29
+ activesupport (= 3.1.3)
30
+ builder (~> 3.0.0)
31
+ erubis (~> 2.7.0)
32
+ i18n (~> 0.6)
33
+ rack (~> 1.3.5)
34
+ rack-cache (~> 1.1)
35
+ rack-mount (~> 0.8.2)
36
+ rack-test (~> 0.6.1)
37
+ sprockets (~> 2.0.3)
38
+ activemodel (3.1.3)
39
+ activesupport (= 3.1.3)
40
+ builder (~> 3.0.0)
41
+ i18n (~> 0.6)
42
+ activerecord (3.1.3)
43
+ activemodel (= 3.1.3)
44
+ activesupport (= 3.1.3)
45
+ arel (~> 2.2.1)
46
+ tzinfo (~> 0.3.29)
47
+ activeresource (3.1.3)
48
+ activemodel (= 3.1.3)
49
+ activesupport (= 3.1.3)
50
+ activesupport (3.1.3)
51
+ multi_json (~> 1.0)
13
52
  addressable (2.2.6)
14
- archive-tar-minitar (0.5.2)
15
- bcrypt-ruby (2.1.4)
16
- capybara (1.0.0)
53
+ arel (2.2.1)
54
+ bcrypt-ruby (3.0.1)
55
+ builder (3.0.0)
56
+ capybara (1.1.2)
17
57
  mime-types (>= 1.16)
18
58
  nokogiri (>= 1.3.3)
19
59
  rack (>= 1.0.0)
20
60
  rack-test (>= 0.5.4)
21
- selenium-webdriver (~> 0.2.0)
61
+ selenium-webdriver (~> 2.0)
22
62
  xpath (~> 0.1.4)
23
- childprocess (0.2.0)
63
+ childprocess (0.2.3)
24
64
  ffi (~> 1.0.6)
25
- columnize (0.3.4)
65
+ coderay (0.9.8)
26
66
  crypt-isaac (0.9.1)
27
- devise (1.4.2)
28
- bcrypt-ruby (~> 2.1.2)
67
+ devise (1.5.2)
68
+ bcrypt-ruby (~> 3.0)
29
69
  orm_adapter (~> 0.0.3)
30
- warden (~> 1.0.3)
31
- diff-lcs (1.1.2)
32
- ffi (1.0.9)
33
- git (1.2.5)
34
- jeweler (1.6.4)
35
- bundler (~> 1.0)
36
- git (>= 1.2.5)
37
- rake
38
- json_pure (1.5.3)
70
+ warden (~> 1.1)
71
+ diff-lcs (1.1.3)
72
+ erubis (2.7.0)
73
+ ffi (1.0.11)
74
+ hike (1.2.1)
75
+ i18n (0.6.0)
76
+ json (1.5.4)
39
77
  launchy (2.0.5)
40
78
  addressable (~> 2.2.6)
41
- linecache (0.43)
42
- linecache19 (0.5.12)
43
- ruby_core_source (>= 0.1.4)
44
- mime-types (1.16)
45
- mocha (0.9.12)
79
+ mail (2.3.0)
80
+ i18n (>= 0.4.0)
81
+ mime-types (~> 1.16)
82
+ treetop (~> 1.4.8)
83
+ metaclass (0.0.1)
84
+ method_source (0.6.7)
85
+ ruby_parser (>= 2.3.1)
86
+ mime-types (1.17.2)
87
+ mocha (0.10.0)
88
+ metaclass (~> 0.0.1)
89
+ multi_json (1.0.4)
46
90
  nokogiri (1.5.0)
47
91
  orm_adapter (0.0.5)
48
- rack (1.3.2)
92
+ polyglot (0.3.3)
93
+ pry (0.9.7.4)
94
+ coderay (~> 0.9.8)
95
+ method_source (~> 0.6.7)
96
+ ruby_parser (>= 2.3.1)
97
+ slop (~> 2.1.0)
98
+ rack (1.3.5)
99
+ rack-cache (1.1)
100
+ rack (>= 0.4)
101
+ rack-mount (0.8.3)
102
+ rack (>= 1.0.0)
103
+ rack-protection (1.1.4)
104
+ rack
105
+ rack-ssl (1.3.2)
106
+ rack
49
107
  rack-test (0.6.1)
50
108
  rack (>= 1.0)
51
- rails (2.3.2)
52
- actionmailer (= 2.3.2)
53
- actionpack (= 2.3.2)
54
- activerecord (= 2.3.2)
55
- activeresource (= 2.3.2)
56
- activesupport (= 2.3.2)
57
- rake (>= 0.8.3)
58
- rake (0.9.2)
59
- rspec (2.6.0)
60
- rspec-core (~> 2.6.0)
61
- rspec-expectations (~> 2.6.0)
62
- rspec-mocks (~> 2.6.0)
63
- rspec-core (2.6.4)
64
- rspec-expectations (2.6.0)
109
+ rails (3.1.3)
110
+ actionmailer (= 3.1.3)
111
+ actionpack (= 3.1.3)
112
+ activerecord (= 3.1.3)
113
+ activeresource (= 3.1.3)
114
+ activesupport (= 3.1.3)
115
+ bundler (~> 1.0)
116
+ railties (= 3.1.3)
117
+ railties (3.1.3)
118
+ actionpack (= 3.1.3)
119
+ activesupport (= 3.1.3)
120
+ rack-ssl (~> 1.3.2)
121
+ rake (>= 0.8.7)
122
+ rdoc (~> 3.4)
123
+ thor (~> 0.14.6)
124
+ rake (0.9.2.2)
125
+ rdoc (3.11)
126
+ json (~> 1.4)
127
+ rspec (2.7.0)
128
+ rspec-core (~> 2.7.0)
129
+ rspec-expectations (~> 2.7.0)
130
+ rspec-mocks (~> 2.7.0)
131
+ rspec-core (2.7.1)
132
+ rspec-expectations (2.7.0)
65
133
  diff-lcs (~> 1.1.2)
66
- rspec-mocks (2.6.0)
67
- ruby-debug (0.10.4)
68
- columnize (>= 0.1)
69
- ruby-debug-base (~> 0.10.4.0)
70
- ruby-debug-base (0.10.4)
71
- linecache (>= 0.3)
72
- ruby-debug-base19 (0.11.25)
73
- columnize (>= 0.3.1)
74
- linecache19 (>= 0.5.11)
75
- ruby_core_source (>= 0.1.4)
76
- ruby-debug19 (0.11.6)
77
- columnize (>= 0.3.1)
78
- linecache19 (>= 0.5.11)
79
- ruby-debug-base19 (>= 0.11.19)
80
- ruby_core_source (0.1.5)
81
- archive-tar-minitar (>= 0.5.2)
82
- rubyzip (0.9.4)
83
- selenium-webdriver (0.2.2)
84
- childprocess (>= 0.1.9)
85
- ffi (>= 1.0.7)
86
- json_pure
134
+ rspec-mocks (2.7.0)
135
+ rspec-rails (2.7.0)
136
+ actionpack (~> 3.0)
137
+ activesupport (~> 3.0)
138
+ railties (~> 3.0)
139
+ rspec (~> 2.7.0)
140
+ ruby_parser (2.3.1)
141
+ sexp_processor (~> 3.0)
142
+ rubycas-client (2.2.1)
143
+ activesupport
144
+ rubyzip (0.9.5)
145
+ selenium-webdriver (2.15.0)
146
+ childprocess (>= 0.2.1)
147
+ ffi (~> 1.0.9)
148
+ multi_json (~> 1.0.4)
87
149
  rubyzip
150
+ sexp_processor (3.0.9)
88
151
  sham_rack (1.3.3)
89
152
  rack
90
153
  shoulda (2.11.3)
91
- sqlite3 (1.3.4)
154
+ sinatra (1.3.1)
155
+ rack (~> 1.3, >= 1.3.4)
156
+ rack-protection (~> 1.1, >= 1.1.2)
157
+ tilt (~> 1.3, >= 1.3.3)
158
+ slop (2.1.0)
159
+ sprockets (2.0.3)
160
+ hike (~> 1.2)
161
+ rack (~> 1.0)
162
+ tilt (~> 1.1, != 1.3.0)
163
+ sqlite3 (1.3.5)
92
164
  sqlite3-ruby (1.3.3)
93
165
  sqlite3 (>= 1.3.3)
94
- warden (1.0.5)
166
+ thor (0.14.6)
167
+ tilt (1.3.3)
168
+ treetop (1.4.10)
169
+ polyglot
170
+ polyglot (>= 0.3.1)
171
+ tzinfo (0.3.31)
172
+ warden (1.1.0)
95
173
  rack (>= 1.0)
96
174
  xpath (0.1.4)
97
175
  nokogiri (~> 1.3)
@@ -101,16 +179,15 @@ PLATFORMS
101
179
 
102
180
  DEPENDENCIES
103
181
  capybara
182
+ castronaut!
104
183
  crypt-isaac
105
- devise
106
- jeweler
184
+ devise_bushido_authenticatable!
107
185
  launchy
108
- linecache (= 0.43)
109
186
  mocha
187
+ pry
110
188
  rails (>= 2.3)
111
189
  rspec
112
- ruby-debug
113
- ruby-debug19
190
+ rspec-rails
114
191
  sham_rack
115
192
  shoulda
116
193
  sqlite3-ruby
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  devise_bushido_authenticatable
2
- ===============================
2
+ =======
3
3
 
4
4
  devise_bushido_authenticatable provides single sign-on support for Bushido applications, that use
5
5
  [Devise](http://github.com/plataformatec/devise) for authentication. It acts as a **replacement for the database_authenticatable option that devise provides**
@@ -42,9 +42,10 @@ Setup
42
42
 
43
43
  ### 1.) Add the following to your devise model
44
44
 
45
+ attr_accessor :ido_id
45
46
  devise :bushido_authenticatable
46
47
 
47
- You can add other modules like trackable, but **do not use database_authenticatable**. bushido_authenticatable is a replacement for that.
48
+ To the devise() method, you can add other modules like trackable, but **do not use database_authenticatable**. bushido_authenticatable is a replacement for that.
48
49
 
49
50
  ### 2.) Modify schema migration
50
51
 
@@ -75,6 +76,7 @@ When the user is authenticated, Bushido passed along the following extra attribu
75
76
  If you find any of these attributes useful and want to capture them, add a bushido_extra_attributes method to your User model (or whichever is your devise model). Below is an example that saves the email and the locale of a user.
76
77
 
77
78
  class User < ActiveRecord::Base
79
+ attr_accessor :ido_id
78
80
  devise :bushido_authenticatable
79
81
 
80
82
  def bushido_extra_attributes(extra_attributes)
data/Rakefile CHANGED
@@ -1,46 +1 @@
1
- require 'bundler'
2
-
3
- Bundler.setup
4
-
5
- require 'rake'
6
- require 'rake/rdoctask'
7
- require 'rspec/mocks/version'
8
- require 'rspec/core/rake_task'
9
-
10
- RSpec::Core::RakeTask.new(:spec)
11
-
12
- desc 'Default: run specs.'
13
- task :default => :spec
14
-
15
- desc 'Generate documentation for the devise_bushido_authenticatable plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'devise_bushido_authenticatable'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
23
-
24
-
25
- begin
26
- require 'jeweler'
27
- Jeweler::Tasks.new do |gemspec|
28
- gemspec.name = "devise_bushido_authenticatable"
29
- gemspec.summary = "Bushido SSO authentication module for Devise"
30
- gemspec.description = "Bushido SSO authentication module for Devise. A slight variant of the excellent work from Nat Budlin on devise_cas_authenticatable."
31
- gemspec.email = "s@bushi.do"
32
- gemspec.homepage = "http://github.com/bushido/bushido_cas_authenticatable"
33
- gemspec.authors = ["Akash Manohar J", "Sean Grove", "Didier Lafforgue"]
34
- gemspec.add_runtime_dependency "devise", ">= 1.0.6"
35
- gemspec.add_runtime_dependency "rubycas-client", ">= 2.2.1"
36
- end
37
- Jeweler::RubygemsDotOrgTasks.new
38
- rescue LoadError
39
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
40
- end
41
-
42
- # namespace :scenario do
43
- # require File.expand_path('../spec/scenario/config/application', __FILE__)
44
- #
45
- # Scenario::Application.load_tasks
46
- # end
1
+ require "bundler/gem_tasks"
@@ -1,19 +1,12 @@
1
1
  class Devise::CasSessionsController < Devise::SessionsController
2
- unloadable
3
2
 
4
3
  def new
5
- unless returning_from_cas?
6
- redirect_to(cas_login_url)
7
- end
4
+ redirect_to(cas_login_url) unless returning_from_cas?
8
5
  end
9
6
 
10
7
  def service
11
8
  warden.authenticate!(:scope => resource_name)
12
-
13
- if params[:redirect]
14
- return redirect_to params[:redirect]
15
- end
16
-
9
+ return redirect_to params[:redirect] if params[:redirect]
17
10
  return redirect_to after_sign_in_path_for(resource_name)
18
11
  end
19
12
 
@@ -21,6 +14,11 @@ class Devise::CasSessionsController < Devise::SessionsController
21
14
  end
22
15
 
23
16
  def destroy
17
+ # Delete the ticket->session ID mapping if one exists for this session
18
+ if ticket = session['cas_last_valid_ticket']
19
+ ::DeviseCasAuthenticatable::SingleSignOut::Strategies.current_strategy.delete_session_index(ticket)
20
+ end
21
+
24
22
  # if :cas_create_user is false a CAS session might be open but not signed_in
25
23
  # in such case we destroy the session here
26
24
  if signed_in?(resource_name)
@@ -31,7 +29,58 @@ class Devise::CasSessionsController < Devise::SessionsController
31
29
  redirect_to(::Devise.cas_client.logout_url)
32
30
  end
33
31
 
34
- private
32
+ def single_sign_out
33
+ if ::Devise.cas_enable_single_sign_out
34
+ session_index = read_session_index
35
+ if session_index
36
+ logger.info "Intercepted single-sign-out request for CAS session #{session_index}."
37
+ session_id = ::DeviseCasAuthenticatable::SingleSignOut::Strategies.current_strategy.find_session_id_by_index(session_index)
38
+ destroy_cas_session(session_id, session_index) if session_id
39
+ else
40
+ logger.warn "Ignoring CAS single-sign-out request as no session index could be parsed from the parameters."
41
+ end
42
+ else
43
+ logger.warn "Ignoring CAS single-sign-out request as feature is not currently enabled."
44
+ end
45
+
46
+ render :nothing => true
47
+ end
48
+
49
+ protected
50
+
51
+ def read_session_index
52
+ if request.headers['CONTENT_TYPE'] =~ %r{^multipart/}
53
+ false
54
+ elsif request.post? && params['logoutRequest'] =~
55
+ %r{^<samlp:LogoutRequest.*?<samlp:SessionIndex>(.*)</samlp:SessionIndex>}m
56
+ $~[1]
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ def destroy_cas_session(session_id, session_index)
63
+ if session_store && session_store.new.respond_to?(:destroy)
64
+ if session_store.respond_to? :find_by_session_id
65
+ user_session = session_store.find_by_session_id(session_id)
66
+ elsif session_store.respond_to? :find
67
+ user_session = session_store.find(session_id)
68
+ end
69
+ user_session.destroy if user_session
70
+ else
71
+ logger.info "A single sign out request was received for ticket #{session_index} but the Rails session_store is not a type supported for single-sign-out by devise_cas_authenticatable."
72
+ end
73
+ ::DeviseCasAuthenticatable::SingleSignOut::Strategies.current_strategy.delete_session_index(session_index)
74
+ end
75
+
76
+ def session_store
77
+ if ::Rails.respond_to? :application
78
+ return @session_store ||= Rails.application.config.session_store.session_class
79
+ elsif ::ActionController::Base.respond_to? :session_store
80
+ return @session_store ||= ActionController::Base.session_store.session_class
81
+ end
82
+ end
83
+
35
84
  def returning_from_cas?
36
85
  params[:ticket] || request.referer =~ /^#{::Devise.cas_client.cas_base_url}/
37
86
  end