Class: RackCAS::SAMLValidationResponse

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

Defined Under Namespace

Classes: AuthenticationFailure, TicketInvalidError

Constant Summary collapse

REQUEST_HEADERS =
{
  'Accept' => '*/*',
  'Content-Type' => 'application/soap+xml; charset=utf-8'
}

Instance Method Summary collapse

Constructor Details

#initialize(url, ticket) ⇒ SAMLValidationResponse


11
12
13
14
# File 'lib/rack-cas/saml_validation_response.rb', line 11

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

Instance Method Details

#extra_attributesObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rack-cas/saml_validation_response.rb', line 24

def extra_attributes
  attrs = {}

  raise AuthenticationFailure, failure_message unless success?

  xml.at('//Response/Assertion/AttributeStatement').children.each do |node|
    key = node.at('@AttributeName')

    if key
      values = node.xpath('AttributeValue').map { |n| n.text }

      values = values.first if values.size == 1

      attrs[key.text] = values
    end
  end

  attrs
end

#userObject


16
17
18
19
20
21
22
# File 'lib/rack-cas/saml_validation_response.rb', line 16

def user
  if success?
    xml.at('//Response/Assertion/AuthenticationStatement/Subject/NameIdentifier').text
  else
    raise AuthenticationFailure, failure_message
  end
end