This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
546 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
<?php | |||
/* | |||
* Copyright 2007-2015 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 <http://pyd.io/>. | |||
*/ | |||
namespace Pydio\Core\Http\Message; | |||
|
|||
use Pydio\Core\Controller\XMLWriter; | |||
use Pydio\Core\Http\Response\JSONSerializableResponseChunk; | |||
use Pydio\Core\Http\Response\XMLSerializableResponseChunk; | |||
|
|||
defined('AJXP_EXEC') or die('Access not allowed'); | |||
|
|||
class Message implements XMLSerializableResponseChunk, JSONSerializableResponseChunk | |||
{ | |||
|
|||
private $message; | |||
|
|||
public function __construct($message) | |||
{ | |||
$this->message = $message; | |||
} | |||
|
|||
public function toXML() | |||
{ | |||
return XMLWriter::sendMessage($this->message, $this->message); | |||
} | |||
|
|||
public function jsonSerializableData() | |||
{ | |||
return $this->message; | |||
} | |||
|
|||
public function jsonSerializableKey() | |||
{ | |||
return 'message'; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
core/src/core/src/pydio/Core/Http/Wopi/RestWopiAuthMiddleware.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,107 @@ | |||
<?php | |||
/* | |||
* Copyright 2007-2015 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 <http://pyd.io/>. | |||
*/ | |||
namespace Pydio\Core\Http\Wopi; | |||
|
|||
use Psr\Http\Message\ResponseInterface; | |||
use Psr\Http\Message\ServerRequestInterface; | |||
use Pydio\Auth\Frontend\Core\FrontendsLoader; | |||
use Pydio\Core\Exception\NoActiveWorkspaceException; | |||
use Pydio\Core\Exception\PydioException; | |||
use Pydio\Core\Exception\WorkspaceForbiddenException; | |||
|
|||
use Pydio\Core\Http\Server; | |||
use Pydio\Core\Model\Context; | |||
use Pydio\Core\Model\ContextInterface; | |||
use Pydio\Core\PluginFramework\PluginsService; | |||
use Pydio\Core\Services\ConfService; | |||
|
|||
use Pydio\Core\Services\RolesService; | |||
use Pydio\Core\Services\UsersService; | |||
use Pydio\Core\Utils\ApplicationState; | |||
use Pydio\Log\Core\Logger; | |||
|
|||
defined('AJXP_EXEC') or die('Access not allowed'); | |||
|
|||
|
|||
/** | |||
* Authentication middleware used in Rest context | |||
* @package Pydio\Core\Http\Rest | |||
*/ | |||
class RestWopiAuthMiddleware | |||
{ | |||
|
|||
/** | |||
* @param ServerRequestInterface $requestInterface | |||
* @param \Psr\Http\Message\ResponseInterface $responseInterface | |||
* @return \Psr\Http\Message\ResponseInterface | |||
* @param callable|null $next | |||
* @throws PydioException | |||
*/ | |||
public static function handleRequest(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface, callable $next = null){ | |||
|
|||
$driverImpl = ConfService::getAuthDriverImpl(); | |||
PluginsService::getInstance(Context::emptyContext())->setPluginUniqueActiveForType("auth", $driverImpl->getName(), $driverImpl); | |||
|
|||
$response = FrontendsLoader::frontendsAsAuthMiddlewares($requestInterface, $responseInterface); | |||
if($response != null){ | |||
return $response; | |||
} | |||
/** @var ContextInterface $ctx */ | |||
$ctx = $requestInterface->getAttribute("ctx"); | |||
|
|||
if(!$ctx->hasUser()){ | |||
$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'){ | |||
$userRepositories = UsersService::getRepositoriesForUser($ctx->getUser()); | |||
if(empty($userRepositories)){ | |||
throw new NoActiveWorkspaceException(); | |||
} | |||
$repo = array_shift($userRepositories); | |||
}else{ | |||
try{ | |||
$repo = UsersService::getRepositoryWithPermission($ctx->getUser(), $repoID); | |||
}catch (WorkspaceForbiddenException $w){ | |||
$responseInterface = $responseInterface->withStatus(401); | |||
$responseInterface->getBody()->write('You are not authorized to access this API.'); | |||
return $responseInterface; | |||
} | |||
} | |||
|
|||
$ctx->setRepositoryObject($repo); | |||
$requestInterface = $requestInterface->withAttribute("ctx", $ctx); | |||
|
|||
Logger::updateContext($ctx); | |||
|
|||
if(UsersService::usersEnabled() && ApplicationState::detectApplicationFirstRun()){ | |||
RolesService::bootSequence(); | |||
} | |||
|
|||
return Server::callNextMiddleWare($requestInterface, $responseInterface, $next); | |||
|
|||
} | |||
|
|||
|
|||
} |
48 changes: 48 additions & 0 deletions
48
core/src/core/src/pydio/Core/Http/Wopi/RestWopiMiddleware.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
<?php | |||
/* | |||
* Copyright 2007-2015 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 <http://pyd.io/>. | |||
*/ | |||
namespace Pydio\Core\Http\Wopi; | |||
|
|||
use \Psr\Http\Message\ServerRequestInterface; | |||
use \Psr\Http\Message\ResponseInterface; | |||
use Pydio\Core\Exception\PydioException; | |||
use Pydio\Core\Http\Wopi\WopiMiddleware; | |||
|
|||
defined('AJXP_EXEC') or die('Access not allowed'); | |||
|
|||
|
|||
class RestWopiMiddleware extends WopiMiddleware | |||
{ | |||
protected $base; | |||
|
|||
public function __construct($base) | |||
{ | |||
$this->base = $base; | |||
} | |||
|
|||
protected function parseRequestRouteAndParams(ServerRequestInterface &$request, ResponseInterface &$response){ | |||
|
|||
$router = new WopiRouter($this->base); | |||
if(!$router->route($request, $response)){ | |||
throw new PydioException("Could not find any endpoint for this URI"); | |||
} | |||
} | |||
|
|||
} |
Oops, something went wrong.