From b4c81cba0181156d60c91ad79dafdb2fedd78d15 Mon Sep 17 00:00:00 2001 From: Denis Yagofarov Date: Wed, 16 May 2012 16:48:09 +0300 Subject: [PATCH 1/3] Fix for "Redis(Session)Store" recognition (as for new 'redis-rails' gem), Fix bug with undefined 'log' method: tested on Rails 3.0 and 3.2, Safer output of current_session_store name --- lib/devise_cas_authenticatable/single_sign_out.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/devise_cas_authenticatable/single_sign_out.rb b/lib/devise_cas_authenticatable/single_sign_out.rb index 1627beb..cae4b9e 100644 --- a/lib/devise_cas_authenticatable/single_sign_out.rb +++ b/lib/devise_cas_authenticatable/single_sign_out.rb @@ -36,12 +36,12 @@ def destroy_session_by_id(sid) session = current_session_store::Session.find_by_session_id(sid) session.destroy if session true - elsif session_store_class.name =~ /RedisSessionStore/ + elsif session_store_class.name =~ /Redis.*Store/ current_session_store.instance_variable_get(:@pool).del(sid) true else - log.error "Cannot process logout request because this Rails application's session store is "+ - " #{current_session_store.name.inspect} and is not a support session store type for Single Sign-Out." + ::Rails.logger.error "Cannot process logout request because this Rails application's session store is "+ + " #{current_session_store.class.to_s} and is not a support session store type for Single Sign-Out." false end end From 3bf8b213aa98aa0a222a3c4dad4c50f2e9d18a22 Mon Sep 17 00:00:00 2001 From: Denis Yagofarov Date: Wed, 23 May 2012 19:43:34 +0300 Subject: [PATCH 2/3] Fix finding of session storage middleware in production enviroment --- .../single_sign_out.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/devise_cas_authenticatable/single_sign_out.rb b/lib/devise_cas_authenticatable/single_sign_out.rb index cae4b9e..54f27e0 100644 --- a/lib/devise_cas_authenticatable/single_sign_out.rb +++ b/lib/devise_cas_authenticatable/single_sign_out.rb @@ -24,7 +24,7 @@ def session_store_class end def current_session_store - app = Rails.application.app + app = get_first_middleware_app begin app = app.instance_variable_get :@app end until app.nil? or app.class == session_store_class @@ -45,6 +45,20 @@ def destroy_session_by_id(sid) false end end + + private + + def get_first_middleware_app + # For case of running in production mode. + @first_middleware_app ||= if Rails.application.app.class == Rack::Cache::Context + Rails.application.app. + entitystore.instance_variable_get(:@store). + instance_variable_get(:@middleware).instance_variable_get(:@app) + else + Rails.application.app + end + + end end end From 526f3a33480c95f1b5bfdcd79e2243b8ea8d31df Mon Sep 17 00:00:00 2001 From: Denis Yagofarov Date: Wed, 23 May 2012 19:47:23 +0300 Subject: [PATCH 3/3] Fix for development environment --- lib/devise_cas_authenticatable/single_sign_out.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/devise_cas_authenticatable/single_sign_out.rb b/lib/devise_cas_authenticatable/single_sign_out.rb index 54f27e0..5da1d9b 100644 --- a/lib/devise_cas_authenticatable/single_sign_out.rb +++ b/lib/devise_cas_authenticatable/single_sign_out.rb @@ -50,7 +50,7 @@ def destroy_session_by_id(sid) def get_first_middleware_app # For case of running in production mode. - @first_middleware_app ||= if Rails.application.app.class == Rack::Cache::Context + @first_middleware_app ||= if defined?(Rack::Cache::Context) && Rails.application.app.class == Rack::Cache::Context Rails.application.app. entitystore.instance_variable_get(:@store). instance_variable_get(:@middleware).instance_variable_get(:@app)