mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 06:23:18 +00:00
Update firewall
This commit is contained in:
@@ -3,54 +3,162 @@
|
|||||||
namespace Alchemy\Phrasea\Security;
|
namespace Alchemy\Phrasea\Security;
|
||||||
|
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
use \Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class Firewall
|
class Firewall
|
||||||
{
|
{
|
||||||
|
private $app;
|
||||||
|
|
||||||
public function requireSetUp(Application $app)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
if ( ! \setup::is_installed()) {
|
$this->app = $app;
|
||||||
|
|
||||||
return $app->redirect("/setup/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requireAdmin(Application $app)
|
public function requireSetUp()
|
||||||
{
|
{
|
||||||
if (null !== $response = $this->requireAuthentication($app)) {
|
if (!\setup::is_installed()) {
|
||||||
|
return $this->app->redirect("/setup/");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireAdmin()
|
||||||
|
{
|
||||||
|
$response = $this->requireNotGuest();
|
||||||
|
if ($response instanceof Response) {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $app['phraseanet.core']->getAuthenticatedUser()->is_admin()) {
|
if (!$this->app['phraseanet.user']->ACL()->is_admin()) {
|
||||||
$app->abort(403);
|
$this->app->abort(403, 'Admin role is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requireAuthentication(Application $app)
|
public function requireAccessToModule($module)
|
||||||
{
|
{
|
||||||
if (false === $app['phraseanet.core']->isAuthenticated()) {
|
$response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
return $app->redirect('/login/');
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($app['phraseanet.core']->getAuthenticatedUser()->is_guest()) {
|
if (!$this->app['phraseanet.user']->ACL()->has_access_to_module($module)) {
|
||||||
|
$this->app->abort(403, 'You do not have required rights');
|
||||||
return $app->redirect('/login/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
unset($response);
|
||||||
$session = $app['phraseanet.appbox']->get_session();
|
|
||||||
$session->open_phrasea_session();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
|
|
||||||
return $app->redirect('/login/logout/');
|
return $this;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requireOrdersAdmin(Application $app) {
|
public function requireAccessToSbas($sbas_id)
|
||||||
if ( false === ! ! count($app['phraseanet.core']->getAuthenticatedUser()->ACL()->get_granted_base(array('order_master')))) {
|
{
|
||||||
$app->abort(403);
|
$response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->app['phraseanet.user']->ACL()->has_access_to_sbas($sbas_id)) {
|
||||||
|
$this->app->abort(403, 'You do not have required rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($response);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireAccessToBase($base_id)
|
||||||
|
{
|
||||||
|
$response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->app['phraseanet.user']->ACL()->has_access_to_base($base_id)) {
|
||||||
|
$this->app->abort(403, 'You do not have required rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($response);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireRight($right)
|
||||||
|
{
|
||||||
|
$response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->app['phraseanet.user']->ACL()->has_right($right)) {
|
||||||
|
$this->app->abort(403, 'You do not have required rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($response);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireRightOnBase($base_id, $right)
|
||||||
|
{
|
||||||
|
$response = $response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->app['phraseanet.user']->ACL()->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)
|
||||||
|
{
|
||||||
|
$response = $response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->app['phraseanet.user']->ACL()->has_right_on_sbas($sbas_id, $right)) {
|
||||||
|
$this->app->abort(403, 'You do not have required rights');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireNotGuest()
|
||||||
|
{
|
||||||
|
$response = $response = $this->requireAuthentication();
|
||||||
|
if ($response instanceof Response) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->app['phraseanet.user']->is_guest()) {
|
||||||
|
$this->app->abort(403, 'Guests do not have admin role');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireAuthentication()
|
||||||
|
{
|
||||||
|
if (!$this->app->isAuthenticated()) {
|
||||||
|
return $this->app->redirect('/login/');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function requireOrdersAdmin()
|
||||||
|
{
|
||||||
|
if (false === !!count($this->app['phraseanet.user']->ACL()->get_granted_base(array('order_master')))) {
|
||||||
|
$this->app->abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user