class RackCAS::ServiceValidationResponse
Constants
- REQUEST_HEADERS
Public Class Methods
new(url)
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 10 def initialize(url) @url = URL.parse(url) end
Public Instance Methods
extra_attributes()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 31 def extra_attributes attrs = {} raise AuthenticationFailure, failure_message unless success? # Jasig style if attr_node = xml.at('//serviceResponse/authenticationSuccess/attributes') attrs = parse_user_info(attr_node) # RubyCas-Server style else xml.at('//serviceResponse/authenticationSuccess').children.each do |node| if node.is_a? Nokogiri::XML::Element if !node.namespace || !node.namespace.prefix == 'cas' # TODO: support JSON encoding attrs[node.name] = YAML.load node.text.strip end end end end attrs end
user()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 14 def user if success? xml.at('//serviceResponse/authenticationSuccess/user').text else case failure_code when 'INVALID_REQUEST' raise RequestInvalidError, failure_message when 'INVALID_TICKET' raise TicketInvalidError, failure_message when 'INVALID_SERVICE' raise ServiceInvalidError, failure_message else raise AuthenticationFailure, failure_message end end end
Protected Instance Methods
authentication_failure()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 61 def authentication_failure @authentication_failure ||= xml.at('//serviceResponse/authenticationFailure') end
failure_code()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 71 def failure_code if authentication_failure authentication_failure['code'] end end
failure_message()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 65 def failure_message if authentication_failure authentication_failure.text.strip end end
parse_user_info(node)
click to toggle source
initially borrowed from omniauth-cas
# File lib/rack-cas/service_validation_response.rb, line 101 def parse_user_info(node) return nil if node.nil? {}.tap do |hash| node.children.each do |e| unless e.kind_of?(Nokogiri::XML::Text) || e.name == 'proxies' # There are no child elements if e.element_children.count == 0 if hash.has_key?(e.name) hash[e.name] = [hash[e.name]] if hash[e.name].is_a? String hash[e.name] << e.content else hash[e.name] = e.content end elsif e.element_children.count # JASIG style extra attributes if e.name == 'attributes' hash.merge!(parse_user_info(e)) else hash[e.name] = [] if hash[e.name].nil? hash[e.name] = [hash[e.name]] if hash[e.name].is_a? String hash[e.name].push(parse_user_info(e)) end end end end end end
response()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 77 def response require 'net/http' return @response unless @response.nil? http = Net::HTTP.new(@url.host, @url.inferred_port) if @url.scheme == 'https' http.use_ssl = true http.verify_mode = RackCAS.config.verify_ssl_cert ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE end http.start do |conn| @response = conn.get(@url.request_uri, REQUEST_HEADERS) end @response end
success?()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 57 def success? @success ||= !!xml.at('//serviceResponse/authenticationSuccess') end
xml()
click to toggle source
# File lib/rack-cas/service_validation_response.rb, line 94 def xml return @xml unless @xml.nil? @xml = Nokogiri::XML(response.body).remove_namespaces! end