Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,40 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery | ||
|
||
# before_filter :require_login, :except => [:not_authenticated] | ||
helper_method :current_users_list | ||
|
||
def render_validation_error(code, message = nil) | ||
xml = Nokogiri::XML::Builder.new do |xml| | ||
xml.serviceResponse("xmlns:cas" => "http://www.yale.edu/tp/cas") { | ||
xml.parent.namespace = xml.parent.namespace_definitions.first | ||
xml['cas'].authenticationFailure(message, :code => code.to_s.upcase){ | ||
} | ||
} | ||
end | ||
render :xml => xml.to_xml | ||
end | ||
|
||
def render_validation_success(username) | ||
xml = Nokogiri::XML::Builder.new do |xml| | ||
xml.serviceResponse("xmlns:cas" => "http://www.yale.edu/tp/cas") { | ||
xml.parent.namespace = xml.parent.namespace_definitions.first | ||
xml['cas'].authenticationSuccess { | ||
xml['cas'].user username | ||
# append_user_info(username, xml) | ||
} | ||
} | ||
end | ||
render :xml => xml.to_xml | ||
end | ||
|
||
def get_url_host url | ||
URI::parse(CGI.unescape(url.to_s)).host | ||
url = URI::parse(CGI.unescape(url.to_s)) | ||
"#{url.host}:#{url.port}" | ||
end | ||
|
||
def has_service_info? | ||
cookies[:service].present? and cookies[:service_back_url].present? | ||
end | ||
|
||
protected | ||
def current_tgt | ||
# unconsumed is meaningless, since it will be deleted after logout | ||
TicketGrantingTicket.where(:ticket => cookies.signed[:tgt]).first | ||
end | ||
|
||
def has_valid_tgt | ||
TicketGrantingTicket.where(:ticket => cookies[:tgt]).first # unconsumed is meaningless, since it will be deleted after logout | ||
def not_authenticated | ||
redirect_to root_path, :alert => "Please login first." | ||
end | ||
|
||
# issue a Service Ticket and redirect back | ||
def issue_service_ticket | ||
if tgt = has_valid_tgt and has_service_info? | ||
# Issue a Service Ticket and return a url with this st | ||
def back_url_with_service_ticket | ||
if tgt = current_tgt and has_service_info? | ||
st = ServiceTicket.create( | ||
:service => cookies[:service], | ||
:username => current_user.id, | ||
:granted_by_tgt_id => tgt.id | ||
) | ||
|
||
service_back_url = cookies[:service_back_url] | ||
service_back_url = cookies[:service_back_url] + "?ticket=#{st.ticket}" | ||
|
||
# remove service info | ||
cookies.delete :service | ||
cookies.delete :service_back_url | ||
|
||
return service_back_url + "?ticket=#{st.ticket}" | ||
service_back_url | ||
end | ||
end | ||
|
||
def not_authenticated | ||
redirect_to root_path, :alert => "Please login first." | ||
end | ||
|
||
def current_users_list | ||
current_users.map {|u| u.email}.join(", ") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters