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)
-
- (Object) failure_message
readonly
Returns the value of attribute failure_message.
-
- (Object) service_redirect_url
readonly
Returns the value of attribute service_redirect_url.
-
- (Object) tgt
readonly
Returns the value of attribute tgt.
-
- (Object) ticket
readonly
Returns the value of attribute ticket.
Instance Method Summary (collapse)
-
- (LoginResponse) initialize(http_response = nil, options = {})
constructor
A new instance of LoginResponse.
- - (Boolean) is_failure?
- - (Boolean) is_success?
- - (Object) parse_http_response(http_response)
Constructor Details
- (LoginResponse) initialize(http_response = nil, options = {})
A new instance of LoginResponse
175 176 177 |
# File 'lib/casclient/responses.rb', line 175 def initialize(http_response = nil, ={}) parse_http_response(http_response) if http_response end |
Instance Attribute Details
- (Object) failure_message (readonly)
Returns the value of attribute failure_message
173 174 175 |
# File 'lib/casclient/responses.rb', line 173 def @failure_message end |
- (Object) service_redirect_url (readonly)
Returns the value of attribute service_redirect_url
172 173 174 |
# File 'lib/casclient/responses.rb', line 172 def service_redirect_url @service_redirect_url end |
- (Object) tgt (readonly)
Returns the value of attribute tgt
172 173 174 |
# File 'lib/casclient/responses.rb', line 172 def tgt @tgt end |
- (Object) ticket (readonly)
Returns the value of attribute ticket
172 173 174 |
# File 'lib/casclient/responses.rb', line 172 def ticket @ticket end |
Instance Method Details
- (Boolean) is_failure?
220 221 222 |
# File 'lib/casclient/responses.rb', line 220 def is_failure? @failure == true end |
- (Boolean) is_success?
216 217 218 |
# File 'lib/casclient/responses.rb', line 216 def is_success? !@failure && !ticket.blank? end |
- (Object) parse_http_response(http_response)
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/casclient/responses.rb', line 179 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 # 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). 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 |