Class: Onelogin::Saml::Logoutrequest

Inherits:
Object
  • Object
show all
Defined in:
lib/onelogin/ruby-saml-bm/logoutrequest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogoutrequest

Returns a new instance of Logoutrequest.



13
14
15
# File 'lib/onelogin/ruby-saml-bm/logoutrequest.rb', line 13

def initialize
  @uuid = "_" + UUID.new.generate
end

Instance Attribute Details

#uuidObject (readonly)

Can be obtained if neccessary



11
12
13
# File 'lib/onelogin/ruby-saml-bm/logoutrequest.rb', line 11

def uuid
  @uuid
end

Instance Method Details

#create(settings, params = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/onelogin/ruby-saml-bm/logoutrequest.rb', line 17

def create(settings, params={})
  request_doc = create_unauth_xml_doc(settings, params)
  request = ""
  request_doc.write(request)

  deflated_request  = Zlib::Deflate.deflate(request, 9)[2..-5]
  base64_request    = Base64.encode64(deflated_request)
  encoded_request   = CGI.escape(base64_request)

  params_prefix     = (settings.idp_slo_target_url =~ /\?/) ? '&' : '?'
  request_params    = "#{params_prefix}SAMLRequest=#{encoded_request}"

  params.each_pair do |key, value|
    request_params << "&#{key}=#{CGI.escape(value.to_s)}"
  end

  @logout_url = settings.idp_slo_target_url + request_params
end

#create_unauth_xml_doc(settings, params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/onelogin/ruby-saml-bm/logoutrequest.rb', line 36

def create_unauth_xml_doc(settings, params)

  time = Time.new().strftime("%Y-%m-%dT%H:%M:%SZ")

  request_doc = REXML::Document.new
  root = request_doc.add_element "samlp:LogoutRequest", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol" }
  root.attributes['ID'] = @uuid
  root.attributes['IssueInstant'] = time
  root.attributes['Version'] = "2.0"

  if settings.issuer
    issuer = root.add_element "saml:Issuer", { "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" }
    issuer.text = settings.issuer
  end

  if settings.name_identifier_value
    name_id = root.add_element "saml:NameID", { "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion" }
    name_id.attributes['NameQualifier'] = settings.sp_name_qualifier if settings.sp_name_qualifier
    name_id.attributes['Format'] = settings.name_identifier_format if settings.name_identifier_format
    name_id.text = settings.name_identifier_value
  end

  if settings.sessionindex
    sessionindex = root.add_element "samlp:SessionIndex", { "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol" }
    sessionindex.text = settings.sessionindex
  end

  # BUG fix here -- if an authn_context is defined, add the tags with an "exact"
  # match required for authentication to succeed.  If this is not defined,
  # the IdP will choose default rules for authentication.  (Shibboleth IdP)
  if settings.authn_context != nil
    requested_context = root.add_element "samlp:RequestedAuthnContext", {
        "xmlns:samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
        "Comparison" => "exact",
    }
    class_ref = requested_context.add_element "saml:AuthnContextClassRef", {
        "xmlns:saml" => "urn:oasis:names:tc:SAML:2.0:assertion",
    }
    class_ref.text = settings.authn_context
  end
  request_doc
end