ResponseHelper::retrieveAdfsParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupGateway\SecondFactorOnlyBundle\Adfs;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\StepupGateway\SecondFactorOnlyBundle\Adfs\ValueObject\Response as AdfsResponse;
23
24
/**
25
 * The Adfs helper service is used to transform Adfs response. Wrapping the SFO response in an ADFS friendly response
26
 * format:
27
 *
28
 * AuthMethod: <AuthMethod>
29
 * Context: <Conext>
30
 * RequestId: <RequestId>
31
 * Response: <The "Response" that was received from the SFO endpoint>
32
 */
33
final class ResponseHelper
34
{
35
36
    /** @var LoggerInterface */
37
    private $logger;
38
39
    /** @var StateHandler */
40
    private $stateHandler;
41
42
    /**
43
     * ResponseHelper constructor.
44
     * @param StateHandler $stateHandler
45
     * @param LoggerInterface $logger
46
     */
47
    public function __construct(StateHandler $stateHandler, LoggerInterface $logger)
48
    {
49
        $this->stateHandler = $stateHandler;
50
        $this->logger = $logger;
51
    }
52
53
    /**
54
     * @param string $originalRequestId
55
     * @return bool
56
     */
57
    public function isAdfsResponse($originalRequestId)
58
    {
59
        return $this->stateHandler->hasMatchingRequestId($originalRequestId);
60
    }
61
62
    /**
63
     * @return AdfsResponse
64
     */
65
    public function retrieveAdfsParameters()
66
    {
67
        $authMethod = $this->stateHandler->getAuthMethod();
68
        $context = $this->stateHandler->getContext();
69
        $requestId = $this->stateHandler->getRequestId();
70
71
        $this->logger->notice(sprintf('Retrieving ADFS Response parameters for RequestId: "%s"', $requestId));
72
        return AdfsResponse::fromValues($authMethod, $context);
73
    }
74
}
75