Address the issue of the administrator changing the identity provider whilst users are logged onto the system. Addressed the issue by adding try/catch logic to the Session::load_user() method. If load_user fails for any reason, then assume that the identity provider has changed, destroy the current session and redirect to the root album.

This commit is contained in:
Tim Almdal
2009-10-21 15:17:23 -07:00
parent b994ea9d62
commit 7638834e97
+28 -19
View File
@@ -23,26 +23,35 @@ class Session extends Session_Core {
* Make sure that we have a session and group_ids cached in the session.
*/
static function load_user() {
$session = Session::instance();
if (!($user = $session->get("user"))) {
$session->set("user", $user = Identity::guest());
}
// The installer cannot set a user into the session, so it just sets an id which we should
// upconvert into a user.
// @todo set the user name into the session instead of 2 and then use it to get the user object
if ($user === 2) {
$user = Instance::lookup_user_by_name("admin");
self::set_active_user($user);
$session->set("user", $user);
}
if (!$session->get("group_ids")) {
$ids = array();
foreach ($user->groups as $group) {
$ids[] = $group->id;
try {
$session = Session::instance();
if (!($user = $session->get("user"))) {
$session->set("user", $user = Identity::guest());
}
$session->set("group_ids", $ids);
// The installer cannot set a user into the session, so it just sets an id which we should
// upconvert into a user.
// @todo set the user name into the session instead of 2 and then use it to get the user object
if ($user === 2) {
$user = Instance::lookup_user_by_name("admin");
self::set_active_user($user);
$session->set("user", $user);
}
if (!$session->get("group_ids")) {
$ids = array();
foreach ($user->groups as $group) {
$ids[] = $group->id;
}
$session->set("group_ids", $ids);
}
} catch (Exception $e) {
try {
Session::instance()->destroy();
} catch (Exception $e) {
// We don't care if there was a problem destroying the session.
}
url::redirect(item::root()->abs_url());
}
}