mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 20:13:28 +00:00

Conflicts: composer.lock lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Command/Setup/H264MappingGenerator.php lib/Alchemy/Phrasea/Controller/AbstractDelivery.php lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php lib/Alchemy/Phrasea/Controller/Prod/Edit.php lib/Alchemy/Phrasea/Controller/Prod/Story.php lib/Alchemy/Phrasea/Controller/Prod/Upload.php lib/Alchemy/Phrasea/Controller/Report/Activity.php lib/Alchemy/Phrasea/Controller/Report/Root.php lib/Alchemy/Phrasea/Controller/Root/Account.php lib/Alchemy/Phrasea/Core/PhraseaEvents.php lib/Alchemy/Phrasea/Core/Version.php lib/classes/API/V1/adapter.php lib/classes/User/Adapter.php lib/classes/databox.php lib/classes/media/subdef.php lib/classes/module/report.php lib/classes/module/report/activity.php lib/classes/module/report/connexion.php lib/classes/module/report/download.php lib/classes/module/report/nav.php lib/classes/module/report/question.php lib/classes/module/report/sqlaction.php lib/classes/module/report/sqlconnexion.php lib/classes/module/report/sqldownload.php lib/classes/module/report/sqlfilter.php lib/classes/task/abstract.php locale/de_DE/LC_MESSAGES/phraseanet.mo locale/de_DE/LC_MESSAGES/phraseanet.po locale/en_GB/LC_MESSAGES/phraseanet.mo locale/en_GB/LC_MESSAGES/phraseanet.po locale/fr_FR/LC_MESSAGES/phraseanet.mo locale/fr_FR/LC_MESSAGES/phraseanet.po locale/nl_NL/LC_MESSAGES/phraseanet.mo locale/nl_NL/LC_MESSAGES/phraseanet.po locale/phraseanet.pot templates/web/prod/index.html.twig tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php tests/classes/api/v1/api_v1_adapterTest.php tests/classes/report/activityTest.php tests/classes/report/editTest.php
156 lines
4.4 KiB
PHP
156 lines
4.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2014 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Security;
|
|
|
|
use Silex\Application;
|
|
use Silex\Controller;
|
|
use Silex\ControllerCollection;
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class Firewall
|
|
{
|
|
private $app;
|
|
|
|
public function __construct(Application $app)
|
|
{
|
|
$this->app = $app;
|
|
}
|
|
|
|
public function requireSetUp()
|
|
{
|
|
if (!$this->app['phraseanet.configuration-tester']->isInstalled()) {
|
|
$this->app->abort(302, 'Phraseanet is not installed', [
|
|
'X-Phraseanet-Redirect' => $this->app->path('setup')
|
|
]);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function requireAdmin()
|
|
{
|
|
$this->requireNotGuest();
|
|
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->is_admin()) {
|
|
$this->app->abort(403, 'Admin role is required');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireAccessToModule($module)
|
|
{
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->has_access_to_module($module)) {
|
|
$this->app->abort(403, 'You do not have required rights');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireAccessToSbas($sbas_id)
|
|
{
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->has_access_to_sbas($sbas_id)) {
|
|
$this->app->abort(403, 'You do not have required rights');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireAccessToBase($base_id)
|
|
{
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->has_access_to_base($base_id)) {
|
|
$this->app->abort(403, 'You do not have required rights');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireRight($right)
|
|
{
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->has_right($right)) {
|
|
$this->app->abort(403, 'You do not have required rights');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireRightOnBase($base_id, $right)
|
|
{
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($base_id, $right)) {
|
|
$this->app->abort(403, 'You do not have required rights');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireRightOnSbas($sbas_id, $right)
|
|
{
|
|
if (!$this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_sbas($sbas_id, $right)) {
|
|
$this->app->abort(403, 'You do not have required rights');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireNotGuest()
|
|
{
|
|
if ($this->app['authentication']->getUser()->isGuest()) {
|
|
$this->app->abort(403, 'Guests do not have admin role');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function requireAuthentication(Request $request = null)
|
|
{
|
|
$params = [];
|
|
if (null !== $request) {
|
|
$params['redirect'] = '..' . $request->getPathInfo().'?'.$request->getQueryString();
|
|
}
|
|
if (!$this->app['authentication']->isAuthenticated()) {
|
|
return new RedirectResponse($this->app->path('homepage', $params));
|
|
}
|
|
}
|
|
|
|
public function addMandatoryAuthentication($controllers)
|
|
{
|
|
if (!$controllers instanceof ControllerCollection && !$controllers instanceof Controller) {
|
|
throw new \InvalidArgumentException('Controllers must be either a Controller or a ControllerCollection.');
|
|
}
|
|
|
|
$app = $this->app;
|
|
|
|
$controllers->before(function (Request $request) use ($app) {
|
|
if (null !== $response = $app['firewall']->requireAuthentication($request)) {
|
|
return $response;
|
|
}
|
|
});
|
|
}
|
|
|
|
public function requireNotAuthenticated()
|
|
{
|
|
if ($this->app['authentication']->isAuthenticated()) {
|
|
return new RedirectResponse($this->app->path('prod'));
|
|
}
|
|
}
|
|
|
|
public function requireOrdersAdmin()
|
|
{
|
|
if (false === !!count($this->app['acl']->get($this->app['authentication']->getUser())->get_granted_base(['order_master']))) {
|
|
$this->app->abort(403, 'You are not an order admin');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|