Class: SamlAuthenticatable::SamlMappedAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_saml_authenticatable/saml_mapped_attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes, attribute_map) ⇒ SamlMappedAttributes

Returns a new instance of SamlMappedAttributes.



3
4
5
6
# File 'lib/devise_saml_authenticatable/saml_mapped_attributes.rb', line 3

def initialize(attributes, attribute_map)
  @attributes = attributes
  @attribute_map = attribute_map
end

Instance Method Details

#resource_keysObject



12
13
14
# File 'lib/devise_saml_authenticatable/saml_mapped_attributes.rb', line 12

def resource_keys
  @attribute_map.values
end

#saml_attribute_keysObject



8
9
10
# File 'lib/devise_saml_authenticatable/saml_mapped_attributes.rb', line 8

def saml_attribute_keys
  @attribute_map.keys
end

#value_by_resource_key(key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/devise_saml_authenticatable/saml_mapped_attributes.rb', line 16

def value_by_resource_key(key)
  str_key = String(key)

  # Find all of the SAML attributes that map to the resource key
  attribute_map_for_key = @attribute_map.select { |_, resource_key| String(resource_key) == str_key }

  saml_value = nil

  # Find the first non-nil value
  attribute_map_for_key.each_key do |saml_key|
    saml_value = value_by_saml_attribute_key(saml_key)

    break unless saml_value.nil?
  end

  saml_value
end

#value_by_saml_attribute_key(key) ⇒ Object



34
35
36
# File 'lib/devise_saml_authenticatable/saml_mapped_attributes.rb', line 34

def value_by_saml_attribute_key(key)
  @attributes[String(key)]
end