# 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|
          @extra_attributes[k] = YAML.load(v)
        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