N.542, N.912 Finalized the API UserRights::Impersonate. This is an enabler for several enhancements.

SVN:trunk[4837]
This commit is contained in:
Romain Quetiez
2017-07-18 09:36:25 +00:00
parent 54ca6ad3d9
commit 46b5293867
2 changed files with 54 additions and 12 deletions

View File

@@ -431,7 +431,7 @@ EOF
unset($_SESSION['auth_user']);
unset($_SESSION['login_mode']);
unset($_SESSION['archive_mode']);
unset($_SESSION['archive_allowed']);
unset($_SESSION['impersonate_user']);
UserRights::_ResetSessionCache();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!

View File

@@ -583,6 +583,13 @@ class UserRights
return false;
}
self::$m_oUser = $oUser;
if (isset($_SESSION['impersonate_user']))
{
self::$m_oRealUser = self::$m_oUser;
self::$m_oUser = self::FindUser($_SESSION['impersonate_user']);
}
Dict::SetUserLanguage(self::GetUserLanguage());
return true;
}
@@ -702,24 +709,50 @@ class UserRights
}
}
public static function Impersonate($sName, $sPassword)
/**
* @param string $sName Login identifier of the user to impersonate
* @return bool True if an impersonation occurred
*/
public static function Impersonate($sName)
{
if (!self::CheckLogin()) return false;
$bRet = false;
$oUser = self::FindUser($sName);
if (is_null($oUser))
if ($oUser)
{
return false;
}
if (!$oUser->CheckCredentials($sPassword))
{
return false;
$bRet = true;
if (is_null(self::$m_oRealUser))
{
// First impersonation
self::$m_oRealUser = self::$m_oUser;
}
if (self::$m_oRealUser && (self::$m_oRealUser->GetKey() == $oUser->GetKey()))
{
// Equivalent to "Deimpersonate"
self::Deimpersonate();
}
else
{
// Do impersonate!
self::$m_oUser = $oUser;
Dict::SetUserLanguage(self::GetUserLanguage());
$_SESSION['impersonate_user'] = $sName;
self::_ResetSessionCache();
}
}
return $bRet;
}
self::$m_oRealUser = self::$m_oUser;
self::$m_oUser = $oUser;
Dict::SetUserLanguage(self::GetUserLanguage());
return true;
public static function Deimpersonate()
{
if (!is_null(self::$m_oRealUser))
{
self::$m_oUser = self::$m_oRealUser;
Dict::SetUserLanguage(self::GetUserLanguage());
unset($_SESSION['impersonate_user']);
self::_ResetSessionCache();
}
}
public static function GetUser()
@@ -851,6 +884,11 @@ class UserRights
return self::$m_oRealUser->Get('login');
}
public static function GetRealUserObject()
{
return self::$m_oRealUser;
}
public static function GetRealUserId()
{
if (is_null(self::$m_oRealUser))
@@ -1193,6 +1231,10 @@ class UserRights
{
unset($_SESSION['profile_list']);
}
if (isset($_SESSION['archive_allowed']))
{
unset($_SESSION['archive_allowed']);
}
}
}