Skip to content
Snippets Groups Projects
Commit 6f505923 authored by Olav Morken's avatar Olav Morken
Browse files

Add unique user id to module attribute processing state.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@820 44740490-163a-0410-bde0-09ae8108e29a
parent 25073d2b
No related branches found
No related tags found
No related merge requests found
......@@ -163,6 +163,11 @@ class SimpleSAML_Auth_ProcessingChain {
$state[self::FILTERS_INDEX] = $this->filters;
if (!array_key_exists('UserID', $state)) {
/* No unique user ID present. Attempt to add one. */
self::addUserID($state);
}
while (count($state[self::FILTERS_INDEX]) > 0) {
$filter = array_shift($state[self::FILTERS_INDEX]);
$filter->process($state);
......@@ -213,6 +218,46 @@ class SimpleSAML_Auth_ProcessingChain {
return SimpleSAML_Auth_State::loadState($id, self::COMPLETED_STAGE);
}
/**
* Add unique user ID.
*
* This function attempts to add an unique user ID to the state.
*
* @param array &$state The state we should update.
*/
private static function addUserID(&$state) {
assert('is_array($state)');
assert('array_key_exists("Attributes", $state)');
if (isset($state['Destination']['userid.attribute'])) {
$attributeName = $state['Destination']['userid.attribute'];
} elseif (isset($state['Source']['userid.attribute'])) {
$attributeName = $state['Source']['userid.attribute'];
} else {
/* Default attribute. */
$attributeName = 'eduPersonPrincipalName';
}
if (!array_key_exists($attributeName, $state['Attributes'])) {
return;
}
$uid = $state['Attributes'][$attributeName];
if (count($uid) === 0) {
SimpleSAML_Logger::warning('Empty user id attribute \'' . $attributeName . '\'.');
return;
}
if (count($uid) > 1) {
SimpleSAML_Logger::warning('Multiple attribute values for user id attribute \'' .
$attributeName . '\'.');
}
$uid = $uid[0];
$state['UserID'] = $uid;
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment