module Cas module Client class Response def initialize(uri) @request_uri = uri @response = nil end def validate_service_response @response = Net::HTTP.get(@request_uri) end def success? @response.to_s.match(/<#{xml_namespace}:authenticationSuccess>/) end def all_attributes get_user.merge!(get_extra_attributes) end protected def xml_namespace Cas::Client.configuration.cas_namespace end def get_user match = @response.match(/<#{xml_namespace}:user>(.*)<\/#{xml_namespace}:user>/) if match { user: match.captures.first } else # Failed login {} end end def get_extra_attributes {}.tap do |attributes| Cas::Client.configuration.extra_attributes.each do |ea| match = @response.match(/<#{xml_namespace}:#{ea}>(.*)<\/#{xml_namespace}:#{ea}>/) if match attributes[ea] = match.captures.first else attributes end end end end end end end