Class: Spid::Saml2::LogoutRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/spid/saml2/logout_request.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid: nil, settings:, session_index:) ⇒ LogoutRequest

Returns a new instance of LogoutRequest.



11
12
13
14
15
16
17
# File 'lib/spid/saml2/logout_request.rb', line 11

def initialize(uuid: nil, settings:, session_index:)
  @settings = settings
  @document = REXML::Document.new
  @session_index = session_index
  @uuid = uuid
  @issue_instant = Time.now.utc.iso8601
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'lib/spid/saml2/logout_request.rb', line 7

def document
  @document
end

#issue_instantObject (readonly)

Returns the value of attribute issue_instant.



9
10
11
# File 'lib/spid/saml2/logout_request.rb', line 9

def issue_instant
  @issue_instant
end

#session_indexObject (readonly)

Returns the value of attribute session_index.



8
9
10
# File 'lib/spid/saml2/logout_request.rb', line 8

def session_index
  @session_index
end

#settingsObject (readonly)

Returns the value of attribute settings.



6
7
8
# File 'lib/spid/saml2/logout_request.rb', line 6

def settings
  @settings
end

Instance Method Details

#issuerObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/spid/saml2/logout_request.rb', line 47

def issuer
  @issuer ||=
    begin
      element = REXML::Element.new("saml:Issuer")
      element.add_attributes(
        "Format" => "urn:oasis:names:tc:SAML:2.0:nameid-format:entity",
        "NameQualifier" => settings.sp_entity_id
      )
      element.text = settings.sp_entity_id
      element
    end
end

#logout_requestObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spid/saml2/logout_request.rb', line 24

def logout_request
  @logout_request ||=
    begin
      element = REXML::Element.new("samlp:LogoutRequest")
      element.add_attributes(logout_request_attributes)
      element.add_element(issuer)
      element.add_element(name_id)
      element.add_element(samlp_session_index)
      element
    end
end

#logout_request_attributesObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/spid/saml2/logout_request.rb', line 36

def logout_request_attributes
  @logout_request_attributes ||= {
    "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
    "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion",
    "ID" => uuid,
    "Version" => "2.0",
    "IssueInstant" => issue_instant,
    "Destination" => settings.idp_slo_target_url
  }
end

#name_idObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/spid/saml2/logout_request.rb', line 60

def name_id
  @name_id ||=
    begin
      element = REXML::Element.new("saml:NameID")
      element.add_attributes(
        "Format" => "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
        "NameQualifier" => settings.idp_entity_id
      )
      element.text = "a-name-identifier-value"
      element
    end
end

#samlp_session_indexObject



73
74
75
76
77
78
79
80
# File 'lib/spid/saml2/logout_request.rb', line 73

def samlp_session_index
  @samlp_session_index ||=
    begin
      element = REXML::Element.new("samlp:SessionIndex")
      element.text = session_index
      element
    end
end

#to_samlObject



19
20
21
22
# File 'lib/spid/saml2/logout_request.rb', line 19

def to_saml
  document.add_element(logout_request)
  document.to_s
end

#uuidObject



82
83
84
# File 'lib/spid/saml2/logout_request.rb', line 82

def uuid
  @uuid ||= "_#{SecureRandom.uuid}"
end