summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Morken <olav.morken@uninett.no>2008-08-20 06:58:23 +0000
committerOlav Morken <olav.morken@uninett.no>2008-08-20 06:58:23 +0000
commit6f5059233cf41e86685c5108277df391aec25dde (patch)
tree280751a645a2bd3a3a479775cdb36e68a71bbf0b
parent25073d2b21bccd0b4ad8668e71fa9bca97adad0e (diff)
downloadsimplesamlphp-6f5059233cf41e86685c5108277df391aec25dde.zip
simplesamlphp-6f5059233cf41e86685c5108277df391aec25dde.tar.gz
simplesamlphp-6f5059233cf41e86685c5108277df391aec25dde.tar.bz2
Add unique user id to module attribute processing state.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@820 44740490-163a-0410-bde0-09ae8108e29a
-rw-r--r--lib/SimpleSAML/Auth/ProcessingChain.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Auth/ProcessingChain.php b/lib/SimpleSAML/Auth/ProcessingChain.php
index 4ba54ba..a3b3615 100644
--- a/lib/SimpleSAML/Auth/ProcessingChain.php
+++ b/lib/SimpleSAML/Auth/ProcessingChain.php
@@ -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