|
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\Model\Assertion\AuthnContext; |
|
17
|
|
|
use LightSaml\Model\Assertion\AuthnStatement; |
|
18
|
|
|
use LightSaml\Model\Assertion\SubjectLocality; |
|
19
|
|
|
use LightSaml\Provider\Session\SessionInfoProviderInterface; |
|
20
|
|
|
use LightSaml\SamlConstants; |
|
21
|
|
|
use Psr\Log\LoggerInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Creates AuthnStatement and sets values provided by session info provider. |
|
25
|
|
|
*/ |
|
26
|
|
|
class AuthnStatementAction extends AbstractAssertionAction |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var SessionInfoProviderInterface */ |
|
29
|
|
|
protected $sessionInfoProvider; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param LoggerInterface $logger |
|
33
|
|
|
* @param SessionInfoProviderInterface $sessionInfoProvider |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(LoggerInterface $logger, SessionInfoProviderInterface $sessionInfoProvider) |
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct($logger); |
|
38
|
|
|
|
|
39
|
|
|
$this->sessionInfoProvider = $sessionInfoProvider; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param AssertionContext $context |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function doExecute(AssertionContext $context) |
|
48
|
|
|
{ |
|
49
|
|
|
$authnContext = new AuthnContext(); |
|
50
|
|
|
$authnContextClassRef = $this->sessionInfoProvider->getAuthnContextClassRef() ?: SamlConstants::AUTHN_CONTEXT_UNSPECIFIED; |
|
51
|
|
|
$authnContext->setAuthnContextClassRef($authnContextClassRef); |
|
52
|
|
|
|
|
53
|
|
|
$authnStatement = new AuthnStatement(); |
|
54
|
|
|
$authnStatement->setAuthnContext($authnContext); |
|
55
|
|
|
$sessionIndex = $this->sessionInfoProvider->getSessionIndex(); |
|
56
|
|
|
if ($sessionIndex) { |
|
57
|
|
|
$authnStatement->setSessionIndex($sessionIndex); |
|
58
|
|
|
} |
|
59
|
|
|
$authnInstant = $this->sessionInfoProvider->getAuthnInstant() ?: new \DateTime(); |
|
60
|
|
|
$authnStatement->setAuthnInstant($authnInstant); |
|
61
|
|
|
|
|
62
|
|
|
$subjectLocality = new SubjectLocality(); |
|
63
|
|
|
$subjectLocality->setAddress($context->getProfileContext()->getHttpRequest()->getClientIp()); |
|
64
|
|
|
$authnStatement->setSubjectLocality($subjectLocality); |
|
65
|
|
|
|
|
66
|
|
|
$context->getAssertion()->addItem($authnStatement); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|