class SAML2::Entity

Attributes

entity_id[W]

@return [String]

Public Class Methods

new(entity_id = nil) click to toggle source

@param id [String] The Entity ID

Calls superclass method SAML2::OrganizationAndContacts::new
# File lib/saml2/entity.rb, line 88
def initialize(entity_id = nil)
  super()
  @valid_until = nil
  @entity_id = entity_id
  @roles = []
  @id = "_#{SecureRandom.uuid}"
end
parse(xml) click to toggle source

Parse a metadata file, and return an appropriate object.

@param xml [String, IO] Anything that can be passed to Nokogiri::XML @return [Entity, Group, nil]

# File lib/saml2/entity.rb, line 23
def self.parse(xml)
  document = Nokogiri::XML(xml)

  # Root can be an array (EntitiesDescriptor), or a single Entity (EntityDescriptor)
  entities = document.at_xpath("/md:EntitiesDescriptor", Namespaces::ALL)
  entity = document.at_xpath("/md:EntityDescriptor", Namespaces::ALL)
  if entities
    Group.from_xml(entities)
  elsif entity
    from_xml(entity)
  else
    nil
  end
end

Public Instance Methods

build(builder) click to toggle source

(see Base#build)

Calls superclass method SAML2::OrganizationAndContacts#build
# File lib/saml2/entity.rb, line 142
def build(builder)
  builder["md"].EntityDescriptor("entityID" => entity_id,
                                 "xmlns:md" => Namespaces::METADATA,
                                 "xmlns:dsig" => Namespaces::DSIG,
                                 "xmlns:xenc" => Namespaces::XENC) do |entity_descriptor|
    entity_descriptor.parent["ID"] = id if id

    roles.each do |role|
      role.build(entity_descriptor)
    end

    super
  end
end
entity_id() click to toggle source

@return [String]

# File lib/saml2/entity.rb, line 110
def entity_id
  @entity_id || (xml && xml["entityID"])
end
from_xml(node) click to toggle source

(see Base#from_xml)

Calls superclass method SAML2::OrganizationAndContacts#from_xml
# File lib/saml2/entity.rb, line 97
def from_xml(node)
  super
  @id = nil
  remove_instance_variable(:@valid_until)
  @roles = nil
end
id() click to toggle source

(see Message#id)

# File lib/saml2/entity.rb, line 115
def id
  @id ||= xml["ID"]
end
identity_providers() click to toggle source

@return [Array<IdentityProvider>]

# File lib/saml2/entity.rb, line 126
def identity_providers
  roles.select { |r| r.is_a?(IdentityProvider) }
end
initiate_authn_request(identity_provider) click to toggle source

Generates an AuthnRequest @param identity_provider [Entity] The metadata of the IdP to send the message to.

# File lib/saml2/entity.rb, line 159
def initiate_authn_request(identity_provider)
  AuthnRequest.initiate(SAML2::NameID.new(entity_id),
                        identity_provider.identity_providers.first,
                        service_provider: service_providers.first)
end
roles() click to toggle source

@return [Array<Role>]

# File lib/saml2/entity.rb, line 136
def roles
  @roles ||= load_object_array(xml, "md:IDPSSODescriptor", IdentityProvider) +
             load_object_array(xml, "md:SPSSODescriptor", ServiceProvider)
end
service_providers() click to toggle source

@return [Array<ServiceProvider>]

# File lib/saml2/entity.rb, line 131
def service_providers
  roles.select { |r| r.is_a?(ServiceProvider) }
end
valid_response?(message, identity_provider, **opts) click to toggle source

Validate a message is a valid response.

@param message [Message] @param identity_provider [Entity]

# File lib/saml2/entity.rb, line 169
def valid_response?(message,
                    identity_provider,
                    **opts)
  unless message.is_a?(Response)
    message.errors << "not a Response object"
    return false
  end

  message.validate(service_provider: self,
                   identity_provider: identity_provider,
                   **opts).empty?
end
valid_schema?() click to toggle source

(see Message#valid_schema?)

# File lib/saml2/entity.rb, line 105
def valid_schema?
  Schemas.metadata.valid?(xml.document)
end
valid_until() click to toggle source

@return [Time, nil]

# File lib/saml2/entity.rb, line 120
def valid_until
  @valid_until = xml["validUntil"] && Time.parse(xml["validUntil"]) unless instance_variable_defined?(:@valid_until)
  @valid_until
end