Completed
Push — feature/post-binding ( d0c113 )
by
unknown
02:23
created

ResponseHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
 * @package Surfnet\StepupGateway\SecondFactorOnlyBundle\Service
34
 */
35
final class ResponseHelper
36
{
37
38
    /** @var LoggerInterface */
39
    private $logger;
40
41
    /** @var StateHandler */
42
    private $stateHandler;
43
44
    /**
45
     * ResponseHelper constructor.
46
     * @param StateHandler $stateHandler
47
     * @param LoggerInterface $logger
48
     */
49
    public function __construct(StateHandler $stateHandler, LoggerInterface $logger)
50
    {
51
        $this->stateHandler = $stateHandler;
52
        $this->logger = $logger;
53
    }
54
55
    /**
56
     * @param string $originalRequestId
57
     * @return bool
58
     */
59
    public function isAdfsResponse($originalRequestId)
60
    {
61
        return $this->stateHandler->hasMatchingRequestId($originalRequestId);
62
    }
63
64
    /**
65
     * @return AdfsResponse
66
     */
67
    public function retrieveAdfsParameters()
68
    {
69
        $authMethod = $this->stateHandler->getAuthMethod();
70
        $context = $this->stateHandler->getContext();
71
        $requestId = $this->stateHandler->getRequestId();
72
        $this->logger->notice(sprintf('Retrieving ADFS Response parameters for RequestId: "%s"', $requestId));
73
        return AdfsResponse::fromValues($authMethod, $context, $requestId);
74
    }
75
}
76