Completed
Pull Request — develop (#93)
by Boy
03:47
created

SecondFactorOnlyNameIdValidationService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 68
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A with() 0 5 1
B validate() 0 32 3
1
<?php
2
3
namespace Surfnet\StepupGateway\SecondFactorOnlyBundle\Service;
4
5
use Psr\Log\LoggerInterface;
6
use Surfnet\StepupGateway\GatewayBundle\Service\SamlEntityService;
7
8
final class SecondFactorOnlyNameIdValidationService
9
{
10
    /**
11
     * @var LoggerInterface
12
     */
13
    private $logger;
14
15
    /**
16
     * @var SamlEntityService
17
     */
18
    private $entityService;
19
20
    public function __construct(LoggerInterface $logger, SamlEntityService $entityService)
21
    {
22
        $this->logger = $logger;
23
        $this->entityService = $entityService;
24
    }
25
26
    /**
27
     * @param LoggerInterface $logger
28
     * @return $this
29
     */
30
    public function with(LoggerInterface $logger)
31
    {
32
        $this->logger = $logger;
33
        return $this;
34
    }
35
36
    /**
37
     * Is the given SP allowed to authenticate via Second Factor Only for the given NameID?
38
     *
39
     * @param string $spEntityId
40
     * @param string $nameId
41
     * @return bool
42
     */
43
    public function validate($spEntityId, $nameId)
44
    {
45
        if (!$nameId) {
46
            $this->logger->info(
47
                'No NameID provided, sending response with status Requester Error'
48
            );
49
            return false;
50
        }
51
52
        $serviceProvider = $this->entityService->getServiceProvider($spEntityId);
53
54
        if (!$serviceProvider->isAllowedToUseSecondFactorOnlyFor($nameId)) {
55
            $this->logger->info(
56
                sprintf(
57
                    'SP "%s" may not use SecondFactorOnly mode for nameid "%s", sending response with status Requester Error',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 126 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
58
                    $spEntityId,
59
                    $nameId
60
                )
61
            );
62
            return false;
63
        }
64
65
        $this->logger->info(
66
            sprintf(
67
                'SP "%s" is allowed to use SecondFactorOnly mode for nameid "%s"',
68
                $spEntityId,
69
                $nameId
70
            )
71
        );
72
73
        return true;
74
    }
75
}
76