Permalink
Browse files

Encapsulate users objects loading / caching inside UsersService

  • Loading branch information...
1 parent 1e6cc40 commit 86591d4f7d49f94c0f0a340d85d837a0bda13ccc @cdujeu cdujeu committed Jun 17, 2016
Showing with 379 additions and 279 deletions.
  1. +1 −0 core/src/.gitignore
  2. +1 −1 core/src/core/src/pydio/Core/Controller/XMLWriter.php
  3. +39 −0 core/src/core/src/pydio/Core/Exception/UserNotFoundException.php
  4. +7 −2 core/src/core/src/pydio/Core/Http/Dav/AuthBackendBasic.php
  5. +5 −4 core/src/core/src/pydio/Core/Http/Dav/AuthBackendDigest.php
  6. +3 −5 core/src/core/src/pydio/Core/Model/Context.php
  7. +1 −1 core/src/core/src/pydio/Core/Services/AuthService.php
  8. +0 −51 core/src/core/src/pydio/Core/Services/ConfService.php
  9. +3 −0 core/src/core/src/pydio/Core/Services/RepositoryService.php
  10. +2 −4 core/src/core/src/pydio/Core/Services/RolesService.php
  11. +135 −16 core/src/core/src/pydio/Core/Services/UsersService.php
  12. +35 −32 core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php
  13. +6 −5 core/src/plugins/access.ajxp_user/class.UserDashboardDriver.php
  14. +1 −2 core/src/plugins/action.avatar/class.AvatarProvider.php
  15. +2 −2 core/src/plugins/action.share/src/Legacy/LegacyPubliclet.php
  16. +7 −5 core/src/plugins/action.share/src/ShareCenter.php
  17. +10 −10 core/src/plugins/action.share/src/Store/ShareRightsManager.php
  18. +1 −1 core/src/plugins/action.share/src/Store/ShareStore.php
  19. +2 −4 core/src/plugins/auth.remote/glueCode.php
  20. +1 −1 core/src/plugins/authfront.cas/class.CasAuthFrontend.php
  21. +4 −4 core/src/plugins/authfront.duosecurity/class.DuoSecurityFrontend.php
  22. +9 −10 core/src/plugins/authfront.otp/class.OtpAuthFrontend.php
  23. +1 −2 core/src/plugins/authfront.session_login/class.SessionLoginFrontend.php
  24. +10 −12 core/src/plugins/boot.conf/class.BootConfLoader.php
  25. +1 −1 core/src/plugins/conf.sql/class.AJXP_SqlUser.php
  26. +1 −1 core/src/plugins/conf.sql/class.sqlConfDriver.php
  27. +1 −3 core/src/plugins/core.access/src/Model/AJXP_Node.php
  28. +2 −2 core/src/plugins/core.conf/class.AbstractAjxpUser.php
  29. +73 −85 core/src/plugins/core.conf/class.AbstractConfDriver.php
  30. +4 −5 core/src/plugins/core.mailer/class.AjxpMailer.php
  31. +1 −1 core/src/plugins/core.notifications/class.AJXP_Notification.php
  32. +2 −0 core/src/plugins/core.notifications/class.AJXP_NotificationCenter.php
  33. +3 −2 core/src/plugins/gui.user/class.UserGuiController.php
  34. +2 −2 core/src/plugins/meta.quota/class.QuotaComputer.php
  35. +1 −1 core/src/plugins/meta.simple_lock/class.SimpleLockManager.php
  36. +2 −2 core/src/plugins/meta.watch/class.MetaWatchRegister.php
View
@@ -1,3 +1,4 @@
+/plugins/index.elasticsearch/vendor
/plugins/access.ajxp_home/res/build
/plugins/access.inbox/res/build
/plugins/core.mailer/js/build
@@ -663,7 +663,7 @@ public static function repositoryToXML($repoId, $repoObject, $exposed, $streams,
if($loggedUser != null && $loggedUser->getId() == $uId){
$currentUserIsOwner = true;
}
- $label = ConfService::getUserPersonalParameter("USER_DISPLAY_NAME", $uId, "core.conf", $uId);
+ $label = UsersService::getUserPersonalParameter("USER_DISPLAY_NAME", $uId, "core.conf", $uId);
$ownerLabel = $label;
$isSharedString = 'owner="'.Utils::xmlEntities($label).'"';
}
@@ -0,0 +1,39 @@
+<?php
+/*
+ * Copyright 2007-2016 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <https://pydio.com/>.
+ */
+namespace Pydio\Core\Exception;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+/**
+ * Class UserNotFoundException
+ * @package Pydio\Core\Exception
+ */
+class UserNotFoundException extends PydioException
+{
+ /**
+ * UserNotFoundException constructor.
+ * @param string $userId
+ */
+ public function __construct($userId)
+ {
+ parent::__construct("Cannot find user ".$userId, null, 50014);
+ }
+}
@@ -24,6 +24,7 @@
use Pydio\Auth\Core\AJXP_Safe;
use Pydio\Core\Exception\LoginException;
use Pydio\Core\Exception\RepositoryLoadException;
+use Pydio\Core\Exception\UserNotFoundException;
use Pydio\Core\Exception\WorkspaceForbiddenException;
use Pydio\Core\Exception\WorkspaceNotFoundException;
use Pydio\Core\Model\ContextInterface;
@@ -87,8 +88,12 @@ public function authenticate(Sabre\DAV\Server $server, $realm)
// Authenticates the user
//AJXP_Logger::info(__CLASS__,"authenticate",$userpass[0]);
- $confDriver = ConfService::getConfStorageImpl();
- $userObject = $confDriver->createUserObject($userpass[0]);
+ try{
+ $userObject = UsersService::getUserById($userpass[0]);
+ }catch (UserNotFoundException $e){
+ throw new Sabre\DAV\Exception\NotAuthenticated();
+ }
+
$webdavData = $userObject->getPref("AJXP_WEBDAV_DATA");
if (empty($webdavData) || !isset($webdavData["ACTIVE"]) || $webdavData["ACTIVE"] !== true) {
AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => $userpass[0], "error" => "WebDAV user not found or disabled"));
@@ -22,6 +22,7 @@
use Pydio\Core\Exception\LoginException;
use Pydio\Core\Exception\RepositoryLoadException;
+use Pydio\Core\Exception\UserNotFoundException;
use Pydio\Core\Exception\WorkspaceForbiddenException;
use Pydio\Core\Exception\WorkspaceNotFoundException;
@@ -62,11 +63,11 @@ public function __construct($context)
public function getDigestHash($realm, $username)
{
- if (!UsersService::userExists($username)) {
- return false;
+ try{
+ $user = UsersService::getUserById($username);
+ }catch (UserNotFoundException $e){
+ throw new Sabre\DAV\Exception\NotAuthenticated();
}
- $confDriver = ConfService::getConfStorageImpl();
- $user = $confDriver->createUserObject($username);
$webdavData = $user->getPref("AJXP_WEBDAV_DATA");
if (empty($webdavData) || !isset($webdavData["ACTIVE"]) || $webdavData["ACTIVE"] !== true || (!isSet($webdavData["PASS"]) && !isset($webdavData["HA1"]) ) ) {
return false;
@@ -21,8 +21,8 @@
namespace Pydio\Core\Model;
-use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\RepositoryService;
+use Pydio\Core\Services\UsersService;
defined('AJXP_EXEC') or die('Access not allowed');
@@ -123,7 +123,7 @@ public function getUser()
return $this->userObject;
}
if(isSet($this->userId)){
- $this->userObject = ConfService::getConfStorageImpl()->createUserObject($this->userId);
+ $this->userObject = UsersService::getUserById($this->userId, false);
return $this->userObject;
}
return null;
@@ -215,15 +215,13 @@ public function resetRepository()
public function getStringIdentifier()
{
- $logged = $this->getUser();
- $u = $logged == null ? "shared" : $logged->getId();
+ $u = $this->userId == null ? "shared" : $this->userId;
$a = "norepository";
$r = $this->getRepository();
if($r !== null){
$a = $r->getSlug();
}
return $u.":".$a;
-
}
/**
@@ -120,7 +120,7 @@ public static function logUser($user_id, $pwd, $bypass_pwd = false, $cookieLogin
AJXP_Safe::storeCredentials($authId, $authPwd);
}
- $user = $confDriver->createUserObject($user_id);
+ $user = UsersService::getUserById($user_id, false);
if ($user->getLock() === "logout") {
AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => Utils::sanitize($user_id, AJXP_SANITIZE_EMAILCHARS), "error" => "Locked user"));
@@ -479,57 +479,6 @@ public static function getCoreConf($varName, $coreType = "ajaxplorer")
}
/**
- * @var array Keep loaded labels in memory
- */
- private static $usersParametersCache = array();
-
- /**
- * @param string $parameterName Plugin parameter name
- * @param AbstractAjxpUser|string $userIdOrObject
- * @param string $pluginId Plugin name, core.conf by default
- * @param null $defaultValue
- * @return mixed
- */
- public static function getUserPersonalParameter($parameterName, $userIdOrObject, $pluginId="core.conf", $defaultValue=null){
-
- $cacheId = $pluginId."-".$parameterName;
- if(!isSet(self::$usersParametersCache[$cacheId])){
- self::$usersParametersCache[$cacheId] = array();
- }
- // Passed an already loaded object
- if($userIdOrObject instanceof AbstractAjxpUser){
- $value = $userIdOrObject->personalRole->filterParameterValue($pluginId, $parameterName, AJXP_REPO_SCOPE_ALL, $defaultValue);
- self::$usersParametersCache[$cacheId][$userIdOrObject->getId()] = $value;
- if(empty($value) && !empty($defaultValue)) $value = $defaultValue;
- return $value;
- }
- // Already in memory cache
- if(isSet(self::$usersParametersCache[$cacheId][$userIdOrObject])){
- return self::$usersParametersCache[$cacheId][$userIdOrObject];
- }
-
- // Try to load personal role if it was already loaded.
- $uRole = RolesService::getRole("AJXP_USR_/" . $userIdOrObject);
- if($uRole === false){
- $uObject = self::getConfStorageImpl()->createUserObject($userIdOrObject);
- if(isSet($uObject)){
- $uRole = $uObject->personalRole;
- }
- }
- if(empty($uRole)){
- return $defaultValue;
- }
- $value = $uRole->filterParameterValue($pluginId, $parameterName, AJXP_REPO_SCOPE_ALL, $defaultValue);
- if(empty($value) && !empty($defaultValue)) {
- $value = $userIdOrObject;
- }
- self::$usersParametersCache[$cacheId][$userIdOrObject] = $value;
- return $value;
-
- }
-
-
- /**
* Singleton method
*
* @return ConfService the service instance
@@ -354,17 +354,20 @@ private function getRepositoryByIdInst($repoId)
}
$test = CacheService::fetch(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId);
if($test !== false){
+ $this->cache["REPOSITORIES"][$repoId] = $test;
return $test;
}
$test = ConfService::getConfStorageImpl()->getRepositoryById($repoId);
if($test != null) {
+ $this->cache["REPOSITORIES"][$repoId] = $test;
CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId, $test);
return $test;
}
// Finally try to search in default repositories
$statics = self::getStaticRepositories();
if (isSet($statics[$repoId])) {
$repo = $statics[$repoId];
+ $this->cache["REPOSITORIES"][$repoId] = $test;
CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, "repository:" . $repoId, $repo);
return $repo;
}
@@ -354,9 +354,8 @@ public static function bootSequence()
if (!$authDriver->getOptionAsBool("TRANSMIT_CLEAR_PASS")) {
$adminPass = md5(ADMIN_PASSWORD);
}
- UsersService::createUser("admin", $adminPass, true);
+ $userObject = UsersService::createUser("admin", $adminPass, true);
if (ADMIN_PASSWORD == INITIAL_ADMIN_PASSWORD) {
- $userObject = ConfService::getConfStorageImpl()->createUserObject("admin");
$userObject->setAdmin(true);
RolesService::updateAdminRights($userObject);
if (UsersService::changePasswordEnabled()) {
@@ -369,8 +368,7 @@ public static function bootSequence()
}
} else if ($adminCount == -1) {
// Here we may come from a previous version! Check the "admin" user and set its right as admin.
- $confStorage = ConfService::getConfStorageImpl();
- $adminUser = $confStorage->createUserObject("admin");
+ $adminUser = UsersService::getUserById("admin");
$adminUser->setAdmin(true);
$adminUser->save("superuser");
file_put_contents(AJXP_CACHE_DIR . "/admin_counted", "true");
Oops, something went wrong.

0 comments on commit 86591d4

Please sign in to comment.