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.



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

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

Instance Attribute Details

#entity_idObject



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

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



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

def build(builder)
  builder['md'].EntityDescriptor('entityID' => entity_id,
                                 'xmlns:md' => Namespaces::,
                                 '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



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

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

#identity_providersObject



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

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

#rolesObject



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

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

#service_providersObject



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

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

#valid_schema?Boolean

Returns:

  • (Boolean)


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

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

#valid_untilObject



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

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