class SAML2::Attribute::X500

Constants

FRIENDLY_NAMES

build hashes out of our known attribute names for quick lookup

GIVEN_NAME
MAIL

www.ietf.org/rfc/rfc4524.txt

OIDS
SN
UID

www.ietf.org/rfc/rfc4519.txt

Public Class Methods

new(name = nil, value = nil) click to toggle source

Create a new X.500 attribute.

The name format will always be set to URI.

@param name [String]

Either an OID or a known friendly name. The opposite value will be
inferred automatically.

@param value optional [Object, nil]

Calls superclass method SAML2::Attribute::new
# File lib/saml2/attribute/x500.rb, line 55
def initialize(name = nil, value = nil)
  # if they pass an OID, infer the friendly name
  friendly_name = OIDS[name]
  unless friendly_name
    # if they pass a friendly name, infer the OID
    proper_name = FRIENDLY_NAMES[name]
    if proper_name
      friendly_name = name
      name = proper_name
    end
  end

  super(name, value, friendly_name, NameFormats::URI)
end
recognizes?(name_or_node) click to toggle source

Returns true if the param should be an {X500} Attribute. @param name_or_node [String, Nokogiri::XML::Element]

# File lib/saml2/attribute/x500.rb, line 37
def self.recognizes?(name_or_node)
  if name_or_node.is_a?(Nokogiri::XML::Element)
    !!name_or_node.at_xpath("@x500:Encoding", Namespaces::ALL) ||
      ((name_or_node["NameFormat"] == NameFormats::URI || name_or_node["NameFormat"].nil?) &&
        OIDS.include?(name_or_node["Name"]))
  else
    FRIENDLY_NAMES.include?(name_or_node) || OIDS.include?(name_or_node)
  end
end

Public Instance Methods

build(builder) click to toggle source

(see Base#build)

Calls superclass method SAML2::Attribute#build
# File lib/saml2/attribute/x500.rb, line 79
def build(builder)
  super
  attr = builder.parent.last_element_child
  attr.add_namespace_definition("x500", Namespaces::X500)
  attr["x500:Encoding"] = "LDAP"
end
from_xml(node) click to toggle source

(see Base.from_xml)

Calls superclass method SAML2::Attribute::from_xml
# File lib/saml2/attribute/x500.rb, line 71
def from_xml(node)
  super
  # infer the friendly name if not provided
  self.friendly_name ||= OIDS[name]
  self
end