Class: SAML2::Response

Inherits:
Base
  • Object
show all
Defined in:
lib/saml2/response.rb

Defined Under Namespace

Modules: Status

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_xml, #from_xml, load_object_array, load_string_array, lookup_qname, #to_s, #to_xml

Constructor Details

#initializeResponse

Returns a new instance of Response.



61
62
63
64
65
66
# File 'lib/saml2/response.rb', line 61

def initialize
  @id = "_#{SecureRandom.uuid}"
  @status_code = Status::SUCCESS
  @issue_instant = Time.now.utc
  @assertions = []
end

Instance Attribute Details

#assertionsObject (readonly)

Returns the value of attribute assertions.



16
17
18
# File 'lib/saml2/response.rb', line 16

def assertions
  @assertions
end

#destinationObject

Returns the value of attribute destination.



17
18
19
# File 'lib/saml2/response.rb', line 17

def destination
  @destination
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/saml2/response.rb', line 16

def id
  @id
end

#in_response_toObject

Returns the value of attribute in_response_to.



17
18
19
# File 'lib/saml2/response.rb', line 17

def in_response_to
  @in_response_to
end

#issue_instantObject (readonly)

Returns the value of attribute issue_instant.



16
17
18
# File 'lib/saml2/response.rb', line 16

def issue_instant
  @issue_instant
end

#issuerObject

Returns the value of attribute issuer.



17
18
19
# File 'lib/saml2/response.rb', line 17

def issuer
  @issuer
end

#status_codeObject

Returns the value of attribute status_code.



17
18
19
# File 'lib/saml2/response.rb', line 17

def status_code
  @status_code
end

Class Method Details

.initiate(service_provider, issuer, name_id, attributes = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/saml2/response.rb', line 35

def self.initiate(service_provider, issuer, name_id, attributes = nil)
  response = new
  response.issuer = issuer
  response.destination = service_provider.assertion_consumer_services.default.location if service_provider
  assertion = Assertion.new
  assertion.subject = Subject.new
  assertion.subject.name_id = name_id
  assertion.subject.confirmation = Subject::Confirmation.new
  assertion.subject.confirmation.method = Subject::Confirmation::Methods::BEARER
  assertion.subject.confirmation.not_on_or_after = Time.now.utc + 30
  assertion.subject.confirmation.recipient = response.destination if response.destination
  assertion.issuer = issuer
  assertion.conditions.not_before = Time.now.utc - 5
  assertion.conditions.not_on_or_after = Time.now.utc + 30
  authn_statement = AuthnStatement.new
  authn_statement.authn_instant = response.issue_instant
  authn_statement.authn_context_class_ref = AuthnStatement::Classes::UNSPECIFIED
  assertion.statements << authn_statement
  if attributes && service_provider.attribute_consuming_services.default
    statement = service_provider.attribute_consuming_services.default.create_statement(attributes)
    assertion.statements << statement if statement
  end
  response.assertions << assertion
  response
end

.respond_to(authn_request, issuer, name_id, attributes = nil) ⇒ Object



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

def self.respond_to(authn_request, issuer, name_id, attributes = nil)
  response = initiate(nil, issuer, name_id)
  response.in_response_to = authn_request.id
  response.destination = authn_request.assertion_consumer_service.location
  confirmation = response.assertions.first.subject.confirmation
  confirmation.in_response_to = authn_request.id
  confirmation.recipient = response.destination
  if attributes && authn_request.attribute_consuming_service
    statement = authn_request.attribute_consuming_service.create_statement(attributes)
    response.assertions.first.statements << statement if statement
  end
  response.assertions.first.conditions << Conditions::AudienceRestriction.new(authn_request.issuer.id)

  response
end

Instance Method Details

#sign(*args) ⇒ Object



68
69
70
# File 'lib/saml2/response.rb', line 68

def sign(*args)
  assertions.each { |assertion| assertion.sign(*args) }
end