Permalink
Browse files

Re-setting admin auth for Websocket authentication

  • Loading branch information...
2 parents a1b4abb + 2a77d7b commit 8212433ac5c2aedb3ee956bc91a527f54e6b0d70 @ghecquet ghecquet committed Jun 6, 2016
Showing with 2,582 additions and 1,699 deletions.
  1. +28 −40 core/src/core/src/pydio/Core/Controller/Controller.php
  2. +4 −2 core/src/core/src/pydio/Core/Controller/XMLWriter.php
  3. +49 −0 core/src/core/src/pydio/Core/Exception/RepositoryLoadException.php
  4. +16 −2 core/src/core/src/pydio/Core/Http/Cli/AuthCliMiddleware.php
  5. +23 −9 core/src/core/src/pydio/Core/Http/Middleware/AuthMiddleware.php
  6. +14 −8 core/src/core/src/pydio/Core/Http/Rest/RestAuthMiddleware.php
  7. +1 −1 core/src/core/src/pydio/Core/Http/SimpleRestResourceRouter.php
  8. +59 −3 core/src/core/src/pydio/Core/Model/Context.php
  9. +18 −0 core/src/core/src/pydio/Core/Model/ContextInterface.php
  10. +5 −4 core/src/core/src/pydio/Core/Model/RepositoryInterface.php
  11. +12 −1 core/src/core/src/pydio/Core/Model/UserInterface.php
  12. +33 −0 core/src/core/src/pydio/Core/PluginFramework/CoreInstanceProvider.php
  13. +40 −17 core/src/core/src/pydio/Core/PluginFramework/Plugin.php
  14. +476 −135 core/src/core/src/pydio/Core/PluginFramework/PluginsService.php
  15. +21 −12 core/src/core/src/pydio/Core/Services/AuthService.php
  16. +59 −290 core/src/core/src/pydio/Core/Services/ConfService.php
  17. +5 −2 core/src/core/src/sabredav/ajaxplorer/class.AJXP_Sabre_Node.php
  18. +90 −56 core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php
  19. +12 −4 core/src/plugins/access.ajxp_home/class.HomePagePlugin.php
  20. +19 −83 core/src/plugins/access.ajxp_user/class.UserDashboardDriver.php
  21. +9 −3 core/src/plugins/access.dropbox/class.dropboxAccessDriver.php
  22. +2 −2 core/src/plugins/access.dropbox/class.dropboxWrapper.php
  23. +41 −36 core/src/plugins/access.fs/class.fsAccessDriver.php
  24. +27 −61 core/src/plugins/access.ftp/class.ftpAccessDriver.php
  25. +4 −2 core/src/plugins/access.ftp/class.ftpAccessWrapper.php
  26. +12 −5 core/src/plugins/access.imap/class.imapAccessDriver.php
  27. +8 −1 core/src/plugins/access.inbox/class.inboxAccessDriver.php
  28. +8 −0 core/src/plugins/access.jsapi/class.jsapiAccessDriver.php
  29. +7 −1 core/src/plugins/access.mysql/class.mysqlAccessDriver.php
  30. +19 −8 core/src/plugins/access.s3/class.s3AccessDriver.php
  31. +10 −6 core/src/plugins/access.sftp/class.sftpAccessDriver.php
  32. +7 −6 core/src/plugins/access.sftp_psl/class.sftpPSLAccessDriver.php
  33. +10 −5 core/src/plugins/access.smb/class.smbAccessDriver.php
  34. +17 −8 core/src/plugins/access.swift/class.swiftAccessDriver.php
  35. +13 −6 core/src/plugins/access.webdav/src/Driver.php
  36. +8 −0 core/src/plugins/access.wms/class.WmsBrowser.php
  37. +3 −2 core/src/plugins/action.antivirus/class.AntivirusScanner.php
  38. +3 −2 core/src/plugins/action.avatar/class.AvatarProvider.php
  39. +4 −4 core/src/plugins/action.compression/class.PluginCompression.php
  40. +7 −5 core/src/plugins/action.disclaimer/class.DisclaimerProvider.php
  41. +8 −4 core/src/plugins/action.powerfs/class.PowerFSController.php
  42. +20 −12 core/src/plugins/action.scheduler/class.AjxpScheduler.php
  43. +3 −1 core/src/plugins/action.share/src/Legacy/LegacyPubliclet.php
  44. +97 −77 core/src/plugins/action.share/src/ShareCenter.php
  45. +1 −1 core/src/plugins/action.share/src/Store/ShareRightsManager.php
  46. +5 −7 core/src/plugins/action.share/src/View/MinisiteRenderer.php
  47. +3 −3 core/src/plugins/action.skeleton/class.PluginSkeleton.php
  48. +6 −5 core/src/plugins/action.timestamp/class.TimestampCreator.php
  49. +16 −13 core/src/plugins/action.updater/class.UpdateController.php
  50. +7 −2 core/src/plugins/auth.custom_db/class.customDbAuthDriver.php
  51. +9 −3 core/src/plugins/auth.ftp/class.ftpAuthDriver.php
  52. +7 −2 core/src/plugins/auth.ldap/class.ldapAuthDriver.php
  53. +15 −31 core/src/plugins/auth.multi/class.multiAuthDriver.php
  54. +8 −2 core/src/plugins/auth.radius/class.radiusAuthDriver.php
  55. +7 −2 core/src/plugins/auth.remote/class.remoteAuthDriver.php
  56. +5 −0 core/src/plugins/auth.remote/glueCode.php
  57. +7 −2 core/src/plugins/auth.serial/class.serialAuthDriver.php
  58. +7 −2 core/src/plugins/auth.sql/class.sqlAuthDriver.php
  59. +14 −9 core/src/plugins/authfront.duosecurity/class.DuoSecurityFrontend.php
  60. +0 −4 core/src/plugins/authfront.keystore/class.KeystoreAuthFrontend.php
  61. +18 −4 core/src/plugins/authfront.multi/class.MultiAuthFrontend.php
  62. +1 −2 core/src/plugins/authfront.multi/manifest.xml
  63. +3 −6 core/src/plugins/authfront.session_login/class.SessionLoginFrontend.php
  64. +7 −2 core/src/plugins/boot.conf/class.BootConfLoader.php
  65. +5 −6 core/src/plugins/cache.doctrine/class.DoctrineCacheDriver.php
  66. +7 −2 core/src/plugins/conf.serial/class.serialConfDriver.php
  67. +6 −2 core/src/plugins/conf.sql/class.sqlConfDriver.php
  68. +72 −33 core/src/plugins/core.access/src/AbstractAccessDriver.php
  69. +3 −1 core/src/plugins/core.access/src/IAjxpWrapperProvider.php
  70. +17 −1 core/src/plugins/core.access/src/Model/AJXP_Node.php
  71. +6 −10 core/src/plugins/core.access/src/Model/Repository.php
  72. +57 −17 core/src/plugins/core.access/src/Model/UserSelection.php
  73. +17 −9 core/src/plugins/core.auth/class.AbstractAuthDriver.php
  74. +18 −9 core/src/plugins/core.auth/class.CoreAuthLoader.php
  75. +10 −4 core/src/plugins/core.authfront/class.FrontendsLoader.php
  76. +2 −6 core/src/plugins/core.cache/class.AbstractCacheDriver.php
  77. +11 −7 core/src/plugins/core.cache/class.CoreCacheLoader.php
  78. +2 −1 core/src/plugins/core.conf/class.AJXP_Role.php
  79. +18 −1 core/src/plugins/core.conf/class.AbstractAjxpUser.php
  80. +104 −95 core/src/plugins/core.conf/class.AbstractConfDriver.php
  81. +8 −5 core/src/plugins/core.conf/class.CoreConfLoader.php
  82. +7 −6 core/src/plugins/core.index/class.AbstractSearchEngineIndexer.php
  83. +16 −14 core/src/plugins/core.index/class.CoreIndexer.php
  84. +14 −7 core/src/plugins/core.log/class.AJXP_Logger.php
  85. +10 −4 core/src/plugins/core.mailer/class.AjxpMailer.php
  86. +4 −2 core/src/plugins/core.meta/class.AJXP_AbstractMetaSource.php
  87. +10 −2 core/src/plugins/core.metastore/interface.MetaStoreProvider.php
  88. +51 −24 core/src/plugins/core.mq/class.MqManager.php
  89. +1 −1 core/src/plugins/core.mq/manifest.xml
  90. +40 −20 core/src/plugins/core.notifications/class.AJXP_NotificationCenter.php
  91. +4 −1 core/src/plugins/core.notifications/interface.AJXP_FeedStore.php
  92. +16 −10 core/src/plugins/core.notifications/interface.AJXP_MessageExchanger.php
  93. +7 −2 core/src/plugins/core.ocs/src/OCSPlugin.php
  94. +6 −4 core/src/plugins/core.tasks/src/ITasksProvider.php
  95. +29 −10 core/src/plugins/core.tasks/src/TaskController.php
  96. +5 −5 core/src/plugins/core.tasks/src/TaskService.php
  97. +20 −16 core/src/plugins/cypher.encfs/class.EncfsMounter.php
  98. +11 −5 core/src/plugins/editor.audio/class.AudioPreviewer.php
  99. +2 −2 core/src/plugins/editor.browser/class.FileMimeSender.php
  100. +9 −8 core/src/plugins/editor.diaporama/class.ImagePreviewer.php
  101. +9 −6 core/src/plugins/editor.eml/class.EmlParser.php
  102. +7 −6 core/src/plugins/editor.etherpad/class.EtherpadClient.php
  103. +10 −10 core/src/plugins/editor.imagick/class.IMagickPreviewer.php
  104. +5 −5 core/src/plugins/editor.pixlr/class.PixlrEditor.php
  105. +2 −3 core/src/plugins/editor.video/class.VideoReader.php
  106. +29 −19 core/src/plugins/editor.zoho/class.ZohoEditor.php
  107. +13 −6 core/src/plugins/feed.sql/class.AJXP_SqlFeedStore.php
  108. +28 −18 core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php
  109. +3 −1 core/src/plugins/gui.mobile/class.MobileGuiPlugin.php
  110. +3 −2 core/src/plugins/gui.user/class.UserGuiController.php
  111. +28 −16 core/src/plugins/index.elasticsearch/class.AjxpElasticSearch.php
  112. +39 −20 core/src/plugins/index.lucene/class.AjxpLuceneIndexer.php
  113. +7 −6 core/src/plugins/log.sql/class.sqlLogDriver.php
  114. +6 −5 core/src/plugins/log.syslog/class.sysLogDriver.php
  115. +5 −5 core/src/plugins/log.text/class.textLogDriver.php
  116. +25 −15 core/src/plugins/meta.comments/class.CommentsMetaManager.php
  117. +16 −5 core/src/plugins/meta.exif/class.ExifMetaManager.php
  118. +16 −8 core/src/plugins/meta.filehasher/class.FileHasher.php
  119. +4 −3 core/src/plugins/meta.git/class.GitManager.php
  120. +4 −2 core/src/plugins/meta.monitor_fs/class.FSMonitoringManager.php
  121. +7 −9 core/src/plugins/meta.mount/class.FilesystemMounter.php
  122. +18 −8 core/src/plugins/meta.simple_lock/class.SimpleLockManager.php
  123. +14 −4 core/src/plugins/meta.svn/class.SvnManager.php
  124. +18 −12 core/src/plugins/meta.syncable/class.ChangesTracker.php
  125. +40 −23 core/src/plugins/meta.user/class.UserMetaManager.php
  126. +17 −7 core/src/plugins/meta.watch/class.MetaWatchRegister.php
  127. +9 −16 core/src/plugins/metastore.s3/class.s3MetaStore.php
  128. +5 −3 core/src/plugins/metastore.serial/class.SerialMetaStore.php
  129. +30 −23 core/src/plugins/mq.serial/class.AJXP_SerialMessageExchanger.php
  130. +30 −25 core/src/plugins/mq.sql/class.AJXP_SqlMessageExchanger.php
  131. +8 −3 core/src/plugins/uploader.flex/class.FlexUploadProcessor.php
  132. +2 −3 core/src/plugins/uploader.html/class.SimpleUploadProcessor.php
  133. +1 −2 core/src/plugins/uploader.http/class.HttpDownloader.php
  134. +11 −6 core/src/plugins/uploader.jumploader/class.JumploaderProcessor.php
  135. +3 −3 core/src/plugins/uploader.plupload/class.PluploadProcessor.php
  136. +8 −11 core/src/worker.php
@@ -26,6 +26,8 @@
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Exception\PydioException;
use Pydio\Auth\Core\AJXP_Safe;
+use Pydio\Core\Model\Context;
+use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
@@ -35,6 +37,7 @@
use Pydio\Tasks\Task;
use Pydio\Tasks\TaskService;
use Zend\Diactoros\Response;
+use Zend\Diactoros\ServerRequestFactory;
defined('AJXP_EXEC') or die( 'Access not allowed');
/**
@@ -69,7 +72,8 @@ class Controller
private static function initXPath($useCache = false)
{
if (!isSet(self::$xPath)) {
- $registry = ConfService::getFilteredXMLRegistry(false, false, $useCache);
+ $ctx = Context::fromGlobalServices();
+ $registry = PluginsService::getInstance($ctx)->getFilteredXMLRegistry(false, false, $useCache);
self::$xPath = new \DOMXPath($registry);
}
return self::$xPath;
@@ -245,11 +249,31 @@ public static function run(ServerRequestInterface $request, &$actionNode = null)
return $response;
}
+ /**
+ * @param Task $task
+ */
public static function applyTaskInBackground(Task $task){
+
$parameters = $task->getParameters();
$task->setStatus(Task::STATUS_RUNNING);
TaskService::getInstance()->updateTask($task);
self::applyActionInBackground($task->getWsId(), $task->getAction(), $parameters, $task->getUserId(), "", $task->getId());
+
+ }
+
+ /**
+ * @param ContextInterface $context
+ * @param string $action
+ * @param array $parameters
+ * @return ServerRequestInterface
+ */
+ public static function executableRequest(ContextInterface $context, $action, $parameters = []){
+ $request = ServerRequestFactory::fromGlobals();
+ $request = $request
+ ->withAttribute("ctx", $context)
+ ->withAttribute("action", $action)
+ ->withParsedBody($parameters);
+ return $request;
}
/**
@@ -265,24 +289,6 @@ public static function applyTaskInBackground(Task $task){
*/
public static function applyActionInBackground($currentRepositoryId, $actionName, $parameters, $user ="", $statusFile = "", $taskId = null)
{
-/*
- if (empty($user)) {
- if(AuthService::usersEnabled() && AuthService::getLoggedUser() !== null) $user = AuthService::getLoggedUser()->getId();
- else $user = "shared";
- }
- $fName = AJXP_DATA_PATH."/plugins/mq.serial/worker-queue";
- $fData = file_get_contents($fName);
- $data = json_decode($fData, true);
- $data[] = array(
- "userId" => $user,
- "repoId" => $currentRepositoryId,
- "actionName" => $actionName,
- "parameters" => $parameters
- );
- file_put_contents($fName, json_encode($data));
- return ;
-*/
-
$token = md5(time());
$logDir = AJXP_CACHE_DIR."/cmd_outputs";
@@ -295,22 +301,7 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
$user = "shared";
}
}
-/*
- require_once(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/core.mq/vendor/autoload.php");
- $nsq = new nsqphp\nsqphp;
- $nsq->publishTo("localhost", 1);
- $payload = array(
- 'msg' => 'bg',
- 'data' => [
- 'repository_id' => $currentRepositoryId,
- 'user_id' => $user,
- 'action' => $actionName,
- 'parameters' => $parameters
- ]);
- $nsq->publish('pydio', new nsqphp\Message\Message(json_encode($payload)));
-
- return;
-*/
+
if (Services\AuthService::usersEnabled()) {
$cKey = ConfService::getCoreConf("AJXP_CLI_SECRET_KEY", "conf");
if(empty($cKey)){
@@ -343,10 +334,7 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
}
}
- $repoObject = ConfService::getRepository();
- if(empty($repoObject)){
- $repoObject = ConfService::getRepositoryById($currentRepositoryId);
- }
+ $repoObject = ConfService::getRepositoryById($currentRepositoryId);
$clearEnv = false;
if($repoObject->getOption("USE_SESSION_CREDENTIALS")){
$encodedCreds = AJXP_Safe::getEncodedCredentialString();
@@ -504,7 +492,7 @@ private static function handleRequest($callback, ServerRequestInterface &$reques
}else{
$httpVars = $request->getParsedBody();
- $result = $plugInstance->$methodName($request->getAttribute("action"), $httpVars, $_FILES);
+ $result = $plugInstance->$methodName($request->getAttribute("action"), $httpVars, $_FILES, $request->getAttribute("ctx"));
// May have been modified
$request = $request->withParsedBody($httpVars);
@@ -22,6 +22,7 @@
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\IAjxpWrapperProvider;
+use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Utils\Utils;
use Pydio\Core\Services;
use Pydio\Core\Services\AuthService;
@@ -420,15 +421,16 @@ public static function triggerBgJSAction($jsCode, $messageId, $print=true, $dela
* List all bookmmarks as XML
* @static
* @param $allBookmarks
+ * @param RepositoryInterface $repository
* @param bool $print
* @param string $format legacy|node_list
* @return string
*/
- public static function writeBookmarks($allBookmarks, $print = true, $format = "legacy")
+ public static function writeBookmarks($allBookmarks, $repository, $print = true, $format = "legacy")
{
$driver = false;
if ($format == "node_list") {
- $driver = ConfService::loadRepositoryDriver();
+ $driver = $repository->getDriverInstance();
if (!($driver instanceof IAjxpWrapperProvider)) {
$driver = false;
}
@@ -0,0 +1,49 @@
+<?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;
+
+use Pydio\Core\Model\RepositoryInterface;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+
+class RepositoryLoadException extends PydioException
+{
+ /**
+ * @var RepositoryInterface
+ */
+ private $repository;
+ /**
+ * RepositoryLoadException constructor.
+ * @param RepositoryInterface $repository
+ * @param array $errors
+ */
+ public function __construct($repository, $errors)
+ {
+ $message = "Error while loading workspace ".$repository->getDisplay()." : ".implode("\n-", $errors);
+ $this->repository = $repository;
+ parent::__construct($message, false, 5000);
+ }
+
+ public function getRepository(){
+ return $this->repository;
+ }
+}
@@ -23,8 +23,11 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Auth\Core\AJXP_Safe;
+use Pydio\Core\Controller\Controller;
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Http\Server;
+use Pydio\Core\Model\Context;
+use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
use Zend\Diactoros\Response;
@@ -43,6 +46,8 @@ class AuthCliMiddleware
*/
public static function handleRequest(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface, callable $next = null){
+ $driverImpl = ConfService::getAuthDriverImpl();
+ PluginsService::getInstance()->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);
$options = $requestInterface->getAttribute("cli-options");
$optUser = $options["u"];
@@ -156,8 +161,12 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
$loggedUser = AuthService::getLoggedUser();
if($loggedUser == null) continue;
ConfService::switchRootDir($optRepoId, true);
- ConfService::reloadServicesAndActivePlugins();
+ Controller::registryReset();
$subResponse = new Response();
+ $ctx = new Context();
+ $ctx->setUserObject($loggedUser);
+ $ctx->setRepositoryId($optRepoId);
+ $requestInterface = $requestInterface->withAttribute("ctx", $ctx);
$subResponse = Server::callNextMiddleWareAndRewind(function($middleware){
return (is_array($middleware) && $middleware["0"] == "Pydio\\Core\\Http\\Cli\\AuthCliMiddleware" && $middleware[1] == "handleRequest");
@@ -179,7 +188,12 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
}else{
ConfService::switchRootDir($optRepoId, true);
- ConfService::reloadServicesAndActivePlugins();
+
+ $ctx = new Context();
+ $ctx->setUserObject($loggedUser);
+ $ctx->setRepositoryId($optRepoId);
+ $requestInterface = $requestInterface->withAttribute("ctx", $ctx);
+
return Server::callNextMiddleWare($requestInterface, $responseInterface, $next);
}
@@ -26,7 +26,10 @@
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Exception\NoActiveWorkspaceException;
use Pydio\Core\Exception\PydioException;
+use Pydio\Core\Exception\RepositoryLoadException;
use Pydio\Core\Http\Server;
+use Pydio\Core\Model\Context;
+use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
use Zend\Diactoros\Response\EmptyResponse;
@@ -46,27 +49,33 @@ class AuthMiddleware
*/
public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface, callable $next = null){
- $response = FrontendsLoader::frontendsAsAuthMiddlewares($requestInterface, $responseInterface);
- if($response != null){
- return $response;
- }
-
- self::bootSessionServer($requestInterface);
try{
+ $driverImpl = ConfService::getAuthDriverImpl();
+ PluginsService::getInstance()->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);
- ConfService::reloadServicesAndActivePlugins();
+ $response = FrontendsLoader::frontendsAsAuthMiddlewares($requestInterface, $responseInterface);
+ if($response != null){
+ return $response;
+ }
+ self::bootSessionServer($requestInterface);
- }catch (NoActiveWorkspaceException $ex){
+ } catch (NoActiveWorkspaceException $ex){
$logged = AuthService::getLoggedUser();
if($logged !== null) $lock = $logged->getLock();
if(empty($lock)){
throw new AuthRequiredException();
}
+ } catch (RepositoryLoadException $r){
+
+ ConfService::switchBackAfterRepositoryError($r->getRepository());
+ throw $r;
+
}
+ $requestInterface = $requestInterface->withAttribute("ctx", Context::fromGlobalServices());
try{
return Server::callNextMiddleWare($requestInterface, $responseInterface, $next);
@@ -78,6 +87,11 @@ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$
}else{
return new EmptyResponse();
}
+ } catch (RepositoryLoadException $r){
+
+ ConfService::switchBackAfterRepositoryError($r->getRepository());
+ throw $r;
+
}
}
@@ -99,7 +113,7 @@ protected static function bootSessionServer(ServerRequestInterface $request){
if ($loggedUser != null) {
$res = ConfService::switchUserToActiveRepository($loggedUser, (isSet($parameters["tmp_repository_id"])?$parameters["tmp_repository_id"]:"-1"));
if (!$res) {
- AuthService::disconnect();
+ throw new NoActiveWorkspaceException();
}
}
}
@@ -24,6 +24,8 @@
use Pydio\Authfront\Core\FrontendsLoader;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Exception\WorkspaceNotFoundException;
+use Pydio\Core\Model\Context;
+use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService;
@@ -42,35 +44,39 @@ class RestAuthMiddleware
*/
public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface, callable $next = null){
+ $driverImpl = ConfService::getAuthDriverImpl();
+ PluginsService::getInstance()->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl);
+
$response = FrontendsLoader::frontendsAsAuthMiddlewares($requestInterface, $responseInterface);
if($response != null){
return $response;
}
if(AuthService::getLoggedUser() == null){
- header('HTTP/1.0 401 Unauthorized');
- echo 'You are not authorized to access this API.';
- exit;
+ $responseInterface = $responseInterface->withStatus(401);
+ $responseInterface->getBody()->write('You are not authorized to access this API.');
+ return $responseInterface;
}
$repoID = $requestInterface->getAttribute("repository_id");
if($repoID == 'pydio'){
ConfService::switchRootDir();
- ConfService::getRepository();
+ $repo = ConfService::getRepository();
}else{
$repo = ConfService::findRepositoryByIdOrAlias($repoID);
if ($repo == null) {
throw new WorkspaceNotFoundException($repoID);
}
if(!ConfService::repositoryIsAccessible($repo->getId(), $repo, AuthService::getLoggedUser(), false, true)){
- header('HTTP/1.0 401 Unauthorized');
- echo 'You are not authorized to access this workspace.';
- exit;
+ $responseInterface = $responseInterface->withStatus(401);
+ $responseInterface->getBody()->write('You are not authorized to access this API.');
+ return $responseInterface;
}
ConfService::switchRootDir($repo->getId());
}
- ConfService::reloadServicesAndActivePlugins();
+ $context = Context::contextWithObjects(AuthService::getLoggedUser(), $repo);
+ $requestInterface = $requestInterface->withAttribute("ctx", $context);
return RestServer::callNextMiddleWare($requestInterface, $responseInterface, $next);
@@ -185,7 +185,7 @@ protected function bodyHandler($callback, ServerRequestInterface &$request, Resp
*
* @param string|object $destination
* @param object $sourceObject
- * @return object
+ * @return mixed
*/
public static function cast($destination, $sourceObject)
{
Oops, something went wrong.

0 comments on commit 8212433

Please sign in to comment.