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, lookup_qname, #to_s, #to_xml

Constructor Details

#initializeEntity

Returns a new instance of Entity.



77
78
79
80
81
82
# File 'lib/saml2/entity.rb', line 77

def initialize
  super
  @valid_until = nil
  @entity_id = nil
  @roles = []
end

Instance Attribute Details

#entity_idObject



95
96
97
# File 'lib/saml2/entity.rb', line 95

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

Class Method Details

.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



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/saml2/entity.rb', line 119

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

#from_xml(node) ⇒ Object



84
85
86
87
88
89
# File 'lib/saml2/entity.rb', line 84

def from_xml(node)
  @root = node
  remove_instance_variable(:@valid_until)
  @roles = nil
  super
end

#identity_providersObject



106
107
108
# File 'lib/saml2/entity.rb', line 106

def identity_providers
  roles.select { |r| r.is_a?(IdentityProvider) }
end

#rolesObject



114
115
116
117
# File 'lib/saml2/entity.rb', line 114

def roles
  @roles ||= load_object_array(@root, 'md:IDPSSODescriptor', IdentityProvider) +
      load_object_array(@root, 'md:SPSSODescriptor', ServiceProvider)
end

#service_providersObject



110
111
112
# File 'lib/saml2/entity.rb', line 110

def service_providers
  roles.select { |r| r.is_a?(ServiceProvider) }
end

#valid_schema?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/saml2/entity.rb', line 91

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

#valid_untilObject



99
100
101
102
103
104
# File 'lib/saml2/entity.rb', line 99

def valid_until
  unless instance_variable_defined?(:@valid_until)
    @valid_until = @root['validUntil'] && Time.parse(@root['validUntil'])
  end
  @valid_until
end