Class: Samlr::Response

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/samlr/response.rb

Overview

This is the object interface to the XML response object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options) ⇒ Response

Returns a new instance of Response.



12
13
14
15
# File 'lib/samlr/response.rb', line 12

def initialize(data, options)
  @options = options
  @document = Response.parse(data)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



10
11
12
# File 'lib/samlr/response.rb', line 10

def document
  @document
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/samlr/response.rb', line 10

def options
  @options
end

Class Method Details

.parse(data) ⇒ Object



47
48
49
# File 'lib/samlr/response.rb', line 47

def self.parse(data)
  Samlr::Tools.parse(data)
end

Instance Method Details

#assertionObject

Returns the assertion element. Only supports a single assertion.



43
44
45
# File 'lib/samlr/response.rb', line 43

def assertion
  @assertion ||= Samlr::Assertion.new(document, options)
end

#locationObject



34
35
36
# File 'lib/samlr/response.rb', line 34

def location
  "/samlp:Response"
end

#signatureObject



38
39
40
# File 'lib/samlr/response.rb', line 38

def signature
  @signature ||= Samlr::Signature.new(document, location, options)
end

#verify!Object

The verification process assumes that all signatures are enveloped. Since this process is destructive the document needs to verify itself first, and then any signed assertions



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/samlr/response.rb', line 19

def verify!
  if signature.missing? && assertion.signature.missing?
    raise Samlr::SignatureError.new("Neither response nor assertion signed with a certificate")
  end

  if document.xpath("//samlp:Response", Samlr::NS_MAP).size > 1
    raise Samlr::FormatError.new("multiple responses")
  end

  signature.verify! unless signature.missing?
  assertion.verify!

  true
end