Sha256: 8424cd8c0b80f4acaf7b3b87e8934d78fbf84b57584683b3ef8f7a12de8a5ef8

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

require 'set'

require 'saml2/base'
require 'saml2/organization_and_contacts'
require 'saml2/key'

module SAML2
  class Role < Base
    module Protocols
      SAML2 = 'urn:oasis:names:tc:SAML:2.0:protocol'.freeze
    end

    include OrganizationAndContacts

    attr_writer :supported_protocols, :keys

    def initialize
      super
      @supported_protocols = Set.new
      @supported_protocols << Protocols::SAML2
      @keys = []
    end

    def from_xml(node)
      super
      @supported_protocols = nil
      @keys = nil
    end

    def supported_protocols
      @supported_protocols ||= xml['protocolSupportEnumeration'].split
    end

    def keys
      @keys ||= load_object_array(xml, 'md:KeyDescriptor', Key)
    end

    def signing_keys
      keys.select { |key| key.signing? }
    end

    def encryption_keys
      keys.select { |key| key.encryption? }
    end

    protected
    # should be called from inside the role element
    def build(builder)
      builder.parent['protocolSupportEnumeration'] = supported_protocols.to_a.join(' ')
      keys.each do |key|
        key.build(builder)
      end
      super
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
saml2-1.1.5 lib/saml2/role.rb
saml2-1.1.4 lib/saml2/role.rb
saml2-1.1.3 lib/saml2/role.rb
saml2-1.1.2 lib/saml2/role.rb
saml2-1.1.1 lib/saml2/role.rb
saml2-1.1.0 lib/saml2/role.rb