Skip to content

Commit

Permalink
Merge pull request rubycas#75 from codeanu/master
Browse files Browse the repository at this point in the history
single sign out requests should now work for https services
  • Loading branch information
zuk committed Feb 3, 2012
2 parents 7567354 + 221d968 commit 8ca290f
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/casserver/cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,26 @@ def send_logout_notification_for_service_ticket(st)
uri.path = '/' if uri.path.empty?
time = Time.now
rand = CASServer::Utils.random_string

path = uri.path
req = Net::HTTP::Post.new(path)
req.set_form_data('logoutRequest' => %{<samlp:LogoutRequest ID="#{rand}" Version="2.0" IssueInstant="#{time.rfc2822}">
<saml:NameID></saml:NameID>
<samlp:SessionIndex>#{st.ticket}</samlp:SessionIndex>
</samlp:LogoutRequest>})

begin
response = Net::HTTP.post_form(uri, {'logoutRequest' => URI.escape(%{<samlp:LogoutRequest ID="#{rand}" Version="2.0" IssueInstant="#{time.rfc2822}">
<saml:NameID></saml:NameID>
<samlp:SessionIndex>#{st.ticket}</samlp:SessionIndex>
</samlp:LogoutRequest>})})
if response.kind_of? Net::HTTPSuccess
$LOG.info "Logout notification successfully posted to #{st.service.inspect}."
return true
else
$LOG.error "Service #{st.service.inspect} responed to logout notification with code '#{response.code}'!"
return false
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme =='https'

http.start do |conn|
response = conn.request(req)
if response.kind_of? Net::HTTPSuccess
$LOG.info "Logout notification successfully posted to #{st.service.inspect}."
return true
else
$LOG.error "Service #{st.service.inspect} responed to logout notification with code '#{response.code}'!"
return false
end
end
rescue Exception => e
$LOG.error "Failed to send logout notification to service #{st.service.inspect} due to #{e}"
Expand Down

0 comments on commit 8ca290f

Please sign in to comment.