Class: RackCAS::ServiceValidationResponse

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

Defined Under Namespace

Classes: AuthenticationFailure, RequestInvalidError, ServiceInvalidError, TicketInvalidError

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ ServiceValidationResponse

Returns a new instance of ServiceValidationResponse.



10
11
12
# File 'lib/rack-cas/service_validation_response.rb', line 10

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

Instance Method Details

#extra_attributesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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 = (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

#userObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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