Class: CASClient::LoginResponse
- Inherits:
-
Object
- Object
- CASClient::LoginResponse
- Defined in:
- lib/casclient/responses.rb
Overview
Represents a response from the CAS server to a login request (i.e. after submitting a username/password).
Instance Attribute Summary collapse
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
-
#service_redirect_url ⇒ Object
readonly
Returns the value of attribute service_redirect_url.
-
#tgt ⇒ Object
readonly
Returns the value of attribute tgt.
-
#ticket ⇒ Object
readonly
Returns the value of attribute ticket.
Instance Method Summary collapse
-
#initialize(http_response = nil) ⇒ LoginResponse
constructor
A new instance of LoginResponse.
- #is_failure? ⇒ Boolean
- #is_success? ⇒ Boolean
- #parse_http_response(http_response) ⇒ Object
Constructor Details
#initialize(http_response = nil) ⇒ LoginResponse
Returns a new instance of LoginResponse.
144 145 146 |
# File 'lib/casclient/responses.rb', line 144 def initialize(http_response = nil) parse_http_response(http_response) if http_response end |
Instance Attribute Details
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
142 143 144 |
# File 'lib/casclient/responses.rb', line 142 def @failure_message end |
#service_redirect_url ⇒ Object (readonly)
Returns the value of attribute service_redirect_url.
141 142 143 |
# File 'lib/casclient/responses.rb', line 141 def service_redirect_url @service_redirect_url end |
#tgt ⇒ Object (readonly)
Returns the value of attribute tgt.
141 142 143 |
# File 'lib/casclient/responses.rb', line 141 def tgt @tgt end |
#ticket ⇒ Object (readonly)
Returns the value of attribute ticket.
141 142 143 |
# File 'lib/casclient/responses.rb', line 141 def ticket @ticket end |
Instance Method Details
#is_failure? ⇒ Boolean
182 183 184 |
# File 'lib/casclient/responses.rb', line 182 def is_failure? @failure == true end |
#is_success? ⇒ Boolean
178 179 180 |
# File 'lib/casclient/responses.rb', line 178 def is_success? !@failure && !ticket.blank? end |
#parse_http_response(http_response) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/casclient/responses.rb', line 148 def parse_http_response(http_response) header = http_response.to_hash # FIXME: this regexp might be incorrect... if header['set-cookie'] && header['set-cookie'].first && header['set-cookie'].first =~ /tgt=([^&]+);/ @tgt = $~[1] end location = header['location'].first if header['location'] && header['location'].first if location =~ /ticket=([^&]+)/ @ticket = $~[1] end if !http_response.kind_of?(Net::HTTPSuccess) || ticket.blank? @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). body = http_response.body if body =~ /<div class="messagebox mistake">(.*?)<\/div>/m @failure_message = $~[1].strip else @failure_message = body end end @service_redirect_url = location end |