Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a "from" parameter in the urls for redirection #232

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/casserver/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ def self.init_database!

# optional params
@service = clean_service_url(params['service'])
@from = clean_service_url(params['from'])
@return_url = if @from.blank?
@service
else
@service + @from
end
@renew = params['renew']
@gateway = params['gateway'] == 'true' || params['gateway'] == '1'

Expand Down Expand Up @@ -334,7 +340,7 @@ def self.init_database!
elsif tgt && !tgt_error
$LOG.debug("Valid ticket granting ticket detected.")
st = generate_service_ticket(@service, tgt.username, tgt)
service_with_ticket = service_uri_with_ticket(@service, st)
service_with_ticket = service_uri_with_ticket(@return_url, st)
$LOG.info("User '#{tgt.username}' authenticated based on ticket granting cookie. Redirecting to service '#{@service}'.")
redirect service_with_ticket, 303 # response code 303 means "See Other" (see Appendix B in CAS Protocol spec)
elsif @gateway
Expand Down Expand Up @@ -396,6 +402,12 @@ def self.init_database!

# 2.2.1 (optional)
@service = clean_service_url(params['service'])
@from = clean_service_url(params['from'])
@return_url = if @from.blank?
@service
else
@service + @from
end

# 2.2.2 (required)
@username = params['username']
Expand Down Expand Up @@ -470,7 +482,7 @@ def self.init_database!
@st = generate_service_ticket(@service, @username, tgt)

begin
service_with_ticket = service_uri_with_ticket(@service, @st)
service_with_ticket = service_uri_with_ticket(@return_url, @st)

$LOG.info("Redirecting authenticated user '#{@username}' at '#{@st.client_hostname}' to service '#{@service}'")
redirect service_with_ticket, 303 # response code 303 means "See Other" (see Appendix B in CAS Protocol spec)
Expand Down
1 change: 1 addition & 0 deletions lib/casserver/views/_login_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<td id="submit-container">
<input type="hidden" id="lt" name="lt" value="<%= escape_html @lt %>" />
<input type="hidden" id="service" name="service" value="<%= escape_html @service %>" />
<input type="hidden" id="from" name="from" value="<%= escape_html @from %>" />
<input type="submit" class="button" accesskey="l" value="<%= t.button.login %>"
tabindex="4" id="login-submit" />
</td>
Expand Down