class SamlIdp::IncomingMetadata

Attributes

raw[RW]

Public Class Methods

new(raw = "") click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 11
def initialize(raw = "")
  self.raw = raw
end

Public Instance Methods

assertion_consumer_services() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 86
def assertion_consumer_services
  xpath(
    "//md:SPSSODescriptor/md:AssertionConsumerService",
    md: metadata_namespace
  ).sort_by { |el| el["index"].to_i }.reduce([]) do |array, el|
    props = el["Binding"].to_s.match /urn:oasis:names:tc:SAML:(?<version>\S+):bindings:(?<name>\S+)/
    array << { binding: props[:name], location: el["Location"], default: !!el["isDefault"] }
    array
  end
end
company() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 106
def company
  contact_person_document.xpath("//md:Company", md: metadata_namespace).first.try(:content).to_s
end
contact_person() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 34
def contact_person
  {
    given_name: given_name,
    surname: surname,
    company: company,
    telephone_number: telephone_number,
    email_address: email_address
  }
end
contact_person_document() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 130
def contact_person_document
  @contact_person_document ||= xpath("//md:ContactPerson", md: metadata_namespace).first
end
display_name() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 29
def display_name
  role_descriptor_document.present? ? role_descriptor_document["ServiceDisplayName"] : ""
end
document() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 15
def document
  @document ||= Saml::XML::Document.parse raw
end
email_address() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 114
def email_address
  contact_person_document.xpath("//md:EmailAddress", md: metadata_namespace).first.try(:content).to_s.gsub("mailto:", "")
end
encryption_certificate() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 54
def encryption_certificate
  xpath(
    "//md:SPSSODescriptor/md:KeyDescriptor[@use='encryption']/ds:KeyInfo/ds:X509Data/ds:X509Certificate",
    ds: signature_namespace,
    md: metadata_namespace
  ).first.try(:content).to_s
end
given_name() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 98
def given_name
  contact_person_document.xpath("//md:GivenName", md: metadata_namespace).first.try(:content).to_s
end
idp_descriptor_document() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 126
def idp_descriptor_document
  @idp_descriptor ||= xpath("//md:IDPSSODescriptor", md: metadata_namespace).first
end
name_id_formats() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 74
def name_id_formats
  xpath(
    "//md:SPSSODescriptor/md:NameIDFormat",
    md: metadata_namespace
  ).reduce(Set.new) do |set, el|
    props = el.content.to_s.match /urn:oasis:names:tc:SAML:(?<version>\S+):nameid-format:(?<name>\S+)/
    set << props[:name].to_s.underscore if props[:name].present?
    set
  end
end
role_descriptor_document() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 118
def role_descriptor_document
  @role_descriptor ||= xpath("//md:RoleDescriptor", md: metadata_namespace).first
end
service_provider_descriptor_document() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 122
def service_provider_descriptor_document
  @service_provider_descriptor ||= xpath("//md:SPSSODescriptor", md: metadata_namespace).first
end
sign_assertions() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 19
def sign_assertions
  doc = xpath(
    "//md:SPSSODescriptor",
    ds: signature_namespace,
    md: metadata_namespace
  ).first
  doc ? !!doc["WantAssertionsSigned"] : false
end
signing_certificate() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 45
def signing_certificate
  xpath(
    "//md:SPSSODescriptor/md:KeyDescriptor[@use='signing']/ds:KeyInfo/ds:X509Data/ds:X509Certificate",
    ds: signature_namespace,
    md: metadata_namespace
  ).first.try(:content).to_s
end
single_logout_services() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 63
def single_logout_services
  xpath(
    "//md:SPSSODescriptor/md:SingleLogoutService",
    md: metadata_namespace
  ).reduce({}) do |hash, el|
    hash[el["Binding"].to_s.split(":").last] = el["Location"]
    hash
  end
end
surname() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 102
def surname
  contact_person_document.xpath("//md:SurName", md: metadata_namespace).first.try(:content).to_s
end
telephone_number() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 110
def telephone_number
  contact_person_document.xpath("//md:TelephoneNumber", md: metadata_namespace).first.try(:content).to_s
end

Private Instance Methods

metadata_namespace() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 134
def metadata_namespace
  Saml::XML::Namespaces::METADATA
end
signature_namespace() click to toggle source
# File lib/saml_idp/incoming_metadata.rb, line 139
def signature_namespace
  Saml::XML::Namespaces::SIGNATURE
end