From 07905af114d86ab96dbbe132b7fb0438d72b95ef Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 20 Jan 2015 13:56:12 +0100 Subject: [PATCH] Stop calling SimpleSAML_Session::getAttributes() in SimpleSAML_Error_Error class. Use an alternate way to try to fetch user's mail. --- lib/SimpleSAML/Error/Error.php | 13 ++++++++----- lib/SimpleSAML/Session.php | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php index bc10ff187..a08ffddcd 100644 --- a/lib/SimpleSAML/Error/Error.php +++ b/lib/SimpleSAML/Error/Error.php @@ -269,12 +269,15 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { $data['errorReportAddress'] = $baseurl . 'errorreport.php'; } + $data['email'] = ''; $session = SimpleSAML_Session::getSessionFromRequest(); - $attributes = $session->getAttributes(); - if (is_array($attributes) && array_key_exists('mail', $attributes) && count($attributes['mail']) > 0) { - $data['email'] = $attributes['mail'][0]; - } else { - $data['email'] = ''; + $authorities = $session->getAuthorities(); + foreach ($authorities as $authority) { + $attributes = $session->getAuthData($authority, 'Attributes'); + if ($attributes !== NULL && array_key_exists('mail', $attributes) && count($attributes['mail']) > 0) { + $data['email'] = $attributes['mail'][0]; + break; // enough, don't need to get all available mails, if more than one + } } $show_function = $config->getArray('errors.show_function', NULL); diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php index fae1e0206..369659520 100644 --- a/lib/SimpleSAML/Session.php +++ b/lib/SimpleSAML/Session.php @@ -901,4 +901,21 @@ class SimpleSAML_Session { return $this->authData[$authority][$name]; } + + /** + * Retrieve a list of authorities (authentication sources) that are currently valid within + * this session. + * + * @return mixed An array containing every authority currently valid. Empty if none available. + */ + public function getAuthorities() + { + $authorities = array(); + foreach (array_keys($this->authData) as $authority) { + if ($this->isValid($authority)) { + $authorities[] = $authority; + } + } + return $authorities; + } } -- GitLab