Class: RackCAS::ServiceValidationResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-cas/service_validation_response.rb

Defined Under Namespace

Classes: AuthenticationFailure

Constant Summary collapse

REQUEST_HEADERS =
{ 'Accept' => '*/*' }

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ ServiceValidationResponse

Returns a new instance of ServiceValidationResponse.



7
8
9
# File 'lib/rack-cas/service_validation_response.rb', line 7

def initialize(url)
  @url = URL.parse(url)
end

Instance Method Details

#extra_attributesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rack-cas/service_validation_response.rb', line 19

def extra_attributes
  attrs = {}

  raise AuthenticationFailure, failure_message unless success?

  # Jasig style
  if attr_node = xml.at('/cas:serviceResponse/cas:authenticationSuccess/cas:attributes')
    attr_node.children.each do |node|
      if node.is_a? Nokogiri::XML::Element
        attrs[node.name] = node.text
      end
    end

  # RubyCas-Server style
  else
    xml.at('/cas:serviceResponse/cas: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

#userObject



11
12
13
14
15
16
17
# File 'lib/rack-cas/service_validation_response.rb', line 11

def user
  if success?
    xml.xpath('/cas:serviceResponse/cas:authenticationSuccess/cas:user').text
  else
    raise AuthenticationFailure, failure_message
  end
end