1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace jschreuder\MiddleAuth\Basic; |
4
|
|
|
|
5
|
|
|
use jschreuder\MiddleAuth\AuthorizationHandlerInterface; |
6
|
|
|
use jschreuder\MiddleAuth\AuthorizationMiddlewareInterface; |
7
|
|
|
use jschreuder\MiddleAuth\AuthorizationRequestInterface; |
8
|
|
|
use jschreuder\MiddleAuth\AuthorizationResponseInterface; |
9
|
|
|
use jschreuder\MiddleAuth\Util\AuthLoggerInterface; |
10
|
|
|
use jschreuder\MiddleAuth\Util\NullAuthLogger; |
11
|
|
|
|
12
|
|
|
final class DenyAllMiddleware implements AuthorizationMiddlewareInterface |
13
|
|
|
{ |
14
|
|
|
private AuthLoggerInterface $logger; |
15
|
|
|
|
16
|
3 |
|
public function __construct( |
17
|
|
|
?AuthLoggerInterface $logger = null |
18
|
|
|
) |
19
|
|
|
{ |
20
|
3 |
|
$this->logger = $logger ?? new NullAuthLogger(); |
21
|
|
|
} |
22
|
|
|
|
23
|
2 |
|
public function process( |
24
|
|
|
AuthorizationRequestInterface $request, |
25
|
|
|
AuthorizationHandlerInterface $handler |
26
|
|
|
): AuthorizationResponseInterface |
27
|
|
|
{ |
28
|
2 |
|
$this->logger->info('DenyAllMiddleware rejecting request - no authorization rules matched', [ |
29
|
2 |
|
'subject_type' => $request->getSubject()->getType(), |
30
|
2 |
|
'subject_id' => $request->getSubject()->getId(), |
31
|
2 |
|
'resource_type' => $request->getResource()?->getType(), |
32
|
2 |
|
'resource_id' => $request->getResource()?->getId(), |
33
|
2 |
|
'action' => $request->getAction(), |
34
|
2 |
|
]); |
35
|
|
|
|
36
|
2 |
|
return new AuthorizationResponse(false, 'No authorization rule matched', self::class); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|