Class: RSAML::Protocol::Response

Inherits:
Message
  • Object
show all
Defined in:
lib/rsaml/protocol/response.rb

Overview

A SAML response

Instance Attribute Summary collapse

Attributes inherited from Message

#consent, #destination, #id, #issue_instant, #issuer, #signature, #version

Instance Method Summary collapse

Methods inherited from Message

#extensions

Constructor Details

#initialize(status) ⇒ Response

Initialize the Response instance



16
17
18
19
# File 'lib/rsaml/protocol/response.rb', line 16

def initialize(status)
  super()
  @status = status
end

Instance Attribute Details

#in_response_toObject

A reference to the identifier of the request to which the response corresponds, if any. If the response is not generated in response to a request, or if the ID attribute value of a request cannot be determined (for example, the request is malformed), then this attribute MUST NOT be present. Otherwise, it MUST be present and its value MUST match the value of the corresponding request’s ID attribute.



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

def in_response_to
  @in_response_to
end

#statusObject

A code representing the status of the corresponding request.



13
14
15
# File 'lib/rsaml/protocol/response.rb', line 13

def status
  @status
end

Instance Method Details

#assertionsObject

SAML assertions



22
23
24
# File 'lib/rsaml/protocol/response.rb', line 22

def assertions
  @assertions ||= []
end

#encrypted_assertionsObject

SAML encrypted assertions



27
28
29
# File 'lib/rsaml/protocol/response.rb', line 27

def encrypted_assertions
  @encrypted_assertions ||= []
end

#to_xml(xml = Builder::XmlMarkup.new) ⇒ Object

Construct an XML fragment representing the request



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rsaml/protocol/response.rb', line 39

def to_xml(xml=Builder::XmlMarkup.new)
  attributes = {'ID' => id, 'Version' => version, 'IssueInstant' => issue_instant.xmlschema}
  attributes['InResponseTo'] = in_response_to unless in_response_to.nil?
  attributes['Destination'] = destination unless destination.nil?
  attributes['Consent'] = consent unless consent.nil?
  attributes = add_xmlns(attributes)
  xml.tag!('samlp:Response', attributes) {
    xml << issuer.to_xml unless issuer.nil?
    xml << signature.to_xml unless signature.nil?
    # TODO: add extensions support
    xml << status.to_xml unless status.nil?
    assertions.each { |assertion| xml << assertion.to_xml }
    encrypted_assertions.each { |encrypted_assertion| xml << encrypted_assertion.to_xml }
  }
end

#validateObject

Validate the request structure

Raises:



32
33
34
35
36
# File 'lib/rsaml/protocol/response.rb', line 32

def validate
  super
  raise ValidationError, "Status must be specified" if status.nil?
  raise ValidationError, "Status must be a RSAML::Protocol::Status instance" unless status.is_a?(Status)
end