Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,18 @@ In the config directory, create a YAML file (`attribute-map.yml`) that maps SAML
```yaml
# attribute-map.yml

"urn:mace:dir:attribute-def:uid": "user_name"
"urn:mace:dir:attribute-def:email": "email"
"urn:mace:dir:attribute-def:name": "last_name"
"urn:mace:dir:attribute-def:givenName": "name"
"urn:mace:dir:attribute-def:email":
"resource_key": "email"
"attribute_type": "single"
"urn:mace:dir:attribute-def:name":
"resource_key": "last_name"
"attribute_type": "single"
"urn:mace:dir:attribute-def:name":
"resource_key": "first_name"
"attribute_type": "single"
"urn:mace:dir:attribute-def:roles":
"resource_key": "roles"
"attribute_type": "multi"
```

The attribute mappings are very dependent on the way the IdP encodes the attributes.
Expand Down
12 changes: 6 additions & 6 deletions lib/devise_saml_authenticatable/saml_mapped_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ def saml_attribute_keys
end

def resource_keys
@attribute_map.values
@attribute_map.values.map { |h| h["resource_key"] }
end

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 }
attribute_map_for_key = @attribute_map.select { |_, config| String(config["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)
attribute_map_for_key.each_pair do |saml_key, config|
saml_value = value_by_saml_attribute_key(saml_key, config)

break unless saml_value.nil?
end

saml_value
end

def value_by_saml_attribute_key(key)
@attributes[String(key)]
def value_by_saml_attribute_key(key, config)
@attributes.send(config["attribute_type"], String(key))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer something a little more explicit:

Suggested change
@attributes.send(config["attribute_type"], String(key))
case config["attribute_type"]
when "single"
@attributes.single(String(key))
when "multi"
@attributes.multi(String(key))
end

end
end
end