Permalink
Browse files

Move session stuffs in SessionService, start removing $_SESSION usage…

… (still todo), remove the $useSession static vars from AuthService/ConfService, make this simpler.

Now ApplicationState is the reference for detecting current "sapi" type (rest / session / cli).
  • Loading branch information...
1 parent 7984f77 commit 9e97641b9525d4e08d7e3b1623fb1c07823a9a50 @cdujeu cdujeu committed Sep 22, 2016
Showing with 268 additions and 242 deletions.
  1. +0 −4 core/src/cmd.php
  2. +4 −10 core/src/core/src/pydio/Core/Controller/XMLWriter.php
  3. +1 −1 core/src/core/src/pydio/Core/Http/Dav/AuthBackendBasic.php
  4. +1 −37 core/src/core/src/pydio/Core/Http/Middleware/SessionRepositoryMiddleware.php
  5. +1 −1 core/src/core/src/pydio/Core/Http/Response/FileReaderResponse.php
  6. +2 −1 core/src/core/src/pydio/Core/Http/Rest/RestApiServer.php
  7. +2 −1 core/src/core/src/pydio/Core/Http/Wopi/Server.php
  8. +9 −1 core/src/core/src/pydio/Core/PluginFramework/PluginsService.php
  9. +1 −1 core/src/core/src/pydio/Core/Services/ApiKeysService.php
  10. +36 −39 core/src/core/src/pydio/Core/Services/AuthService.php
  11. +1 −32 core/src/core/src/pydio/Core/Services/ConfService.php
  12. +3 −3 core/src/core/src/pydio/Core/Services/LocaleService.php
  13. +56 −12 core/src/core/src/pydio/Core/Services/SessionService.php
  14. +47 −3 core/src/core/src/pydio/Core/Utils/ApplicationState.php
  15. +2 −2 core/src/plugins/access.ajxp_conf/src/RepositoriesManager.php
  16. +6 −6 core/src/plugins/access.ajxp_conf/src/UsersManager.php
  17. +1 −4 core/src/plugins/access.fs/FsAccessDriver.php
  18. +0 −1 core/src/plugins/access.smb/smb.php
  19. +1 −1 core/src/plugins/action.disclaimer/DisclaimerProvider.php
  20. +15 −10 core/src/plugins/action.share/src/Http/MinisiteAuthMiddleware.php
  21. +2 −1 core/src/plugins/action.share/src/Http/MinisiteServer.php
  22. +0 −7 core/src/plugins/action.share/src/Store/ShareStore.php
  23. +1 −1 core/src/plugins/auth.remote/glueCode.php
  24. +2 −0 core/src/plugins/authfront.cas/CasAuthFrontend.php
  25. +2 −0 core/src/plugins/authfront.cyphered/CypheredAuthFrontend.php
  26. +1 −1 core/src/plugins/authfront.duosecurity/DuoSecurityFrontend.php
  27. +11 −5 core/src/plugins/authfront.session_login/SessionLoginFrontend.php
  28. +4 −2 core/src/plugins/core.authfront/FrontendsLoader.php
  29. +1 −1 core/src/plugins/core.cache/AbstractCacheDriver.php
  30. +2 −1 core/src/plugins/core.cache/CoreCacheLoader.php
  31. +5 −5 core/src/plugins/core.conf/AbstractConfDriver.php
  32. +3 −2 core/src/plugins/core.index/CoreIndexer.php
  33. +2 −1 core/src/plugins/core.mq/src/MqManager.php
  34. +3 −8 core/src/plugins/core.ocs/src/OCSPlugin.php
  35. +2 −1 core/src/plugins/core.tasks/src/TaskService.php
  36. +5 −4 core/src/plugins/gui.ajax/RichClient.php
  37. +3 −2 core/src/plugins/index.elasticsearch/ElasticSearchIndexer.php
  38. +7 −6 core/src/plugins/index.lucene/LuceneIndexer.php
  39. +18 −16 core/src/plugins/meta.svn/SvnManager.php
  40. +2 −1 core/src/plugins/meta.syncable/ChangesTracker.php
  41. +1 −4 core/src/plugins/uploader.html/SimpleUpload.php
  42. +2 −3 core/src/worker.php
View
@@ -29,13 +29,9 @@
use Symfony\Component\Console\Application;
use Pydio\Core\Http\Cli\Command;
-ConfService::$useSession = false;
-AuthService::$useSession = false;
-
ConfService::init();
ConfService::start();
-
$input = new \Pydio\Core\Http\Cli\FreeArgvOptions();
$application = new Application();
$application->add(new Command());
@@ -24,6 +24,7 @@
use Pydio\Access\Core\IAjxpWrapperProvider;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\LocaleService;
+use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Vars\InputFilter;
use Pydio\Core\Utils\Vars\StatHelper;
use Pydio\Core\Utils\Vars\StringHelper;
@@ -54,7 +55,7 @@ class XMLWriter
public static function header($docNode="tree", $attributes=array())
{
if(self::$headerSent !== false && self::$headerSent == $docNode) return ;
- if(!ConfService::currentContextIsCommandLine()){
+ if(!ApplicationState::sapiIsCli()){
header('Content-Type: text/xml; charset=UTF-8');
header('Cache-Control: no-cache');
}
@@ -163,7 +164,7 @@ public static function renderPaginationData($count, $currentPage, $totalPages, $
*/
public static function renderHeaderNode($nodeName, $nodeLabel, $isLeaf, $metaData = array())
{
- if(!ConfService::currentContextIsCommandLine()) {
+ if(!ApplicationState::sapiIsCli()) {
header('Content-Type: text/xml; charset=UTF-8');
header('Cache-Control: no-cache');
}
@@ -179,7 +180,7 @@ public static function renderHeaderNode($nodeName, $nodeLabel, $isLeaf, $metaDat
*/
public static function renderAjxpHeaderNode($ajxpNode)
{
- if(!ConfService::currentContextIsCommandLine()) {
+ if(!ApplicationState::sapiIsCli()) {
header('Content-Type: text/xml; charset=UTF-8');
header('Cache-Control: no-cache');
}
@@ -256,13 +257,6 @@ public static function replaceAjxpXmlKeywords($xml, $stripSpaces = false)
$messages = LocaleService::getMessages();
$confMessages = LocaleService::getConfigMessages();
$matches = array();
- if (isSet($_SESSION["AJXP_SERVER_PREFIX_URI"])) {
- //$xml = str_replace("AJXP_THEME_FOLDER", $_SESSION["AJXP_SERVER_PREFIX_URI"].AJXP_THEME_FOLDER, $xml);
- $xml = str_replace("AJXP_SERVER_ACCESS", $_SESSION["AJXP_SERVER_PREFIX_URI"].AJXP_SERVER_ACCESS, $xml);
- } else {
- //$xml = str_replace("AJXP_THEME_FOLDER", AJXP_THEME_FOLDER, $xml);
- $xml = str_replace("AJXP_SERVER_ACCESS", AJXP_SERVER_ACCESS, $xml);
- }
$xml = str_replace("AJXP_APPLICATION_TITLE", ConfService::getGlobalConf("APPLICATION_TITLE"), $xml);
$xml = str_replace("AJXP_MIMES_EDITABLE", StatHelper::getAjxpMimes("editable"), $xml);
$xml = str_replace("AJXP_MIMES_IMAGE", StatHelper::getAjxpMimes("image"), $xml);
@@ -178,7 +178,7 @@ public function authenticate(Sabre\DAV\Server $server, $realm)
$webdavData["TMP_PASS"] = $encryptedPass;
$userObject->setPref("AJXP_WEBDAV_DATA", $webdavData);
$userObject->save("user");
- AuthService::updateUser($userObject);
+ AuthService::updateSessionUser($userObject);
}
return true;
@@ -167,43 +167,7 @@ public static function switchUserToRepository(UserInterface $user, ServerRequest
$user->setArrayPref("history", "last_repository", $repoObject->getId());
}
}
-
-
- /*
- if (UsersService::usersEnabled() && $loggedUser !== null && !empty($repoObject)) {
- $currentRepoId = $repoObject->getId();
- if (isSet($_SESSION["PENDING_REPOSITORY_ID"]) && isSet($_SESSION["PENDING_FOLDER"])) {
- $loggedUser->setArrayPref("history", "last_repository", $_SESSION["PENDING_REPOSITORY_ID"]);
- $loggedUser->setPref("pending_folder", $_SESSION["PENDING_FOLDER"]);
- AuthService::updateUser($loggedUser);
- unset($_SESSION["PENDING_REPOSITORY_ID"]);
- unset($_SESSION["PENDING_FOLDER"]);
- }
- $lastRepoId = $loggedUser->getArrayPref("history", "last_repository");
- $defaultRepoId = -1;
- // Find default ID from ACLS
- $acls = $loggedUser->getMergedRole()->listAcls(true);
- foreach($acls as $key => $right){
- if (!empty($right) && ConfService::getRepositoryById($key) != null) {
- $defaultRepoId= $key;
- break;
- }
- }
- if ($defaultRepoId == -1) {
- throw new NoActiveWorkspaceException();
- } else {
- if ($lastRepoId !== "" && $lastRepoId!== $currentRepoId && $restRepositoryId == -1 && $loggedUser->canSwitchTo($lastRepoId)) {
- $repoObject = ConfService::switchRootDir($lastRepoId);
- } else if ($restRepositoryId !== -1 && $loggedUser->canSwitchTo($restRepositoryId)) {
- $repoObject = ConfService::switchRootDir($restRepositoryId);
- } else if (!$loggedUser->canSwitchTo($currentRepoId)) {
- $repoObject = ConfService::switchRootDir($defaultRepoId);
- }
- }
-
- }
- */
-
+
return $repoObject;
}
@@ -442,7 +442,7 @@ protected function sendToAccelerator($accelConfiguration, $localPathOrNode, $ser
// Pydio Agent acceleration - We make sure that request was really proxied by Agent, by checking a specific header.
if($accelConfiguration === "pydio" && array_key_exists("HTTP_X_PYDIO_DOWNLOAD_SUPPORTED", $serverParams)
- && ApiKeysService::requestHasValidHeadersForAdminTask($serverParams, "go-upload", AuthService::getLoggedUser()->getId())) {
+ && ApiKeysService::requestHasValidHeadersForAdminTask($serverParams, "go-upload")) {
if ($localPathOrNode instanceof AJXP_Node) {
$options = MetaStreamWrapper::getResolvedOptionsForNode($localPathOrNode);
@@ -23,6 +23,7 @@
use Pydio\Core\Http\Server;
use Pydio\Core\Services\ConfService;
+use Pydio\Core\Utils\ApplicationState;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -41,7 +42,7 @@ class RestApiServer extends Server
public function __construct($base, $requestAttributes = [])
{
parent::__construct($base, $requestAttributes);
- ConfService::currentContextIsRestAPI($base);
+ ApplicationState::setSapiRestBase($base);
}
protected function stackMiddleWares()
@@ -23,6 +23,7 @@
use Pydio\Core\Http\Server as HttpServer;
use Pydio\Core\Services\ConfService;
+use Pydio\Core\Utils\ApplicationState;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -41,7 +42,7 @@ class Server extends HttpServer
public function __construct($base, $additionalAttributes = [])
{
parent::__construct($base, $additionalAttributes);
- ConfService::currentContextIsRestAPI($base);
+ ApplicationState::setSapiRestBase($base);
}
protected function stackMiddleWares()
@@ -37,7 +37,9 @@
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Services\CacheService;
+use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\UsersService;
+use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\FileHelper;
use Pydio\Log\Core\Logger;
use Pydio\Access\Meta\Core\AbstractMetaSource;
@@ -1241,8 +1243,14 @@ private function updateXmlRegistry($registry, $extendedVersion = true)
*/
private function getRegistryCacheKey($extendedVersion = true)
{
+ $phpContext = 'session';
+ if(ApplicationState::getSapiRestBase() !== null){
+ $phpContext = 'rest';
+ }else if(ApplicationState::sapiIsCli()){
+ $phpContext = 'cli';
+ }
$v = $extendedVersion ? "extended" : "light";
- return "xml_registry:" . $v . ":" . $this->context->getStringIdentifier();
+ return "xml_registry:". $phpContext . ":" . $v . ":" . $this->context->getStringIdentifier();
}
/**
@@ -148,7 +148,7 @@ public static function revokePairForAdminTask($adminTaskId, $userId = ""){
* @param $userId
* @return bool
*/
- public static function requestHasValidHeadersForAdminTask($serverData, $adminTaskId, $userId){
+ public static function requestHasValidHeadersForAdminTask($serverData, $adminTaskId, $userId = ""){
if(!isSet($serverData['HTTP_X_PYDIO_ADMIN_AUTH'])){
Logger::error(__CLASS__, __FUNCTION__,"Invalid tokens for admin task $adminTaskId");
return false;
@@ -20,11 +20,11 @@
*/
namespace Pydio\Core\Services;
use Pydio\Auth\Core\MemorySafe;
-use Pydio\Conf\Core\AbstractUser;
use Pydio\Core\Controller\Controller;
use Pydio\Core\Exception\LoginException;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\UserInterface;
+use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Http\BruteForceHelper;
use Pydio\Core\Utils\Http\CookiesHelper;
use Pydio\Core\Utils\Vars\InputFilter;
@@ -39,26 +39,8 @@
*/
class AuthService
{
- public static $useSession = true;
- private static $currentUser;
+
public static $bufferedMessage = null;
-
- /**
- * Get the currently logged user object
- * @return AbstractUser
- */
- public static function getLoggedUser()
- {
- if (self::$useSession && isSet($_SESSION["AJXP_USER"])) {
- if (is_a($_SESSION["AJXP_USER"], "__PHP_Incomplete_Class")) {
- session_unset();
- return null;
- }
- return $_SESSION["AJXP_USER"];
- }
- if(!self::$useSession && isSet(self::$currentUser)) return self::$currentUser;
- return null;
- }
/**
* Log the user from its credentials
@@ -132,10 +114,10 @@ public static function logUser($user_id, $pwd, $bypass_pwd = false, $cookieLogin
$user->save("superuser"); // make sure update rights now
}
- self::updateUser($user);
+ //self::updateSessionUser($user);
Controller::applyHook("user.after_login", [$tempContext, $user]);
- Logger::info(__CLASS__, "Log In", array("context"=>self::$useSession?"WebUI":"API"));
+ Logger::info(__CLASS__, "Log In", array("context"=> ApplicationState::sapiUsesSession() ?"WebUI":"API"));
return $user;
}
@@ -145,33 +127,48 @@ public static function logUser($user_id, $pwd, $bypass_pwd = false, $cookieLogin
* @param $userObject
* @return void
*/
- public static function updateUser($userObject)
- {
- if(self::$useSession) $_SESSION["AJXP_USER"] = $userObject;
- else self::$currentUser = $userObject;
+ public static function updateSessionUser($userObject) {
+ SessionService::save(SessionService::USER_KEY, $userObject);
}
/**
+ * Force an acl change for the current session user
+ * @param $repositoryId
+ * @param $acl
+ */
+ public static function updateSessionUserAcl($repositoryId, $acl){
+ /**
+ * @var $u UserInterface
+ */
+ $u = SessionService::fetch(SessionService::USER_KEY);
+ if($u instanceof UserInterface){
+ $u->getPersonalRole()->setAcl($repositoryId, $acl);
+ $u->recomputeMergedRole();
+ self::updateSessionUser($u);
+ }
+ }
+
+
+ /**
* Clear the session
* @static
* @return void
*/
public static function disconnect()
{
- if (isSet($_SESSION["AJXP_USER"]) || isSet(self::$currentUser)) {
- $user = isSet($_SESSION["AJXP_USER"]) ? $_SESSION["AJXP_USER"] : self::$currentUser;
- $userId = $user->id;
- Controller::applyHook("user.before_disconnect", array(Context::emptyContext(), $user));
- CookiesHelper::clearRememberCookie($user);
- Logger::info(__CLASS__, "Log Out", "");
- unset($_SESSION["AJXP_USER"]);
- //if(isSet(self::$currentUser)) unset(self::$currentUser);
- if (ConfService::getContextConf(Context::contextWithObjects($user, null), "SESSION_SET_CREDENTIALS", "auth")) {
- MemorySafe::clearCredentials();
- }
- Controller::applyHook("user.after_disconnect", array(Context::emptyContext(), $userId));
+ $user = SessionService::fetch(SessionService::USER_KEY);
+ if(empty($user) || !$user instanceof UserInterface){
+ return;
}
+ $userId = $user->getId();
+ Controller::applyHook("user.before_disconnect", array(Context::emptyContext(), $user));
+ CookiesHelper::clearRememberCookie($user);
+ Logger::info(__CLASS__, "Log Out", "");
+ SessionService::delete(SessionService::USER_KEY);
+ if (ConfService::getContextConf(Context::contextWithObjects($user, null), "SESSION_SET_CREDENTIALS", "auth")) {
+ MemorySafe::clearCredentials();
+ }
+ Controller::applyHook("user.after_disconnect", array(Context::emptyContext(), $userId));
}
-
}
@@ -44,7 +44,6 @@
class ConfService
{
private static $instance;
- public static $useSession = true;
private $errors = array();
private $configs = array();
@@ -173,37 +172,7 @@ public static function instanciatePluginFromGlobalParams($globalsArray, $interfa
return $plugin;
}
-
- /**
- * Check if the STDIN constant is defined
- * @static
- * @return bool
- */
- public static function currentContextIsCommandLine()
- {
- return php_sapi_name() === "cli";
- }
-
- protected static $restAPIContext;
-
- /**
- * Set or get if we are currently running REST
- * @static
- * @param string $restBase
- * @return bool
- */
- public static function currentContextIsRestAPI($restBase = '')
- {
- if(!empty($restBase)){
- self::$restAPIContext = $restBase;
- self::$useSession = false;
- AuthService::$useSession = false;
- return $restBase;
- }else{
- return self::$restAPIContext;
- }
- }
-
+
/**
* Check the presence of mcrypt and option CMDLINE_ACTIVE
* @static
@@ -129,8 +129,8 @@ public static function getMessages($forceRefresh = false)
public static function listAvailableLanguages()
{
// Cache in session!
- if (isSet($_SESSION["AJXP_LANGUAGES"]) && !isSet($_GET["refresh_langs"])) {
- return $_SESSION["AJXP_LANGUAGES"];
+ if (SessionService::has(SessionService::LANGUAGES_KEY) && !isSet($_GET["refresh_langs"])) {
+ return SessionService::fetch(SessionService::LANGUAGES_KEY);
}
$langDir = AJXP_COREI18N_FOLDER;
$languages = array();
@@ -147,7 +147,7 @@ public static function listAvailableLanguages()
closedir($dh);
}
if (count($languages)) {
- $_SESSION["AJXP_LANGUAGES"] = $languages;
+ SessionService::save(SessionService::LANGUAGES_KEY, $languages);
}
return $languages;
}
Oops, something went wrong.

0 comments on commit 9e97641

Please sign in to comment.