1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LightSAML-IDP package. |
5
|
|
|
* |
6
|
|
|
* (c) Milos Tomic <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the GPL-3 license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LightSaml\Idp\Action\Assertion\Outbound; |
13
|
|
|
|
14
|
|
|
use LightSaml\Action\Assertion\AbstractAssertionAction; |
15
|
|
|
use LightSaml\Context\Profile\AssertionContext; |
16
|
|
|
use LightSaml\Provider\TimeProvider\TimeProviderInterface; |
17
|
|
|
use LightSaml\Model\Assertion\Subject; |
18
|
|
|
use LightSaml\Model\Assertion\SubjectConfirmation; |
19
|
|
|
use LightSaml\Model\Assertion\SubjectConfirmationData; |
20
|
|
|
use LightSaml\SamlConstants; |
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Creates SubjectConfirmation and creates Subject if not already created. |
25
|
|
|
*/ |
26
|
|
|
class SubjectConfirmationAction extends AbstractAssertionAction |
27
|
|
|
{ |
28
|
|
|
/** @var TimeProviderInterface */ |
29
|
|
|
protected $timeProvider; |
30
|
|
|
|
31
|
|
|
/** @var int */ |
32
|
|
|
protected $expirationSeconds; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param LoggerInterface $logger |
36
|
|
|
* @param TimeProviderInterface $timeProvider |
37
|
|
|
* @param int $expirationSeconds |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
LoggerInterface $logger, |
41
|
|
|
TimeProviderInterface $timeProvider, |
42
|
|
|
$expirationSeconds |
43
|
|
|
) { |
44
|
|
|
parent::__construct($logger); |
45
|
|
|
|
46
|
|
|
$this->expirationSeconds = $expirationSeconds; |
47
|
|
|
$this->timeProvider = $timeProvider; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param AssertionContext $context |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
protected function doExecute(AssertionContext $context) |
56
|
|
|
{ |
57
|
|
|
$profileContext = $context->getProfileContext(); |
58
|
|
|
$inboundMessage = $profileContext->getInboundContext()->getMessage(); |
59
|
|
|
$endpoint = $profileContext->getEndpoint(); |
60
|
|
|
|
61
|
|
|
$data = new SubjectConfirmationData(); |
62
|
|
|
if ($inboundMessage) { |
63
|
|
|
$data->setInResponseTo($inboundMessage->getID()); |
64
|
|
|
} |
65
|
|
|
$data->setAddress($profileContext->getHttpRequest()->getClientIp()); |
66
|
|
|
$data->setNotOnOrAfter($this->timeProvider->getTimestamp() + $this->expirationSeconds); |
67
|
|
|
$data->setRecipient($endpoint->getLocation()); |
68
|
|
|
|
69
|
|
|
$subjectConfirmation = new SubjectConfirmation(); |
70
|
|
|
$subjectConfirmation->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER); |
71
|
|
|
$subjectConfirmation->setSubjectConfirmationData($data); |
72
|
|
|
|
73
|
|
|
if (null === $context->getAssertion()->getSubject()) { |
74
|
|
|
$context->getAssertion()->setSubject(new Subject()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$context->getAssertion()->getSubject()->addSubjectConfirmation($subjectConfirmation); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|