SubjectConfirmationAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 9
dl 0
loc 54
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A doExecute() 0 24 3
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