Class: Saml::Kit::Builders::Response

Inherits:
Object
  • Object
show all
Includes:
XmlTemplatable
Defined in:
lib/saml/kit/builders/response.rb

Overview

Constant Summary

Constants included from XmlTemplatable

XmlTemplatable::TEMPLATES_DIR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XmlTemplatable

#digest_method, #sign?, #signature_method, #signing_key_pair, #template_name, #template_path

Constructor Details

#initialize(user, request = nil, configuration: Saml::Kit.configuration) ⇒ Response

Returns a new instance of Response.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/saml/kit/builders/response.rb', line 13

def initialize(
  user, request = nil, configuration: Saml::Kit.configuration
)
  @user = user
  @request = request
  @id = ::Xml::Kit::Id.generate
  @now = Time.now.utc
  @version = '2.0'
  @status_code = Namespaces::SUCCESS
  @status_message = nil
  @issuer = configuration.entity_id
  @encryption_certificate = request.try(:provider)
    .try(:encryption_certificates).try(:last)
  @encrypt = encryption_certificate.present?
  @configuration = configuration
end

Instance Attribute Details

#configuration ⇒ Object (readonly)

Returns the value of attribute configuration.



10
11
12
# File 'lib/saml/kit/builders/response.rb', line 10

def configuration
  @configuration
end

#destination ⇒ Object

Returns the value of attribute destination.



10
11
12
# File 'lib/saml/kit/builders/response.rb', line 10

def destination
  @destination
end

#id ⇒ Object

Returns the value of attribute id.



11
12
13
# File 'lib/saml/kit/builders/response.rb', line 11

def id
  @id
end

#issuer ⇒ Object

Returns the value of attribute issuer.



10
11
12
# File 'lib/saml/kit/builders/response.rb', line 10

def issuer
  @issuer
end

#now ⇒ Object

Returns the value of attribute now.



10
11
12
# File 'lib/saml/kit/builders/response.rb', line 10

def now
  @now
end

#request ⇒ Object (readonly)

Returns the value of attribute request.



10
11
12
# File 'lib/saml/kit/builders/response.rb', line 10

def request
  @request
end

#status_code ⇒ Object

Returns the value of attribute status_code.



11
12
13
# File 'lib/saml/kit/builders/response.rb', line 11

def status_code
  @status_code
end

#status_message ⇒ Object

Returns the value of attribute status_message.



11
12
13
# File 'lib/saml/kit/builders/response.rb', line 11

def status_message
  @status_message
end

#user ⇒ Object (readonly)

Returns the value of attribute user.



10
11
12
# File 'lib/saml/kit/builders/response.rb', line 10

def user
  @user
end

#version ⇒ Object

Returns the value of attribute version.



11
12
13
# File 'lib/saml/kit/builders/response.rb', line 11

def version
  @version
end

Instance Method Details

#assertion ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/saml/kit/builders/response.rb', line 42

def assertion
  @assertion ||=
    begin
      assertion = Assertion.new(user, request, configuration: configuration)
      assertion.sign_with(@signing_key_pair) if @signing_key_pair
      assertion.embed_signature = embed_signature unless embed_signature.nil?
      assertion.now = now
      assertion.destination = destination
      assertion.issuer = issuer
      encrypt ? EncryptedAssertion.new(self, assertion) : assertion
    end
end

#assertion=(value) ⇒ Object



38
39
40
# File 'lib/saml/kit/builders/response.rb', line 38

def assertion=(value)
  @assertion = value || Null.new
end

#build ⇒ Object



30
31
32
33
34
35
36
# File 'lib/saml/kit/builders/response.rb', line 30

def build
  Saml::Kit::Response.new(
    to_xml,
    request_id: request.try(:id),
    configuration: configuration
  )
end

#embed_signature=(value) ⇒ Object



81
82
83
84
# File 'lib/saml/kit/builders/response.rb', line 81

def embed_signature=(value)
  @embed_signature = value
  assertion.embed_signature = value
end

#encrypt=(value) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/saml/kit/builders/response.rb', line 55

def encrypt=(value)
  super(value)
  return if @assertion.nil?

  if value
    @assertion = EncryptedAssertion.new(self, assertion) if assertion.is_a?(Assertion)
  elsif assertion.is_a?(EncryptedAssertion)
    @assertion = assertion.assertion if assertion.is_a?(EncryptedAssertion)
  end
end