Class: SAML2::Attribute::X500

Inherits:
SAML2::Attribute show all
Defined in:
lib/saml2/attribute/x500.rb

Defined Under Namespace

Modules: EduPerson, InetOrgPerson

Constant Summary collapse

GIVEN_NAME =
"urn:oid:2.5.4.42"
SN =
SURNAME           = "urn:oid:2.5.4.4"
UID =
USERID           = "urn:oid:0.9.2342.19200300.100.1.1"
MAIL =
"urn:oid:0.9.2342.19200300.100.1.3"

Instance Attribute Summary

Attributes inherited from SAML2::Attribute

#friendly_name, #name, #name_format, #value

Attributes inherited from Base

#xml

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SAML2::Attribute

create, element, from_xml, namespace

Methods inherited from Base

#decrypt, from_xml, #inspect, load_object_array, load_string_array, lookup_qname, #to_s, #to_xml

Constructor Details

#initialize(name = nil, value = nil) ⇒ X500

Create a new X.500 attribute.

The name format will always be set to URI.

Parameters:

  • name (String) (defaults to: nil)

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

  • value (defaults to: nil)

    optional [Object, nil]



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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

Class Method Details

.recognizes?(name_or_node) ⇒ Boolean

Returns true if the param should be an SAML2::Attribute::X500 Attribute.

Parameters:

  • name_or_node (String, Nokogiri::XML::Element)

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# 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

Instance Method Details

#build(builder) ⇒ void

This method returns an undefined value.

Serialize this object to XML, as part of a larger document

Parameters:

  • builder (Nokogiri::XML::Builder)

    The builder helper object to serialize to.



79
80
81
82
83
84
# 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) ⇒ Base?

Create an appropriate object to represent the given XML element.

Parameters:

  • node (Nokogiri::XML::Element, nil)

Returns:



71
72
73
74
75
76
# 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