lib/onelogin/ruby-saml/metadata.rb
def add_sp_service_elements(sp_sso, root, settings)
        if settings.single_logout_service_url
          sp_sso.add_element "md:SingleLogoutService", {
              "Binding" => settings.single_logout_service_binding,
              "Location" => settings.single_logout_service_url,
              "ResponseLocation" => settings.single_logout_service_url
          }
        end

        if settings.name_identifier_format
          nameid = sp_sso.add_element "md:NameIDFormat"
          nameid.text = settings.name_identifier_format
        end

        if settings.assertion_consumer_service_url
          sp_sso.add_element "md:AssertionConsumerService", {
              "Binding" => settings.assertion_consumer_service_binding,
              "Location" => settings.assertion_consumer_service_url,
              "isDefault" => true,
              "index" => 0
          }
        end

        if settings.organization_name || settings.organization_display_name || settings.organization_url
          sp_org = root.add_element "md:Organization"

          if settings.organization_name
            org_name = sp_org.add_element "md:OrganizationName", {
              "xml:lang" => "en"
            }
            org_name.text = settings.organization_name
          end

          if settings.organization_display_name
            org_name = sp_org.add_element "md:OrganizationDisplayName", {
              "xml:lang" => "en"
            }
            org_name.text = settings.organization_display_name
          end

          if settings.organization_url
            org_name = sp_org.add_element "md:OrganizationURL", {
              "xml:lang" => "en"
            }
            org_name.text = settings.organization_url
          end
        end

        if settings.contact_person.configured?
          settings.contact_person.contacts.each do |contact|
            sp_contact = root.add_element "md:ContactPerson", {
              "contactType" => contact[:contact_type] || 'other'
            }

            if contact[:given_name]
              sp_given_name = sp_contact.add_element "md:GivenName"
              sp_given_name.text = contact[:given_name]
            end

            sp_email = sp_contact.add_element "md:EmailAddress"
            sp_email.text = contact[:email]
          end
        end

        if settings.attribute_consuming_service.configured?
          sp_acs = sp_sso.add_element "md:AttributeConsumingService", {
            "isDefault" => "true",
            "index" => settings.attribute_consuming_service.index
          }
          srv_name = sp_acs.add_element "md:ServiceName", {
            "xml:lang" => "en"
          }
          srv_name.text = settings.attribute_consuming_service.name
          settings.attribute_consuming_service.attributes.each do |attribute|
            sp_req_attr = sp_acs.add_element "md:RequestedAttribute", {
              "NameFormat" => attribute[:name_format],
              "Name" => attribute[:name],
              "FriendlyName" => attribute[:friendly_name],
              "isRequired" => attribute[:is_required] || false
            }
            unless attribute[:attribute_value].nil?
              Array(attribute[:attribute_value]).each do |value|
                sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
                sp_attr_val.text = value.to_s
              end
            end
          end
        end

        # With OpenSSO, it might be required to also include
        #  <md:RoleDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:query="urn:oasis:names:tc:SAML:metadata:ext:query" xsi:type="query:AttributeQueryDescriptorType" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/>
        #  <md:XACMLAuthzDecisionQueryDescriptor WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/>

        sp_sso
      end
# Return SP metadata based on the settings.
# @param settings [OneLogin::RubySaml::Settings|nil] Toolkit settings
# @param pretty_print [Boolean] Pretty print or not the response
#                               (No pretty print if you gonna validate the signature)
# @param valid_until [DateTime] Metadata's valid time
# @param cache_duration [Integer] Duration of the cache in seconds
# @return [String] XML Metadata of the Service Provider
#
Return SP metadata based on the settings.
Return SP metadata based on the settings .
def add_sp_service_elements(sp_sso, root, settings)
        if settings.single_logout_service_url
          sp_sso.add_element "md:SingleLogoutService", {
              "Binding" => settings.single_logout_service_binding,
              "Location" => settings.single_logout_service_url,
              "ResponseLocation" => settings.single_logout_service_url
          }
        end
        if settings.name_identifier_format
          nameid = sp_sso.add_element "md:NameIDFormat"
          nameid.text = settings.name_identifier_format
        end
        if settings.assertion_consumer_service_url
          sp_sso.add_element "md:AssertionConsumerService", {
              "Binding" => settings.assertion_consumer_service_binding,
              "Location" => settings.assertion_consumer_service_url,
              "isDefault" => true,
              "index" => 0
          }
        end
        if settings.organization_name || settings.organization_display_name || settings.organization_url
          sp_org = root.add_element "md:Organization"
          if settings.organization_name
            org_name = sp_org.add_element "md:OrganizationName", {
              "xml:lang" => "en"
            }
            org_name.text = settings.organization_name
          end
          if settings.organization_display_name
            org_name = sp_org.add_element "md:OrganizationDisplayName", {
              "xml:lang" => "en"
            }
            org_name.text = settings.organization_display_name
          end
          if settings.organization_url
            org_name = sp_org.add_element "md:OrganizationURL", {
              "xml:lang" => "en"
            }
            org_name.text = settings.organization_url
          end
        end
        if settings.contact_person.configured?
          settings.contact_person.contacts.each do |contact|
            sp_contact = root.add_element "md:ContactPerson", {
              "contactType" => contact[:contact_type] || 'other'
            }
            if contact[:given_name]
              sp_given_name = sp_contact.add_element "md:GivenName"
              sp_given_name.text = contact[:given_name]
            end
            sp_email = sp_contact.add_element "md:EmailAddress"
            sp_email.text = contact[:email]
          end
        end
        if settings.attribute_consuming_service.configured?
          sp_acs = sp_sso.add_element "md:AttributeConsumingService", {
            "isDefault" => "true",
            "index" => settings.attribute_consuming_service.index
          }
          srv_name = sp_acs.add_element "md:ServiceName", {
            "xml:lang" => "en"
          }
          srv_name.text = settings.attribute_consuming_service.name
          settings.attribute_consuming_service.attributes.each do |attribute|
            sp_req_attr = sp_acs.add_element "md:RequestedAttribute", {
              "NameFormat" => attribute[:name_format],
              "Name" => attribute[:name],
              "FriendlyName" => attribute[:friendly_name],
              "isRequired" => attribute[:is_required] || false
            }
            unless attribute[:attribute_value].nil?
              Array(attribute[:attribute_value]).each do |value|
                sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
                sp_attr_val.text = value.to_s
              end
            end
          end
        end
        sp_sso
      end
def add_sp_service_elements ( sp_sso , root , settings ) if settings . single_logout_service_url sp_sso . add_element "md:SingleLogoutService" , { "Binding" => settings . single_logout_service_binding , "Location" => settings . single_logout_service_url , "ResponseLocation" => settings . single_logout_service_url } end if settings . name_identifier_format nameid = sp_sso . add_element "md:NameIDFormat" nameid . text = settings . name_identifier_format end if settings . assertion_consumer_service_url sp_sso . add_element "md:AssertionConsumerService" , { "Binding" => settings . assertion_consumer_service_binding , "Location" => settings . assertion_consumer_service_url , "isDefault" => true , "index" => 0 } end if settings . organization_name || settings . organization_display_name || settings . organization_url sp_org = root . add_element "md:Organization" if settings . organization_name org_name = sp_org . add_element "md:OrganizationName" , { "xml:lang" => "en" } org_name . text = settings . organization_name end if settings . organization_display_name org_name = sp_org . add_element "md:OrganizationDisplayName" , { "xml:lang" => "en" } org_name . text = settings . organization_display_name end if settings . organization_url org_name = sp_org . add_element "md:OrganizationURL" , { "xml:lang" => "en" } org_name . text = settings . organization_url end end if settings . contact_person . configured? settings . contact_person . contacts . each do | contact | sp_contact = root . add_element "md:ContactPerson" , { "contactType" => contact [ :contact_type ] || 'other' } if contact [ :given_name ] sp_given_name = sp_contact . add_element "md:GivenName" sp_given_name . text = contact [ :given_name ] end sp_email = sp_contact . add_element "md:EmailAddress" sp_email . text = contact [ :email ] end end if settings . attribute_consuming_service . configured? sp_acs = sp_sso . add_element "md:AttributeConsumingService" , { "isDefault" => "true" , "index" => settings . attribute_consuming_service . index } srv_name = sp_acs . add_element "md:ServiceName" , { "xml:lang" => "en" } srv_name . text = settings . attribute_consuming_service . name settings . attribute_consuming_service . attributes . each do | attribute | sp_req_attr = sp_acs . add_element "md:RequestedAttribute" , { "NameFormat" => attribute [ :name_format ] , "Name" => attribute [ :name ] , "FriendlyName" => attribute [ :friendly_name ] , "isRequired" => attribute [ :is_required ] || false } unless attribute [ :attribute_value ] . nil? Array ( attribute [ :attribute_value ] ) . each do | value | sp_attr_val = sp_req_attr . add_element "saml:AttributeValue" sp_attr_val . text = value . to_s end end end end sp_sso end
Return SP metadata based on the settings.
Return SP metadata based on the settings .
# With OpenSSO, it might be required to also include #  <md:RoleDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:query="urn:oasis:names:tc:SAML:metadata:ext:query" xsi:type="query:AttributeQueryDescriptorType" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/> #  <md:XACMLAuthzDecisionQueryDescriptor WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/>
XML Metadata of the Service Provider
XML Metadata of the Service Provider
String
sp_sso
root
settings
None
pretty_print
Pretty print or not the response (No pretty print if you gonna validate the signature)
Pretty print or not the response ( No pretty print if you gonna validate the signature )
valid_until
Metadata's valid time
Metadata ' s valid time
cache_duration
Duration of the cache in seconds
Duration of the cache in seconds