Sha256: 435041bbc3088e8447e37857f4ffbebfe6c4f950abc564ae54131decd9f30007

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

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(/<cas:authenticationSuccess>/).captures.length > 0
      end

      def all_attributes(extra_attributes)
        {}.merge!(get_user(@response)).merge!(get_extra_attributes(@response, extra_attributes))
      end

      protected

      def xml_namespace
        "cas"
      end

      def get_user(res)
        match = res.match(/<#{xml_namespace}:user>(.*)<\/#{xml_namespace}:user>/)
        if match
          { user: match.captures.first }
        else # Failed login
          {}
        end
      end

      def get_extra_attributes(res, extra_attributes)
        attributes = {}
        extra_attributes.each do |ea|
          match = res.match(/<#{xml_namespace}:#{ea}>(.*)<\/#{xml_namespace}:#{ea}>/)
          if match
            attributes[ea] = match.captures.first
          end
        end
        attributes
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cas-client-0.1.3 lib/cas/client/response.rb