Class: Onelogin::Saml::Metadata

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

Instance Method Summary collapse

Instance Method Details

#generate(settings) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/onelogin/ruby-saml-bm/metadata.rb', line 13

def generate(settings)
  meta_doc = REXML::Document.new
  root = meta_doc.add_element "md:EntityDescriptor", { 
      "xmlns:md" => "urn:oasis:names:tc:SAML:2.0:metadata" 
  }
  sp_sso = root.add_element "md:SPSSODescriptor", { 
      "protocolSupportEnumeration" => "urn:oasis:names:tc:SAML:2.0:protocol"
  }
  if settings.issuer != nil
    root.attributes["entityID"] = settings.issuer
  end
  if settings.name_identifier_format != nil
    name_id = sp_sso.add_element "md:NameIDFormat"
    name_id.text = settings.name_identifier_format
  end
  if settings.assertion_consumer_service_url != nil
    sp_sso.add_element "md:AssertionConsumerService", {
        # Add this as a setting to create different bindings?
        "Binding" => "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
        "Location" => settings.assertion_consumer_service_url
    }
  end
  meta_doc << REXML::XMLDecl.new
  ret = ""
  # pretty print the XML so IdP administrators can easily see what the SP supports
  meta_doc.write(ret, 1)

  Logging.debug "Generated metadata:\n#{ret}"

  return ret

end