Completed
Push — main ( d02cfb...38ec3a )
by
unknown
22s queued 15s
created

SecondFactor::getInstitution()   A

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")
35
 * @ORM\Table(
36
 *      indexes={
37
 *          @ORM\Index(name="idx_secondfactor_nameid", columns={"name_id"}),
38
 *      }
39
 * )
40
 */
41
class SecondFactor implements SecondFactorInterface
42
{
43
    /**
44
     * @var int
45
     *
46
     * @ORM\Id
47
     * @ORM\Column(length=36)
48
     */
49
    public $id;
50
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Id
55
     * @ORM\Column(length=36)
56
     */
57
    public $identityId;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(length=200)
63
     */
64
    public $nameId;
65
66
    /**
67
     * @var string
68
     *
69
     * @ORM\Column(length=200)
70
     */
71
    public $institution;
72
73
    /**
74
     * In which language to display any second factor verification screens.
75
     *
76
     * @var string
77
     *
78
     * @ORM\Column
79
     */
80
    public $displayLocale;
81
82
    /**
83
     * @var string
84
     *
85
     * @ORM\Column(length=36)
86
     */
87
    public $secondFactorId;
88
89
    /**
90
     * @var string
91
     *
92
     * @ORM\Column(length=50)
93
     */
94
    public $secondFactorType;
95
96
    /**
97
     * @var string
98
     *
99
     * @ORM\Column(length=255)
100
     */
101
    public $secondFactorIdentifier;
102
103
    /**
104
     * This boolean indicates if the second factor token was vetted
105
     * using one of the vetting types that are considered 'identity-vetted'.
106
     * That in turn means if the owner of the second factor token has its
107
     * identity vetted (verified) by a RA(A) at the service desk. This trickles
108
     * down to the self-vet vetting type. As the token used for self vetting
109
     * was RA vetted.
110
     *
111
     * @ORM\Column(type="boolean", options={"default":"1"})
112
     */
113
    public $identityVetted;
114
115
    /**
116
     * No new second factors should be created by the gateway
117
     */
118
    final private function __construct()
119
    {
120
    }
121
122
    public function canSatisfy(Loa $loa, SecondFactorTypeService $service): bool
123
    {
124
        $secondFactorType = new SecondFactorType($this->secondFactorType);
125
        $vettingType = $this->determineVettingType($this->identityVetted);
126
        return $service->canSatisfy($secondFactorType, $loa, $vettingType);
127
    }
128
129
    /**
130
     * @param SecondFactorTypeService $service
131
     * @return float
132
     */
133
    public function getLoaLevel(SecondFactorTypeService $service): float
134
    {
135
        $secondFactorType = new SecondFactorType($this->secondFactorType);
136
        $vettingType = $this->determineVettingType($this->identityVetted);
137
        $level = $service->getLevel($secondFactorType, $vettingType);
138
        return $level;
139
    }
140
141
    private function determineVettingType(bool $identityVetted): VettingType
142
    {
143
        if ($identityVetted) {
144
            return new VettingType(VettingType::TYPE_ON_PREMISE);
145
        }
146
        return new VettingType(VettingType::TYPE_SELF_ASSERTED_REGISTRATION);
147
    }
148
149
    public function getSecondFactorId(): string
150
    {
151
        return $this->secondFactorId;
152
    }
153
154
    public function getSecondFactorType(): string
155
    {
156
        return $this->secondFactorType;
157
    }
158
159
    public function getDisplayLocale(): string
160
    {
161
        return $this->displayLocale;
162
    }
163
164
    public function getSecondFactorIdentifier(): string
165
    {
166
        return $this->secondFactorIdentifier;
167
    }
168
169
    public function getInstitution(): string
170
    {
171
        return $this->institution;
172
    }
173
}
174