|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Action\Profile\Inbound\StatusResponse; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Action\Profile\AbstractProfileAction; |
|
15
|
|
|
use LightSaml\Context\Profile\Helper\LogHelper; |
|
16
|
|
|
use LightSaml\Context\Profile\Helper\MessageContextHelper; |
|
17
|
|
|
use LightSaml\Context\Profile\ProfileContext; |
|
18
|
|
|
use LightSaml\Context\Profile\ProfileContexts; |
|
19
|
|
|
use LightSaml\Context\Profile\RequestStateContext; |
|
20
|
|
|
use LightSaml\Error\LightSamlContextException; |
|
21
|
|
|
use LightSaml\State\Request\RequestStateParameters; |
|
22
|
|
|
use LightSaml\Store\Request\RequestStateStoreInterface; |
|
23
|
|
|
use Psr\Log\LoggerInterface; |
|
24
|
|
|
|
|
25
|
|
|
class InResponseToValidatorAction extends AbstractProfileAction |
|
26
|
|
|
{ |
|
27
|
|
|
/** @var RequestStateStoreInterface */ |
|
28
|
|
|
protected $requestStore; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(LoggerInterface $logger, RequestStateStoreInterface $requestStore) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct($logger); |
|
33
|
|
|
|
|
34
|
|
|
$this->requestStore = $requestStore; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function doExecute(ProfileContext $context) |
|
38
|
|
|
{ |
|
39
|
|
|
$response = MessageContextHelper::asStatusResponse($context->getInboundContext()); |
|
40
|
|
|
$inResponseTo = $response->getInResponseTo(); |
|
41
|
|
|
if ($inResponseTo) { |
|
42
|
|
|
$requestState = $this->requestStore->get($inResponseTo); |
|
43
|
|
|
if (null == $requestState) { |
|
44
|
|
|
$message = sprintf("Unknown InResponseTo '%s'", $inResponseTo); |
|
45
|
|
|
$this->logger->critical($message, LogHelper::getActionErrorContext($context, $this, [ |
|
46
|
|
|
'in_response_to' => $inResponseTo, |
|
47
|
|
|
])); |
|
48
|
|
|
throw new LightSamlContextException($context, $message); |
|
49
|
|
|
} |
|
50
|
|
|
$sentToParty = $requestState->getParameters()->get(RequestStateParameters::PARTY); |
|
51
|
|
|
if ($sentToParty && $response->getIssuer() && $response->getIssuer()->getValue() != $sentToParty) { |
|
52
|
|
|
$message = sprintf('AuthnRequest with id "%s" sent to party "%s" but StatusResponse for that request issued by party "%s"', $inResponseTo, $sentToParty, $response->getIssuer()->getValue()); |
|
53
|
|
|
$this->logger->critical($message, LogHelper::getActionErrorContext($context, $this, [ |
|
54
|
|
|
'sent_to' => $sentToParty, |
|
55
|
|
|
'received_from' => $response->getIssuer()->getValue(), |
|
56
|
|
|
])); |
|
57
|
|
|
throw new LightSamlContextException($context, $message); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** @var RequestStateContext $requestStateContext */ |
|
61
|
|
|
$requestStateContext = $context->getInboundContext()->getSubContext(ProfileContexts::REQUEST_STATE, RequestStateContext::class); |
|
62
|
|
|
$requestStateContext->setRequestState($requestState); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|