看板初始化提交
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Middleware;
|
||||
|
||||
use Kanboard\Core\Controller\AccessForbiddenException;
|
||||
use Kanboard\Core\Controller\BaseMiddleware;
|
||||
|
||||
/**
|
||||
* Class ApplicationAuthorizationMiddleware
|
||||
*
|
||||
* @package Kanboard\Middleware
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ApplicationAuthorizationMiddleware extends BaseMiddleware
|
||||
{
|
||||
/**
|
||||
* Execute middleware
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (! $this->helper->user->hasAccess($this->router->getController(), $this->router->getAction())) {
|
||||
throw new AccessForbiddenException();
|
||||
}
|
||||
|
||||
$this->next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Middleware;
|
||||
|
||||
use Kanboard\Core\Controller\AccessForbiddenException;
|
||||
use Kanboard\Core\Controller\BaseMiddleware;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
/**
|
||||
* Class AuthenticationMiddleware
|
||||
*
|
||||
* @package Kanboard\Middleware
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class AuthenticationMiddleware extends BaseMiddleware
|
||||
{
|
||||
/**
|
||||
* Execute middleware
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (! $this->authenticationManager->checkCurrentSession()) {
|
||||
$this->response->redirect($this->helper->url->to('AuthController', 'login'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->isPublicAccess()) {
|
||||
$this->handleAuthentication();
|
||||
}
|
||||
|
||||
$this->next();
|
||||
}
|
||||
|
||||
protected function handleAuthentication()
|
||||
{
|
||||
if (! $this->userSession->isLogged() && ! $this->authenticationManager->preAuthentication()) {
|
||||
$this->nextMiddleware = null;
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
$this->response->text('Not Authorized', 401);
|
||||
} else {
|
||||
$redirectURI = $this->request->getUri();
|
||||
if ($this->request->isSafeRedirectUri($redirectURI)) {
|
||||
session_set('redirectAfterLogin', $redirectURI);
|
||||
}
|
||||
$this->response->redirect($this->helper->url->to('AuthController', 'login'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function isPublicAccess()
|
||||
{
|
||||
if ($this->applicationAuthorization->isAllowed($this->router->getController(), $this->router->getAction(), Role::APP_PUBLIC)) {
|
||||
$this->nextMiddleware = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Middleware;
|
||||
|
||||
use Kanboard\Core\Controller\BaseMiddleware;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Class BootstrapMiddleware
|
||||
*
|
||||
* @package Kanboard\Middleware
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class BootstrapMiddleware extends BaseMiddleware
|
||||
{
|
||||
/**
|
||||
* Execute middleware
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->sessionManager->open();
|
||||
$this->dispatcher->dispatch(new Event, 'app.bootstrap');
|
||||
$this->sendHeaders();
|
||||
$this->next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send HTTP headers
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function sendHeaders()
|
||||
{
|
||||
$this->response->withContentSecurityPolicy($this->container['cspRules']);
|
||||
$this->response->withSecurityHeaders();
|
||||
$this->response->withP3P();
|
||||
|
||||
if (ENABLE_XFRAME) {
|
||||
$this->response->withXframe();
|
||||
}
|
||||
|
||||
if (ENABLE_HSTS) {
|
||||
$this->response->withStrictTransportSecurity();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Middleware;
|
||||
|
||||
use Kanboard\Core\Controller\BaseMiddleware;
|
||||
|
||||
/**
|
||||
* Class PostAuthenticationMiddleware
|
||||
*
|
||||
* @package Kanboard\Middleware
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class PostAuthenticationMiddleware extends BaseMiddleware
|
||||
{
|
||||
/**
|
||||
* Execute middleware
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$controller = strtolower($this->router->getController());
|
||||
$action = strtolower($this->router->getAction());
|
||||
$ignore = ($controller === 'twofactorcontroller' && in_array($action, array('code', 'check'))) || ($controller === 'authcontroller' && $action === 'logout');
|
||||
|
||||
if ($ignore === false && $this->userSession->hasPostAuthentication() && ! $this->userSession->isPostAuthenticationValidated()) {
|
||||
$this->nextMiddleware = null;
|
||||
|
||||
if ($this->request->isAjax()) {
|
||||
$this->response->text('Not Authorized', 401);
|
||||
} else {
|
||||
$this->response->redirect($this->helper->url->to('TwoFactorController', 'code'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->next();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Middleware;
|
||||
|
||||
use Kanboard\Core\Controller\AccessForbiddenException;
|
||||
use Kanboard\Core\Controller\BaseMiddleware;
|
||||
|
||||
/**
|
||||
* Class ProjectAuthorizationMiddleware
|
||||
*
|
||||
* @package Kanboard\Middleware
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectAuthorizationMiddleware extends BaseMiddleware
|
||||
{
|
||||
/**
|
||||
* Execute middleware
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$project_id = $this->request->getIntegerParam('project_id');
|
||||
$task_id = $this->request->getIntegerParam('task_id');
|
||||
|
||||
if ($task_id > 0 && $project_id === 0) {
|
||||
$project_id = $this->taskFinderModel->getProjectId($task_id);
|
||||
}
|
||||
|
||||
if ($project_id > 0 && ! $this->helper->user->hasProjectAccess($this->router->getController(), $this->router->getAction(), $project_id)) {
|
||||
throw new AccessForbiddenException();
|
||||
}
|
||||
|
||||
$this->next();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user