-
Notifications
You must be signed in to change notification settings - Fork 0
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
2 changed files
with
47 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* This file is part of the daikon-cqrs/security-interop project. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Daikon\Security\Middleware; | ||
|
||
use Daikon\Boot\Middleware\Action\DaikonRequest; | ||
use Daikon\Boot\Middleware\RoutingHandler; | ||
use Daikon\Security\Middleware\Action\SecureActionInterface; | ||
use Fig\Http\Message\StatusCodeInterface; | ||
use Middlewares\Utils\Factory; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
final class Authorizor implements MiddlewareInterface, StatusCodeInterface | ||
{ | ||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
$requestHandler = $request->getAttribute(RoutingHandler::REQUEST_HANDLER); | ||
|
||
if ($requestHandler instanceof SecureActionInterface) { | ||
if (!$requestHandler->isAuthorized(DaikonRequest::wrap($request))) { | ||
return Factory::createResponse(self::STATUS_FORBIDDEN); | ||
} | ||
} | ||
|
||
return $handler->handle($request); | ||
} | ||
} |