Module: Kraut::Rails::Authentication
- Defined in:
- lib/kraut/rails/authentication.rb
Constant Summary collapse
- CROWD_SESSION_TIMEOUT_MINUTES =
The timeout for a Crowd session in minutes.
25
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_to?(action) ⇒ Boolean
- #authenticate_application ⇒ Object
- #check_for_crowd_token ⇒ Object
- #logged_in? ⇒ Boolean
- #store_current_location ⇒ Object
- #stored_location! ⇒ Object
- #switch_user(user) ⇒ Object
- #user ⇒ Object
- #verify_access ⇒ Object
- #verify_login ⇒ Object
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/kraut/rails/authentication.rb', line 7 def self.included(base) base.helper_method :user, :logged_in?, :allowed_to? base.rescue_from SecurityError do |e| reset_session redirect_to new_kraut_sessions_path, :alert => I18n.t("errors.kraut.session_expired") end end |
Instance Method Details
#allowed_to?(action) ⇒ Boolean
30 31 32 33 |
# File 'lib/kraut/rails/authentication.rb', line 30 def allowed_to?(action) authenticate_application !!user && user.allowed_to?(action) end |
#authenticate_application ⇒ Object
62 63 64 65 66 |
# File 'lib/kraut/rails/authentication.rb', line 62 def authenticate_application if Kraut::Application.authentication_required? CROWD_SESSION_TIMEOUT_MINUTES Kraut::Application.authenticate Kraut::Rails::Engine.config.webservice[:user], Kraut::Rails::Engine.config.webservice[:password] end end |
#check_for_crowd_token ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kraut/rails/authentication.rb', line 35 def check_for_crowd_token if params[:crowd_token] begin authenticate_application switch_user(Session.find_by_token(params[:crowd_token])) rescue Kraut::InvalidPrincipalToken reset_session redirect_to new_kraut_sessions_path, :alert => I18n.t("errors.kraut.token_not_found") end end end |
#logged_in? ⇒ Boolean
26 27 28 |
# File 'lib/kraut/rails/authentication.rb', line 26 def logged_in? !user.nil? end |
#store_current_location ⇒ Object
68 69 70 |
# File 'lib/kraut/rails/authentication.rb', line 68 def store_current_location session[:stored_location] = request.fullpath if request.get? end |
#stored_location! ⇒ Object
72 73 74 |
# File 'lib/kraut/rails/authentication.rb', line 72 def stored_location! session.delete(:stored_location) end |
#switch_user(user) ⇒ Object
18 19 20 |
# File 'lib/kraut/rails/authentication.rb', line 18 def switch_user(user) session[:user] = user end |
#user ⇒ Object
22 23 24 |
# File 'lib/kraut/rails/authentication.rb', line 22 def user session[:user] end |
#verify_access ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/kraut/rails/authentication.rb', line 54 def verify_access authenticate_application unless logged_in? && user.allowed_to?("#{params[:controller]}_#{params[:action]}") store_current_location redirect_to new_kraut_sessions_path, :alert => I18n.t("errors.kraut.access_denied") end end |
#verify_login ⇒ Object
47 48 49 50 51 52 |
# File 'lib/kraut/rails/authentication.rb', line 47 def verify_login unless logged_in? store_current_location redirect_to new_kraut_sessions_path end end |