protected function UserFieldsEventSubscriber::getAttribute in SAML Authentication 8.3
Same name and namespace in other branches
- 4.x modules/samlauth_user_fields/src/EventSubscriber/UserFieldsEventSubscriber.php \Drupal\samlauth_user_fields\EventSubscriber\UserFieldsEventSubscriber::getAttribute()
Returns value from a SAML attribute; logs anything strange.
This is suitable for single-value attributes. For multi-value attributes, we log a debug message to make clear we're dropping data (because this indicates that the site owner may need to take care of getting more sophisticated path mapping code).
Parameters
string $name: The name of a SAML attribute.
array $attributes: The complete set of SAML attributes in the assertion. (The attributes can currently be duplicated, keyed both by their name and friendly name.)
Return value
mixed|null The SAML attribute value; NULL if the attribute value was not found.
2 calls to UserFieldsEventSubscriber::getAttribute()
- UserFieldsEventSubscriber::getMatchExpressions in modules/
samlauth_user_fields/ src/ EventSubscriber/ UserFieldsEventSubscriber.php - Constructs expressions that should be used for user matching attempts.
- UserFieldsEventSubscriber::getUpdatableAttributeValue in modules/
samlauth_user_fields/ src/ EventSubscriber/ UserFieldsEventSubscriber.php - Returns 'updatable' value from a SAML attribute; logs anything strange.
File
- modules/
samlauth_user_fields/ src/ EventSubscriber/ UserFieldsEventSubscriber.php, line 553
Class
- UserFieldsEventSubscriber
- Synchronizes SAML attributes into user fields / links new users during login.
Namespace
Drupal\samlauth_user_fields\EventSubscriberCode
protected function getAttribute($name, array $attributes) {
$value = NULL;
if (isset($attributes[$name])) {
// Log everything unexpected about the format of the attributes. Use
// debug() because we're not sure if the site owner would be able to fix
// things.
if (!is_array($attributes[$name])) {
$this->logger
->debug('SAML attribute %name has a non-array value; this points to a coding error somewhere (since the SAML standard seems to mandate this).', [
'%name' => $name,
]);
}
elseif ($attributes[$name]) {
if (count($attributes[$name]) > 1) {
$this->logger
->debug('SAML attribute %name has multiple values; we only support using the first one: @values.', [
'%name' => $name,
'@values' => function_exists('json_encode') ? json_encode($attributes[$name]) : var_export($attributes[$name], TRUE),
]);
}
if (!isset($attributes[$name][0])) {
$value = reset($attributes[$name]);
$this->logger
->debug("SAML attribute %name's one-element array value has non-zero key %key, which points to a coding error somewhere; even though we are using the value, we're not sure if that's right.", [
'%name' => $name,
]);
}
else {
$value = $attributes[$name][0];
}
}
}
return $value;
}