Skip to content

Commit

Permalink
More robust handling of EntityAttribute values
Browse files Browse the repository at this point in the history
When set manually in SimpleSAMLphp's config, a single-valued
EntityAttribute can be set as a scalar rather than an array.
However, when the same thing is done by metarefresh, it becomes an array
with only one key. This makes the handling of these two cases more
robust.
  • Loading branch information
ghalse committed Aug 22, 2016
1 parent 3d77db2 commit 9eaecd3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Auth/Process/AttributeFromEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,27 @@ public function process(&$request)
SimpleSAML_Logger::info('AttributeFromEntity: found entity attribute mapping ' .
$entityAttributeName . ' -> ' . $this->map[$entityAttributeName]);

if (!is_array($entityAttributeValue)) {
$entityAttributeValue = array($entityAttributeValue);
}

/*
* because we pass through this twice, we need to keep
* track of replacements we've made vs replacements of
* the original SAML attributes.
*/
if ($this->replace === true and !in_array($this->map[$entityAttributeName], $this->replaced)) {
$attributes[$this->map[$entityAttributeName]] = array($entityAttributeValue);
$attributes[$this->map[$entityAttributeName]] = $entityAttributeValue;
$this->replaced[$this->map[$entityAttributeName]] = true;
} elseif (array_key_exists($this->map[$entityAttributeName], $attributes)) {
if ($this->ignore !== false) {
array_push($attributes[$this->map[$entityAttributeName]],
$entityAttributeValue);
$attributes[$this->map[$entityAttributeName]]= array_merge(
$attributes[$this->map[$entityAttributeName]],
$entityAttributeValue
);
}
} else {
$attributes[$this->map[$entityAttributeName]] = array($entityAttributeValue);
$attributes[$this->map[$entityAttributeName]] = $entityAttributeValue;
}
}
}
Expand Down

0 comments on commit 9eaecd3

Please sign in to comment.