From 1308deba94c2531e0a3e8d9e4b58ed380601e316 Mon Sep 17 00:00:00 2001 From: Brad Seefeld Date: Thu, 23 Aug 2012 10:02:29 -0700 Subject: [PATCH 1/2] #42: HTTPSeeOther is the only valid response that should be returned from the server on successful login --- lib/casclient/responses.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/casclient/responses.rb b/lib/casclient/responses.rb index 099e00e5..a5667272 100644 --- a/lib/casclient/responses.rb +++ b/lib/casclient/responses.rb @@ -191,7 +191,7 @@ def parse_http_response(http_response) @ticket = $~[1] end - if not ((http_response.kind_of?(Net::HTTPSuccess) || http_response.kind_of?(Net::HTTPFound)) && @ticket.present?) + unless http_response.kind_of?(Net::HTTPSeeOther) && @ticket.present? @failure = true # Try to extract the error message -- this only works with RubyCAS-Server. # For other servers we just return the entire response body (i.e. the whole error page). From b7de9ece870f189e56193a0333374e5776d8f2da Mon Sep 17 00:00:00 2001 From: Brad Seefeld Date: Fri, 7 Sep 2012 09:31:48 -0700 Subject: [PATCH 2/2] #42: Support legacy checks --- lib/casclient/responses.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/casclient/responses.rb b/lib/casclient/responses.rb index a5667272..f4044b76 100644 --- a/lib/casclient/responses.rb +++ b/lib/casclient/responses.rb @@ -190,8 +190,15 @@ def parse_http_response(http_response) if location =~ /ticket=([^&]+)/ @ticket = $~[1] end - - unless http_response.kind_of?(Net::HTTPSeeOther) && @ticket.present? + + # Legacy check. CAS Server used to return a 200 (Success) or a 302 (Found) on successful authentication. + # This behavior should be deprecated at some point in the future. + legacy_valid_ticket = (http_response.kind_of?(Net::HTTPSuccess) || http_response.kind_of?(Net::HTTPFound)) && @ticket.present? + + # If using rubycas-server 1.1.0+ + valid_ticket = http_response.kind_of?(Net::HTTPSeeOther) && @ticket.present? + + if !legacy_valid_ticket && !valid_ticket @failure = true # Try to extract the error message -- this only works with RubyCAS-Server. # For other servers we just return the entire response body (i.e. the whole error page).