SecondFactor::getInstitution()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2014 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\GatewayBundle\Entity;
20
21
use Doctrine\ORM\Mapping as ORM;
22
use Surfnet\StepupBundle\Service\SecondFactorTypeService;
23
use Surfnet\StepupBundle\Value\Loa;
24
use Surfnet\StepupBundle\Value\SecondFactorType;
25
use Surfnet\StepupBundle\Value\VettingType;
26
use Surfnet\StepupGateway\GatewayBundle\Service\SecondFactor\SecondFactorInterface;
27
28
/**
29
 * WARNING: Any schema change made to this entity should also be applied to the Middleware SecondFactor entity!
30
 *          Migrations are managed by Middleware.
31
 *
32
 * @see Surfnet\StepupMiddleware\GatewayBundle\Entity\SecondFactor (in OpenConext/Stepup-Middleware project)
33
 */
34
#[ORM\Entity(repositoryClass: \Surfnet\StepupGateway\GatewayBundle\Entity\DoctrineSecondFactorRepository::class)]
35
#[ORM\Table]
36
#[ORM\Index(name: 'idx_secondfactor_nameid', columns: ['name_id'])]
37
class SecondFactor implements SecondFactorInterface
38
{
39
    /**
40
     * @var string
41
     */
42
    #[ORM\Id]
43
    #[ORM\Column(length: 36)]
44
    public $id;
45
46
    /**
47
     * @var string
48
     */
49
    #[ORM\Id]
50
    #[ORM\Column(length: 36)]
51
    public $identityId;
52
53
    /**
54
     * @var string
55
     */
56
    #[ORM\Column(length: 200)]
57
    public $nameId;
58
59
    /**
60
     * @var string
61
     */
62
    #[ORM\Column(length: 200)]
63
    public $institution;
64
65
    /**
66
     * In which language to display any second factor verification screens.
67
     *
68
     * @var string
69
     */
70
    #[ORM\Column]
71
    public $displayLocale;
72
73
    /**
74
     * @var string
75
     */
76
    #[ORM\Column(length: 36)]
77
    public $secondFactorId;
78
79
    /**
80
     * @var string
81
     */
82
    #[ORM\Column(length: 50)]
83
    public $secondFactorType;
84
85
    /**
86
     * @var string
87
     */
88
    #[ORM\Column(length: 255)]
89
    public $secondFactorIdentifier;
90
91
    /**
92
     * This boolean indicates if the second factor token was vetted
93
     * using one of the vetting types that are considered 'identity-vetted'.
94
     * That in turn means if the owner of the second factor token has its
95
     * identity vetted (verified) by a RA(A) at the service desk. This trickles
96
     * down to the self-vet vetting type. As the token used for self vetting
97
     * was RA vetted.
98
     */
99
    #[ORM\Column(type: 'boolean', options: ['default' => '1'])]
100
    public $identityVetted;
101
102
    /**
103
     * No new second factors should be created by the gateway
104
     */
105
    private function __construct()
106
    {
107
    }
108
109
    public function canSatisfy(Loa $loa, SecondFactorTypeService $service): bool
110
    {
111
        $secondFactorType = new SecondFactorType($this->secondFactorType);
112
        $vettingType = $this->determineVettingType($this->identityVetted);
113
        return $service->canSatisfy($secondFactorType, $loa, $vettingType);
114
    }
115
116
    /**
117
     * @param SecondFactorTypeService $service
118
     * @return float
119
     */
120
    public function getLoaLevel(SecondFactorTypeService $service): float
121
    {
122
        $secondFactorType = new SecondFactorType($this->secondFactorType);
123
        $vettingType = $this->determineVettingType($this->identityVetted);
124
        $level = $service->getLevel($secondFactorType, $vettingType);
125
        return $level;
126
    }
127
128
    private function determineVettingType(bool $identityVetted): VettingType
129
    {
130
        if ($identityVetted) {
131
            return new VettingType(VettingType::TYPE_ON_PREMISE);
132
        }
133
        return new VettingType(VettingType::TYPE_SELF_ASSERTED_REGISTRATION);
134
    }
135
136
    public function getSecondFactorId(): string
137
    {
138
        return $this->secondFactorId;
139
    }
140
141
    public function getSecondFactorType(): string
142
    {
143
        return $this->secondFactorType;
144
    }
145
146
    public function getDisplayLocale(): string
147
    {
148
        return $this->displayLocale;
149
    }
150
151
    public function getSecondFactorIdentifier(): string
152
    {
153
        return $this->secondFactorIdentifier;
154
    }
155
156
    public function getInstitution(): string
157
    {
158
        return $this->institution;
159
    }
160
}
161