Class: SAML2::Entity

Inherits:
Base
  • Object
show all
Includes:
OrganizationAndContacts
Defined in:
lib/saml2/entity.rb

Defined Under Namespace

Classes: Group

Instance Attribute Summary collapse

Attributes included from OrganizationAndContacts

#contacts, #organization

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#from_xml, load_object_array, load_string_array, #to_s, #to_xml

Constructor Details

#initialize(root = nil) ⇒ Entity

Returns a new instance of Entity.



50
51
52
53
54
55
56
# File 'lib/saml2/entity.rb', line 50

def initialize(root = nil)
  super
  @root = root
  unless @root
    @roles = []
  end
end

Instance Attribute Details

#entity_idObject



62
63
64
# File 'lib/saml2/entity.rb', line 62

def entity_id
  @entity_id || @root && @root['entityID']
end

Class Method Details

.from_xml(node) ⇒ Object



46
47
48
# File 'lib/saml2/entity.rb', line 46

def self.from_xml(node)
  node && new(node)
end

.parse(xml) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/saml2/entity.rb', line 14

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

Instance Method Details

#build(builder) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/saml2/entity.rb', line 71

def build(builder)
  builder['md'].EntityDescriptor('entityID' => entity_id,
                                 'xmlns:md' => Namespaces::METADATA,
                                 'xmlns:dsig' => Namespaces::DSIG,
                                 'xmlns:xenc' => Namespaces::XENC) do |builder|
    roles.each do |role|
      role.build(builder)
    end

    super
  end
end

#rolesObject



66
67
68
69
# File 'lib/saml2/entity.rb', line 66

def roles
  # TODO: load IdPSSODescriptors as well
  @roles ||= load_object_array(@root, 'md:SPSSODescriptor', ServiceProvider)
end

#valid_schema?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/saml2/entity.rb', line 58

def valid_schema?
  Schemas..valid?(@root.document)
end