N°3985 - Performance checks on the back end - Fix Session helper

This commit is contained in:
Eric
2021-08-26 16:14:14 +02:00
parent 81d9ea389d
commit 67cd5e321e
7 changed files with 7 additions and 22 deletions

View File

@@ -51,10 +51,8 @@ class LoginForm extends AbstractLoginFSMExtension implements iLoginUIExtension
$this->bForceFormOnError = false; $this->bForceFormOnError = false;
exit; exit;
} }
Session::Start();
Session::Set('login_temp_auth_user', $sAuthUser); Session::Set('login_temp_auth_user', $sAuthUser);
Session::Set('login_mode', 'form'); Session::Set('login_mode', 'form');
Session::WriteClose();
} }
return LoginWebPage::LOGIN_FSM_CONTINUE; return LoginWebPage::LOGIN_FSM_CONTINUE;
} }

View File

@@ -394,14 +394,12 @@ class LoginWebPage extends NiceWebPage
public static function ResetSession() public static function ResetSession()
{ {
// Unset all of the session variables. // Unset all of the session variables.
Session::Start();
Session::Unset('auth_user'); Session::Unset('auth_user');
Session::Unset('login_state'); Session::Unset('login_state');
Session::Unset('can_logoff'); Session::Unset('can_logoff');
Session::Unset('archive_mode'); Session::Unset('archive_mode');
Session::Unset('impersonate_user'); Session::Unset('impersonate_user');
UserRights::_ResetSessionCache(); UserRights::_ResetSessionCache();
Session::WriteClose();
// If it's desired to kill the session, also delete the session cookie. // 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! // Note: This will destroy the session, and not just the session data!
} }
@@ -669,10 +667,8 @@ class LoginWebPage extends NiceWebPage
$oLog->DBInsertNoReload(); $oLog->DBInsertNoReload();
} }
Session::Start();
Session::Set('auth_user', $sAuthUser); Session::Set('auth_user', $sAuthUser);
Session::Set('login_mode', $sLoginMode); Session::Set('login_mode', $sLoginMode);
Session::WriteClose();
UserRights::_InitSessionCache(); UserRights::_InitSessionCache();
} }
@@ -1017,7 +1013,6 @@ class LoginWebPage extends NiceWebPage
$sMessage = self::HandleOperations($operation); // May exit directly $sMessage = self::HandleOperations($operation); // May exit directly
$iRet = self::Login($iOnExit); $iRet = self::Login($iOnExit);
if ($iRet == self::EXIT_CODE_OK) if ($iRet == self::EXIT_CODE_OK)
{ {
if ($bMustBeAdmin && !UserRights::IsAdministrator()) if ($bMustBeAdmin && !UserRights::IsAdministrator())

View File

@@ -68,9 +68,10 @@ register_shutdown_function(function()
} }
} }
}); });
$oKPI = new ExecutionKPI();
Session::Start(); Session::Start();
Session::WriteClose(); Session::WriteClose();
$oKPI->ComputeAndReport("Session Start");
$sSwitchEnv = utils::ReadParam('switch_env', null); $sSwitchEnv = utils::ReadParam('switch_env', null);
$bAllowCache = true; $bAllowCache = true;

View File

@@ -1795,10 +1795,6 @@ class UserRights
self::$m_aAdmins = array(); self::$m_aAdmins = array();
self::$m_aPortalUsers = array(); self::$m_aPortalUsers = array();
} }
if (!utils::IsModeCLI())
{
Session::Start();
}
self::_ResetSessionCache(); self::_ResetSessionCache();
if (self::$m_oAddOn) if (self::$m_oAddOn)
{ {
@@ -1905,10 +1901,8 @@ class UserRights
public static function _ResetSessionCache() public static function _ResetSessionCache()
{ {
Session::Start();
Session::Unset('profile_list'); Session::Unset('profile_list');
Session::Unset('archive_allowed'); Session::Unset('archive_allowed');
Session::WriteClose();
} }
/** /**

View File

@@ -49,7 +49,6 @@ class CASLoginExtension extends AbstractLoginFSMExtension implements iLogoutExte
{ {
if (Session::Get('login_mode') == 'cas') if (Session::Get('login_mode') == 'cas')
{ {
Session::Start();
static::InitCASClient(); static::InitCASClient();
if (phpCAS::isAuthenticated()) if (phpCAS::isAuthenticated())
{ {
@@ -72,7 +71,6 @@ class CASLoginExtension extends AbstractLoginFSMExtension implements iLogoutExte
Session::Set('login_mode', 'cas'); Session::Set('login_mode', 'cas');
phpCAS::forceAuthentication(); // Redirect to CAS and exit phpCAS::forceAuthentication(); // Redirect to CAS and exit
} }
Session::WriteClose();
} }
return LoginWebPage::LOGIN_FSM_CONTINUE; return LoginWebPage::LOGIN_FSM_CONTINUE;
} }

View File

@@ -43,9 +43,11 @@ if ($sPage == '')
} }
$sPage = basename($sPage); // protect against ../.. ... $sPage = basename($sPage); // protect against ../.. ...
$oKPI = new ExecutionKPI();
Session::Start(); Session::Start();
$sEnvironment = utils::ReadParam('exec_env', utils::GetCurrentEnvironment()); $sEnvironment = utils::ReadParam('exec_env', utils::GetCurrentEnvironment());
Session::WriteClose(); Session::WriteClose();
$oKPI->ComputeAndReport("Session Start");
$sTargetPage = APPROOT.'env-'.$sEnvironment.'/'.$sModule.'/'.$sPage; $sTargetPage = APPROOT.'env-'.$sEnvironment.'/'.$sModule.'/'.$sPage;

View File

@@ -7,8 +7,6 @@
namespace Combodo\iTop\Application\Helper; namespace Combodo\iTop\Application\Helper;
use ExecutionKPI;
/** /**
* Session management * Session management
* Allow early session close to have multiple ajax calls in parallel * Allow early session close to have multiple ajax calls in parallel
@@ -26,7 +24,6 @@ class Session
{ {
self::$bIsInitialized = true; self::$bIsInitialized = true;
if (!self::$bSessionStarted) { if (!self::$bSessionStarted) {
$oKPI = new ExecutionKPI();
session_name('itop-'.md5(APPROOT)); session_name('itop-'.md5(APPROOT));
if (!is_null(self::$iSessionId)) { if (!is_null(self::$iSessionId)) {
session_id(self::$iSessionId); session_id(self::$iSessionId);
@@ -35,17 +32,14 @@ class Session
self::$bSessionStarted = session_start(); self::$bSessionStarted = session_start();
self::$iSessionId = session_id(); self::$iSessionId = session_id();
} }
$oKPI->ComputeAndReport("Session Start");
} }
} }
public static function WriteClose() public static function WriteClose()
{ {
if (self::$bSessionStarted) { if (self::$bSessionStarted) {
$oKPI = new ExecutionKPI();
session_write_close(); session_write_close();
self::$bSessionStarted = false; self::$bSessionStarted = false;
$oKPI->ComputeAndReport("Session Write Close");
} }
} }
@@ -55,6 +49,9 @@ class Session
*/ */
public static function Set($key, $value) public static function Set($key, $value)
{ {
if (self::Get($key) == $value) {
return;
}
$aSession = $_SESSION; $aSession = $_SESSION;
$sSessionVar = &$aSession; $sSessionVar = &$aSession;
if (is_array($key)) { if (is_array($key)) {