devise_cas_authenticatable 1.10.4 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +32 -0
- data/.gitignore +0 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile +8 -0
- data/README.md +84 -88
- data/app/controllers/devise/cas_sessions_controller.rb +23 -67
- data/app/views/devise/cas_sessions/unregistered.html.erb +3 -3
- data/devise_cas_authenticatable.gemspec +19 -26
- data/lib/devise_cas_authenticatable.rb +15 -70
- data/lib/devise_cas_authenticatable/model.rb +21 -28
- data/lib/devise_cas_authenticatable/routes.rb +22 -44
- data/lib/devise_cas_authenticatable/strategy.rb +14 -24
- data/spec/model_spec.rb +29 -35
- data/spec/routes_spec.rb +26 -26
- data/spec/scenario/app/assets/config/manifest.js +0 -0
- data/spec/scenario/app/controllers/home_controller.rb +2 -2
- data/spec/scenario/app/views/layouts/application.html.erb +1 -3
- data/spec/scenario/config/application.rb +1 -27
- data/spec/scenario/config/initializers/backtrace_silencers.rb +1 -1
- data/spec/scenario/config/initializers/devise.rb +2 -2
- data/spec/scenario/config/routes.rb +0 -4
- data/spec/scenario/db/migrate/20100401102949_create_tables.rb +3 -3
- data/spec/scenario/db/migrate/20111002012903_add_sessions_table.rb +1 -1
- data/spec/scenario/db/migrate/20121009092400_add_deactivated_flag_to_users.rb +1 -1
- data/spec/spec_helper.rb +38 -8
- data/spec/strategy_spec.rb +43 -82
- data/spec/support/migrations.rb +1 -1
- metadata +18 -123
- data/.travis.yml +0 -45
- data/Gemfile.devise12 +0 -11
- data/Gemfile.devise13 +0 -11
- data/Gemfile.devise14 +0 -11
- data/Gemfile.devise15 +0 -11
- data/Gemfile.devise20 +0 -11
- data/Gemfile.devise21 +0 -13
- data/Gemfile.devise30 +0 -12
- data/Gemfile.devise42 +0 -13
- data/lib/devise_cas_authenticatable/exceptions.rb +0 -10
- data/lib/devise_cas_authenticatable/memcache_checker.rb +0 -42
- data/lib/devise_cas_authenticatable/railtie.rb +0 -14
- data/lib/devise_cas_authenticatable/schema.rb +0 -20
- data/lib/devise_cas_authenticatable/session_store_identifier.rb +0 -29
- data/lib/devise_cas_authenticatable/single_sign_out.rb +0 -69
- data/lib/devise_cas_authenticatable/single_sign_out/rack.rb +0 -39
- data/lib/devise_cas_authenticatable/single_sign_out/strategies.rb +0 -58
- data/lib/devise_cas_authenticatable/single_sign_out/strategies/base.rb +0 -11
- data/lib/devise_cas_authenticatable/single_sign_out/strategies/rails_cache.rb +0 -31
- data/lib/devise_cas_authenticatable/single_sign_out/strategies/redis_cache.rb +0 -38
- data/lib/devise_cas_authenticatable/single_sign_out/warden_failure_app.rb +0 -46
- data/lib/devise_cas_authenticatable/single_sign_out/with_conn.rb +0 -14
- data/spec/config_spec.rb +0 -27
- data/spec/memcache_checker_spec.rb +0 -49
- data/spec/scenario/config/castronaut.yml +0 -32
- data/spec/scenario/config/initializers/castronaut.rb +0 -1
- data/spec/scenario/config/initializers/session_store.rb +0 -8
- data/spec/single_sign_out_spec.rb +0 -51
- data/spec/support/urls.rb +0 -19
- data/spec/warden_failure_app_spec.rb +0 -53
data/.travis.yml
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
rvm:
|
2
|
-
- 1.9.3
|
3
|
-
- 2.0.0
|
4
|
-
- 2.1.2
|
5
|
-
- 2.2.4
|
6
|
-
- 2.3.0
|
7
|
-
gemfile:
|
8
|
-
- Gemfile.devise12
|
9
|
-
- Gemfile.devise13
|
10
|
-
- Gemfile.devise14
|
11
|
-
- Gemfile.devise15
|
12
|
-
- Gemfile.devise20
|
13
|
-
- Gemfile.devise21
|
14
|
-
- Gemfile.devise30
|
15
|
-
- Gemfile.devise42
|
16
|
-
|
17
|
-
# Exclude unsupported Ruby/Rails combinations
|
18
|
-
matrix:
|
19
|
-
exclude:
|
20
|
-
- rvm: 1.9.3
|
21
|
-
gemfile: Gemfile.devise30
|
22
|
-
- rvm: 2.0.0
|
23
|
-
gemfile: Gemfile.devise30
|
24
|
-
- rvm: 2.1.2
|
25
|
-
gemfile: Gemfile.devise30
|
26
|
-
- rvm: 1.9.3
|
27
|
-
gemfile: Gemfile.devise42
|
28
|
-
- rvm: 2.0.0
|
29
|
-
gemfile: Gemfile.devise42
|
30
|
-
- rvm: 2.1.2
|
31
|
-
gemfile: Gemfile.devise42
|
32
|
-
- rvm: 2.2.4
|
33
|
-
gemfile: Gemfile.devise12
|
34
|
-
- rvm: 2.2.4
|
35
|
-
gemfile: Gemfile.devise13
|
36
|
-
- rvm: 2.3.0
|
37
|
-
gemfile: Gemfile.devise12
|
38
|
-
- rvm: 2.3.0
|
39
|
-
gemfile: Gemfile.devise13
|
40
|
-
|
41
|
-
before_install:
|
42
|
-
- gem update bundler
|
43
|
-
script: "bundle exec rake spec"
|
44
|
-
sudo: required
|
45
|
-
dist: trusty
|
data/Gemfile.devise12
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 3.1.0'
|
7
|
-
gem 'devise', '~> 1.2.0'
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
11
|
-
end
|
data/Gemfile.devise13
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 3.1.0'
|
7
|
-
gem 'devise', '~> 1.3.0'
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
11
|
-
end
|
data/Gemfile.devise14
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 3.2.0'
|
7
|
-
gem 'devise', '~> 1.4.0'
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
11
|
-
end
|
data/Gemfile.devise15
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 3.2.0'
|
7
|
-
gem 'devise', '~> 1.5.0'
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
11
|
-
end
|
data/Gemfile.devise20
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 3.2.0'
|
7
|
-
gem 'devise', '~> 2.0.0'
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
11
|
-
end
|
data/Gemfile.devise21
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 3.2.0'
|
7
|
-
gem 'devise', '~> 2.1.0'
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
11
|
-
gem 'minitest'
|
12
|
-
gem 'test-unit'
|
13
|
-
end
|
data/Gemfile.devise30
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 4.0.0'
|
7
|
-
gem 'devise', '~> 3.0.0'
|
8
|
-
gem 'activerecord-session_store'
|
9
|
-
|
10
|
-
group :test do
|
11
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
12
|
-
end
|
data/Gemfile.devise42
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in devise_cas_authenticatable.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem 'rails', '~> 5.0.0'
|
7
|
-
gem 'devise', '~> 4.2.0'
|
8
|
-
gem 'activerecord-session_store'
|
9
|
-
gem 'sinatra', '~> 2.0.0.beta2'
|
10
|
-
|
11
|
-
group :test do
|
12
|
-
gem 'castronaut', :git => 'https://github.com/nbudin/castronaut.git', :branch => 'dam5s-merge'
|
13
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
require 'timeout'
|
3
|
-
|
4
|
-
module DeviseCasAuthenticatable
|
5
|
-
class MemcacheChecker
|
6
|
-
attr_reader :rails_configuration
|
7
|
-
|
8
|
-
def initialize(rails_configuration)
|
9
|
-
@rails_configuration = rails_configuration
|
10
|
-
end
|
11
|
-
|
12
|
-
def session_store_memcache?
|
13
|
-
!!(session_store_class.name =~ /memcache/i)
|
14
|
-
end
|
15
|
-
|
16
|
-
def alive?
|
17
|
-
memcache_servers = rails_configuration.session_options[:memcache_server] || ["127.0.0.1:11211"]
|
18
|
-
memcache_servers.each do |server|
|
19
|
-
host, port = server.split(":")
|
20
|
-
begin
|
21
|
-
try_connect host, port
|
22
|
-
|
23
|
-
return true
|
24
|
-
rescue Errno::ECONNREFUSED, Timeout::Error
|
25
|
-
return false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def try_connect(host, port)
|
31
|
-
Timeout::timeout(1) do
|
32
|
-
TCPSocket.open(host, port)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def session_store_class
|
39
|
-
@session_store_class ||= DeviseCasAuthenticatable::SessionStoreIdentifier.new.session_store_class
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'devise_cas_authenticatable'
|
2
|
-
require 'rails'
|
3
|
-
|
4
|
-
module DeviseCasAuthenticatable
|
5
|
-
class Railtie < ::Rails::Railtie
|
6
|
-
initializer "devise_cas_authenticatable.use_rack_middleware" do |app|
|
7
|
-
if Rails::VERSION::MAJOR < 5
|
8
|
-
app.config.middleware.use "DeviseCasAuthenticatable::SingleSignOut::StoreSessionId"
|
9
|
-
else
|
10
|
-
app.config.middleware.use DeviseCasAuthenticatable::SingleSignOut::StoreSessionId
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'devise/version'
|
2
|
-
|
3
|
-
# Devise 2.1 removes schema stuff
|
4
|
-
if Devise::VERSION < "2.1"
|
5
|
-
require 'devise/schema'
|
6
|
-
|
7
|
-
module Devise
|
8
|
-
module Schema
|
9
|
-
# Adds the required fields for cas_authenticatable to the schema. Currently
|
10
|
-
# this is just username (String).
|
11
|
-
def cas_authenticatable
|
12
|
-
if respond_to? :apply_devise_schema
|
13
|
-
apply_devise_schema :username, String
|
14
|
-
else
|
15
|
-
apply_schema :username, String
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module DeviseCasAuthenticatable
|
2
|
-
class SessionStoreIdentifier
|
3
|
-
|
4
|
-
def current_session_store
|
5
|
-
app = Rails.application.app
|
6
|
-
begin
|
7
|
-
app = (app.instance_variable_get(:@backend) || app.instance_variable_get(:@app) || app.instance_variable_get(:@target))
|
8
|
-
end until app.nil? or app.class == session_store_class
|
9
|
-
app
|
10
|
-
end
|
11
|
-
|
12
|
-
def session_store_class
|
13
|
-
@session_store_class ||=
|
14
|
-
begin
|
15
|
-
# Rails 3 & 4 session store
|
16
|
-
if ::DeviseCasAuthenticatable::SingleSignOut.rails3_or_greater?
|
17
|
-
Rails.configuration.session_store
|
18
|
-
::Rails.application.config.session_store
|
19
|
-
else
|
20
|
-
# => Rails 2
|
21
|
-
ActionController::Base.session_store
|
22
|
-
end
|
23
|
-
rescue NameError => e
|
24
|
-
# for older versions of Rails (prior to 2.3)
|
25
|
-
ActionController::Base.session_options[:database_manager]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'devise_cas_authenticatable/single_sign_out/with_conn'
|
2
|
-
|
3
|
-
module DeviseCasAuthenticatable
|
4
|
-
module SingleSignOut
|
5
|
-
|
6
|
-
def self.rails3_or_greater?
|
7
|
-
defined?(::Rails) && ::Rails::VERSION::MAJOR >= 3
|
8
|
-
end
|
9
|
-
|
10
|
-
# Supports destroying sessions by ID for ActiveRecord and Redis session stores
|
11
|
-
module DestroySession
|
12
|
-
include ::DeviseCasAuthenticatable::SingleSignOut::WithConn
|
13
|
-
|
14
|
-
def destroy_session_by_id(sid)
|
15
|
-
logger.debug "Single Sign Out from session store: #{current_session_store.class}"
|
16
|
-
|
17
|
-
if session_store_class.name =~ /ActiveRecord::SessionStore/
|
18
|
-
session = session_store_class::Session.find_by_session_id(sid)
|
19
|
-
session.destroy if session
|
20
|
-
true
|
21
|
-
elsif session_store_class.name =~ /ActionDispatch::Session::ActiveRecordStore/
|
22
|
-
session = current_session_store.session_class.find_by_session_id(sid)
|
23
|
-
session.destroy if session
|
24
|
-
true
|
25
|
-
elsif session_store_class.name =~ /ActionDispatch::Session::DalliStore/
|
26
|
-
current_session_store.send(:destroy_session, env, sid, drop: true)
|
27
|
-
true
|
28
|
-
elsif session_store_class.name =~ /RedisSessionStore/
|
29
|
-
current_session_store.send(:destroy_session, env, sid, drop: true)
|
30
|
-
true
|
31
|
-
elsif session_store_class.name =~ /Redis/
|
32
|
-
with_conn { |conn| conn.del(sid) }
|
33
|
-
true
|
34
|
-
elsif session_store_class.name =~ /CacheStore/
|
35
|
-
if current_session_store.respond_to?(:delete_session) # Rails 5 and up
|
36
|
-
current_session_store.delete_session({}, sid, {})
|
37
|
-
else
|
38
|
-
current_session_store.destroy_session({}, sid, {})
|
39
|
-
end
|
40
|
-
|
41
|
-
true
|
42
|
-
else
|
43
|
-
logger.error "Cannot process logout request because this Rails application's session store is "+
|
44
|
-
" #{session_store_class.name} and is not a support session store type for Single Sign-Out."
|
45
|
-
false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def session_store_identifier
|
50
|
-
@session_store_identifier ||= DeviseCasAuthenticatable::SessionStoreIdentifier.new
|
51
|
-
end
|
52
|
-
|
53
|
-
def current_session_store
|
54
|
-
session_store_identifier.current_session_store
|
55
|
-
end
|
56
|
-
|
57
|
-
def session_store_class
|
58
|
-
session_store_identifier.session_store_class
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
require 'devise_cas_authenticatable/single_sign_out/strategies'
|
66
|
-
require 'devise_cas_authenticatable/single_sign_out/strategies/base'
|
67
|
-
require 'devise_cas_authenticatable/single_sign_out/strategies/rails_cache'
|
68
|
-
require 'devise_cas_authenticatable/single_sign_out/strategies/redis_cache'
|
69
|
-
require 'devise_cas_authenticatable/single_sign_out/rack'
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module DeviseCasAuthenticatable
|
2
|
-
module SingleSignOut
|
3
|
-
|
4
|
-
class StoreSessionId
|
5
|
-
CAS_TICKET_STORE = 'cas_last_valid_ticket_store'
|
6
|
-
CAS_LAST_TICKET = 'cas_last_valid_ticket'
|
7
|
-
|
8
|
-
def initialize(app)
|
9
|
-
@app = app
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(env)
|
13
|
-
store_session_id_for_cas_ticket(env)
|
14
|
-
@app.call(env)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
def store_session_id_for_cas_ticket(env)
|
19
|
-
request = Rack::Request.new(env)
|
20
|
-
session = request.session
|
21
|
-
|
22
|
-
if session.respond_to?(:id)
|
23
|
-
# Rack > 1.5
|
24
|
-
session_id = session.id
|
25
|
-
else
|
26
|
-
# Compatible with old Rack requests
|
27
|
-
session_id = env['rack.session.options'][:id]
|
28
|
-
end
|
29
|
-
cas_ticket_store = session[CAS_TICKET_STORE]
|
30
|
-
|
31
|
-
if cas_ticket_store
|
32
|
-
Rails.logger.info "Storing Session ID #{session_id} for ticket #{session[CAS_LAST_TICKET]}"
|
33
|
-
::DeviseCasAuthenticatable::SingleSignOut::Strategies.current_strategy.store_session_id_for_index(session[CAS_LAST_TICKET], session_id)
|
34
|
-
session[CAS_TICKET_STORE] = false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module DeviseCasAuthenticatable
|
2
|
-
module SingleSignOut
|
3
|
-
module Strategies
|
4
|
-
class << self
|
5
|
-
|
6
|
-
# Add a strategy and store it in a hash.
|
7
|
-
def add(label, strategy, &block)
|
8
|
-
strategy ||= Class.new(DeviseCasAuthenticatable::SingleSignOut::Strategies::Base)
|
9
|
-
strategy.class_eval(&block) if block_given?
|
10
|
-
|
11
|
-
check_method(label, strategy, :store_session_id_for_index)
|
12
|
-
check_method(label, strategy, :find_session_id_by_index)
|
13
|
-
check_method(label, strategy, :delete_session_index)
|
14
|
-
|
15
|
-
unless strategy.ancestors.include?(DeviseCasAuthenticatable::SingleSignOut::Strategies::Base)
|
16
|
-
raise "#{label.inspect} is not a #{base}"
|
17
|
-
end
|
18
|
-
|
19
|
-
_strategies[label] = strategy.new()
|
20
|
-
end
|
21
|
-
|
22
|
-
# Update a previously given strategy.
|
23
|
-
def update(label, &block)
|
24
|
-
strategy = _strategies[label]
|
25
|
-
raise "Unknown strategy #{label.inspect}" unless strategy
|
26
|
-
add(label, strategy, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Provides access to strategies by label
|
30
|
-
def [](label)
|
31
|
-
_strategies[label]
|
32
|
-
end
|
33
|
-
|
34
|
-
def current_strategy
|
35
|
-
self[::Devise.cas_single_sign_out_mapping_strategy]
|
36
|
-
end
|
37
|
-
|
38
|
-
# Clears all declared.
|
39
|
-
def clear!
|
40
|
-
_strategies.clear
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def _strategies
|
46
|
-
@strategies ||= {}
|
47
|
-
end
|
48
|
-
|
49
|
-
def check_method(label, strategy, method)
|
50
|
-
unless strategy.method_defined?(method)
|
51
|
-
raise NoMethodError, "#{method.to_s} is not declared in the #{label.inspect} strategy"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|