|
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\Context\Profile\Helper\LogHelper; |
|
17
|
|
|
use LightSaml\Resolver\Signature\SignatureResolverInterface; |
|
18
|
|
|
use Psr\Log\LoggerInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* If TrustOptions::getSignAssertions is true, sets. |
|
22
|
|
|
*/ |
|
23
|
|
|
class SignAssertionAction extends AbstractAssertionAction |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var SignatureResolverInterface */ |
|
26
|
|
|
protected $signatureResolver; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param LoggerInterface $logger |
|
30
|
|
|
* @param SignatureResolverInterface $signatureResolver |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(LoggerInterface $logger, SignatureResolverInterface $signatureResolver) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($logger); |
|
35
|
|
|
|
|
36
|
|
|
$this->signatureResolver = $signatureResolver; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param AssertionContext $context |
|
41
|
|
|
* |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function doExecute(AssertionContext $context) |
|
45
|
|
|
{ |
|
46
|
|
|
$profileContext = $context->getProfileContext(); |
|
47
|
|
|
$trustOptions = $profileContext->getTrustOptions(); |
|
48
|
|
|
|
|
49
|
|
|
if ($trustOptions->getSignAssertions()) { |
|
50
|
|
|
$signature = $this->signatureResolver->getSignature($profileContext); |
|
51
|
|
|
if ($signature) { |
|
52
|
|
|
$this->logger->debug( |
|
53
|
|
|
sprintf( |
|
54
|
|
|
'Signing assertion with fingerprint %s', |
|
55
|
|
|
$signature->getCertificate()->getFingerprint() |
|
56
|
|
|
), |
|
57
|
|
|
LogHelper::getActionContext($context, $this, array( |
|
58
|
|
|
'certificate' => $signature->getCertificate()->getInfo(), |
|
59
|
|
|
)) |
|
60
|
|
|
); |
|
61
|
|
|
$context->getAssertion()->setSignature($signature); |
|
62
|
|
|
} else { |
|
63
|
|
|
$this->logger->critical( |
|
64
|
|
|
'Unable to resolve assertion signature, though signing enabled', |
|
65
|
|
|
LogHelper::getActionErrorContext($context, $this) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} else { |
|
69
|
|
|
$this->logger->debug('Assertion signing disabled', LogHelper::getActionContext($context, $this)); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|