Class: CASClient::ValidationResponse
- Inherits:
-
Object
- Object
- CASClient::ValidationResponse
- Includes:
- XmlResponse
- Defined in:
- lib/casclient/responses.rb
Overview
Represents a response from the CAS server to a ‘validate’ request (i.e. after validating a service/proxy ticket).
Instance Attribute Summary collapse
-
#extra_attributes ⇒ Object
readonly
Returns the value of attribute extra_attributes.
-
#pgt_iou ⇒ Object
readonly
Returns the value of attribute pgt_iou.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Attributes included from XmlResponse
#failure_code, #failure_message, #parse_datetime, #xml
Instance Method Summary collapse
-
#initialize(raw_text) ⇒ ValidationResponse
constructor
A new instance of ValidationResponse.
- #is_failure? ⇒ Boolean
- #is_success? ⇒ Boolean
- #parse(raw_text) ⇒ Object
Methods included from XmlResponse
Constructor Details
#initialize(raw_text) ⇒ ValidationResponse
Returns a new instance of ValidationResponse.
34 35 36 |
# File 'lib/casclient/responses.rb', line 34 def initialize(raw_text) parse(raw_text) end |
Instance Attribute Details
#extra_attributes ⇒ Object (readonly)
Returns the value of attribute extra_attributes.
32 33 34 |
# File 'lib/casclient/responses.rb', line 32 def extra_attributes @extra_attributes end |
#pgt_iou ⇒ Object (readonly)
Returns the value of attribute pgt_iou.
32 33 34 |
# File 'lib/casclient/responses.rb', line 32 def pgt_iou @pgt_iou end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
32 33 34 |
# File 'lib/casclient/responses.rb', line 32 def protocol @protocol end |
#proxies ⇒ Object (readonly)
Returns the value of attribute proxies.
32 33 34 |
# File 'lib/casclient/responses.rb', line 32 def proxies @proxies end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
32 33 34 |
# File 'lib/casclient/responses.rb', line 32 def user @user end |
Instance Method Details
#is_failure? ⇒ Boolean
94 95 96 |
# File 'lib/casclient/responses.rb', line 94 def is_failure? @valid == false || (protocol > 1.0 && xml.name == "authenticationFailure" ) end |
#is_success? ⇒ Boolean
90 91 92 |
# File 'lib/casclient/responses.rb', line 90 def is_success? @valid == true || (protocol > 1.0 && xml.name == "authenticationSuccess") end |
#parse(raw_text) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/casclient/responses.rb', line 38 def parse(raw_text) raise BadResponseException, "CAS response is empty/blank." if raw_text.blank? @parse_datetime = Time.now if raw_text =~ /^(yes|no)\n(.*?)\n$/m @protocol = 1.0 @valid = $~[1] == 'yes' @user = $~[2] return end @xml = check_and_parse_xml(raw_text) # if we got this far then we've got a valid XML response, so we're doing CAS 2.0 @protocol = 2.0 if is_success? @user = @xml.elements["cas:user"].text.strip if @xml.elements["cas:user"] @pgt_iou = @xml.elements["cas:proxyGrantingTicket"].text.strip if @xml.elements["cas:proxyGrantingTicket"] proxy_els = @xml.elements.to_a('//cas:authenticationSuccess/cas:proxies/cas:proxy') if proxy_els.size > 0 @proxies = [] proxy_els.each do |el| @proxies << el.text end end @extra_attributes = {} @xml.elements.to_a('//cas:authenticationSuccess/*').each do |el| @extra_attributes.merge!(Hash.from_xml(el.to_s)) unless el.prefix == 'cas' end # unserialize extra attributes @extra_attributes.each do |k, v| if v.blank? @extra_attributes[k] = nil else @extra_attributes[k] = YAML.load(v) end end elsif is_failure? @failure_code = @xml.elements['//cas:authenticationFailure'].attributes['code'] @failure_message = @xml.elements['//cas:authenticationFailure'].text.strip else # this should never happen, since the response should already have been recognized as invalid raise BadResponseException, "BAD CAS RESPONSE:\n#{raw_text.inspect}\n\nXML DOC:\n#{doc.inspect}" end end |