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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -20
- data/Gemfile.lock +151 -74
- data/README.md +4 -2
- data/Rakefile +1 -46
- data/app/controllers/devise/cas_sessions_controller.rb +59 -10
- data/app/views/devise/cas_sessions/unregistered.html.erb +150 -2
- data/app/views/devise/cas_sessions/unregistered.html.erb.old +2 -0
- data/devise_bushido_authenticatable.gemspec +28 -95
- data/lib/devise_bushido_authenticatable/version.rb +3 -0
- data/lib/devise_cas_authenticatable.rb +45 -3
- data/lib/devise_cas_authenticatable/missing_session_helpers.rb +9 -0
- data/lib/devise_cas_authenticatable/model.rb +5 -6
- data/lib/devise_cas_authenticatable/routes.rb +5 -3
- data/lib/devise_cas_authenticatable/single_sign_out.rb +22 -0
- data/lib/devise_cas_authenticatable/single_sign_out/session_store/active_record.rb +12 -0
- data/lib/devise_cas_authenticatable/single_sign_out/session_store/redis.rb +27 -0
- data/lib/devise_cas_authenticatable/single_sign_out/strategies.rb +58 -0
- data/lib/devise_cas_authenticatable/single_sign_out/strategies/base.rb +11 -0
- data/lib/devise_cas_authenticatable/single_sign_out/strategies/rails_cache.rb +31 -0
- data/lib/devise_cas_authenticatable/strategy.rb +15 -11
- data/spec/devise_cas_authenticatable/model_spec.rb +39 -0
- data/spec/routes_spec.rb +25 -7
- data/spec/scenario/app/models/user.rb +2 -2
- data/spec/scenario/config/environments/development.rb +0 -1
- data/spec/scenario/config/initializers/castronaut.rb +1 -0
- data/spec/scenario/config/initializers/session_store.rb +2 -2
- data/spec/scenario/db/migrate/20100401102949_create_tables.rb +3 -2
- data/spec/scenario/db/migrate/20111002012903_add_sessions_table.rb +16 -0
- data/spec/scenario/db/schema.rb +25 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/strategy_spec.rb +20 -29
- metadata +118 -27
- data/VERSION +0 -1
- data/devise_cas_authenticatable.gemspec +0 -118
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
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
|
-
|
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
|
data/Gemfile.lock
CHANGED
@@ -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 (
|
5
|
-
actionpack (=
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
activesupport (=
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
bcrypt-ruby (
|
16
|
-
|
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 (~>
|
61
|
+
selenium-webdriver (~> 2.0)
|
22
62
|
xpath (~> 0.1.4)
|
23
|
-
childprocess (0.2.
|
63
|
+
childprocess (0.2.3)
|
24
64
|
ffi (~> 1.0.6)
|
25
|
-
|
65
|
+
coderay (0.9.8)
|
26
66
|
crypt-isaac (0.9.1)
|
27
|
-
devise (1.
|
28
|
-
bcrypt-ruby (~>
|
67
|
+
devise (1.5.2)
|
68
|
+
bcrypt-ruby (~> 3.0)
|
29
69
|
orm_adapter (~> 0.0.3)
|
30
|
-
warden (~> 1.
|
31
|
-
diff-lcs (1.1.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
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 (
|
52
|
-
actionmailer (=
|
53
|
-
actionpack (=
|
54
|
-
activerecord (=
|
55
|
-
activeresource (=
|
56
|
-
activesupport (=
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|