This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
redmine_cas/lib/redmine_cas/application_controller_patc...

47 lines
1.6 KiB
Ruby

require 'redmine_cas'
module RedmineCAS
module ApplicationControllerPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :verify_authenticity_token, :cas
alias_method_chain :require_login, :cas
end
end
module InstanceMethods
def require_login_with_cas
return require_login_without_cas unless RedmineCAS.enabled?
if !User.current.logged?
referrer = request.fullpath;
respond_to do |format|
# pass referer to cas action, to work around this problem:
# https://github.com/ninech/redmine_cas/pull/13#issuecomment-53697288
format.html { redirect_to :controller => 'account', :action => 'cas', :ref => referrer }
format.atom { redirect_to :controller => 'account', :action => 'cas', :ref => referrer }
format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
end
return false
end
true
end
def verify_authenticity_token_with_cas
if cas_logout_request?
logger.info 'CAS logout request detected: Skipping validation of authenticity token'
else
verify_authenticity_token_without_cas
end
end
def cas_logout_request?
request.post? && params.has_key?('logoutRequest')
end
end
end
end