Module: Sinatra::CasHelper
- Defined in:
- lib/sinatra/helpers/cas.rb
Constant Summary collapse
- CAS_CLIENT =
CASClient::Client.new(:cas_base_url => ENV['CAS_BASE_URL'], :log => Logger.new(STDOUT), :ticket_store_config => {:storage_dir => ENV['TICKET_STORE_DIR']})
Instance Method Summary collapse
- #authenticated(model) ⇒ Object
- #logged_in?(request, session) ⇒ Boolean
- #need_authentication(request, session) ⇒ Object
- #process_cas_login(request, session) ⇒ Object
- #require_authorization(request, session) ⇒ Object
Instance Method Details
#authenticated(model) ⇒ Object
53 54 55 56 |
# File 'lib/sinatra/helpers/cas.rb', line 53 def authenticated(model) raise 500 if session[:cas_user].nil? || session[:cas_user].empty? model.find(:hxt_id => "#{session[:cas_user]}") end |
#logged_in?(request, session) ⇒ Boolean
41 42 43 |
# File 'lib/sinatra/helpers/cas.rb', line 41 def logged_in?(request, session) session[:cas_ticket] && !session[:cas_ticket].empty? end |
#need_authentication(request, session) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sinatra/helpers/cas.rb', line 10 def need_authentication(request, session) if session[:cas_ticket] if request[:ticket] && session[:cas_ticket] != request[:ticket] true else false end else true end end |
#process_cas_login(request, session) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sinatra/helpers/cas.rb', line 22 def process_cas_login(request, session) if request[:ticket] && request[:ticket] != session[:ticket] service_url = read_service_url(request) service_ticket = read_ticket(request[:ticket], service_url) CAS_CLIENT.validate_service_ticket(service_ticket) if service_ticket.success session[:cas_ticket] = service_ticket.ticket session[:cas_user] = service_ticket.user else redirect request.path_info #raise "Service Ticket validation failed! #{st.failure_code} - #{st.failure_message}" end end end |
#require_authorization(request, session) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/sinatra/helpers/cas.rb', line 45 def (request, session) if !logged_in?(request, session) service_url = read_service_url(request) url = CAS_CLIENT.add_service_to_login_url(service_url) redirect url end end |