Module: DeviseCasAuthenticatable::SingleSignOut::DestroySession

Includes:
WithConn
Included in:
Devise::CasSessionsController, Strategies::RedisCache
Defined in:
lib/devise_cas_authenticatable/single_sign_out.rb

Overview

Supports destroying sessions by ID for ActiveRecord and Redis session stores

Instance Method Summary collapse

Methods included from WithConn

#with_conn

Instance Method Details

#current_session_storeObject


53
54
55
# File 'lib/devise_cas_authenticatable/single_sign_out.rb', line 53

def current_session_store
  session_store_identifier.current_session_store
end

#destroy_session_by_id(sid) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/devise_cas_authenticatable/single_sign_out.rb', line 14

def destroy_session_by_id(sid)
  logger.debug "Single Sign Out from session store: #{current_session_store.class}"

  if session_store_class.name =~ /ActiveRecord::SessionStore/
    session = session_store_class::Session.find_by_session_id(sid)
    session.destroy if session
    true
  elsif session_store_class.name =~ /ActionDispatch::Session::ActiveRecordStore/
    session = current_session_store.session_class.find_by_session_id(sid)
    session.destroy if session
    true
  elsif session_store_class.name =~ /ActionDispatch::Session::DalliStore/
    current_session_store.send(:destroy_session, env, sid, drop: true)
    true
  elsif session_store_class.name =~ /RedisSessionStore/
    current_session_store.send(:destroy_session, env, sid, drop: true)
    true
  elsif session_store_class.name =~ /Redis/
    with_conn { |conn| conn.del(sid) }
    true
  elsif session_store_class.name =~ /CacheStore/
    if current_session_store.respond_to?(:delete_session)  # Rails 5 and up
      current_session_store.delete_session({}, sid, {})
    else
      current_session_store.destroy_session({}, sid, {})
    end

    true
  else
    logger.error "Cannot process logout request because this Rails application's session store is "+
          " #{session_store_class.name} and is not a support session store type for Single Sign-Out."
    false
  end
end

#session_store_classObject


57
58
59
# File 'lib/devise_cas_authenticatable/single_sign_out.rb', line 57

def session_store_class
  session_store_identifier.session_store_class
end

#session_store_identifierObject


49
50
51
# File 'lib/devise_cas_authenticatable/single_sign_out.rb', line 49

def session_store_identifier
  @session_store_identifier ||= DeviseCasAuthenticatable::SessionStoreIdentifier.new
end