1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acquia\Hmac\Symfony; |
4
|
|
|
|
5
|
|
|
use Acquia\Hmac\ResponseSigner; |
6
|
|
|
use Nyholm\Psr7\Factory\Psr17Factory; |
7
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; |
|
|
|
|
8
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; |
|
|
|
|
9
|
|
|
use Symfony\Component\HttpKernel\Event\ResponseEvent; |
10
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
11
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Signs the response from an HTTP HMAC-authenticated request. |
15
|
|
|
*/ |
16
|
|
|
class HmacResponseListener implements EventSubscriberInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event |
20
|
3 |
|
*/ |
21
|
|
|
public function onKernelResponse(ResponseEvent $event) |
22
|
3 |
|
{ |
23
|
1 |
|
if (!$event->isMasterRequest()) { |
24
|
|
|
return; |
25
|
|
|
} |
26
|
2 |
|
|
27
|
2 |
|
$request = $event->getRequest(); |
28
|
|
|
$response = $event->getResponse(); |
29
|
2 |
|
|
30
|
1 |
|
if ($request->attributes->has('hmac.key')) { |
31
|
1 |
|
$psr17Factory = new Psr17Factory(); |
32
|
|
|
$httpMessageFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); |
33
|
1 |
|
$foundationFactory = new HttpFoundationFactory(); |
34
|
1 |
|
|
35
|
|
|
$psr7Request = $httpMessageFactory->createRequest($request); |
36
|
1 |
|
$psr7Response = $httpMessageFactory->createResponse($response); |
37
|
1 |
|
|
38
|
|
|
$signer = new ResponseSigner($request->attributes->get('hmac.key'), $psr7Request); |
39
|
1 |
|
$signedResponse = $signer->signResponse($psr7Response); |
40
|
|
|
|
41
|
2 |
|
$event->setResponse($foundationFactory->createResponse($signedResponse)); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
1 |
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
1 |
|
public static function getSubscribedEvents() |
49
|
|
|
{ |
50
|
|
|
return [KernelEvents::RESPONSE => 'onKernelResponse']; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths