Completed
Push — release/3.1 ( 4bc9e6...ab193b )
by Michiel
03:25 queued 01:15
created

findConfigurationOptionsFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2020 SURFnet B.V.
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\StepupMiddleware\MiddlewareBundle\Service;
20
21
use Doctrine\ORM\NonUniqueResultException;
22
use Surfnet\Stepup\Configuration\Value\Institution;
23
use Surfnet\Stepup\Identity\Value\Institution as IdentityInstitution;
24
use Surfnet\Stepup\Identity\Value\NameId;
25
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionConfigurationOptions;
26
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionConfigurationOptionsRepository;
27
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
28
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\UnverifiedSecondFactor;
29
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VerifiedSecondFactor;
30
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository;
31
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\UnverifiedSecondFactorRepository;
32
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VerifiedSecondFactorRepository;
33
34
/**
35
 * Encapsulates some ApiBundle repositories to aid the bootstrapping of identities including second factor tokens
36
 * for test
37
 */
38
class TokenBootstrapService
39
{
40
    /** @var IdentityRepository  */
41
    private $identityRepository;
42
    /** @var UnverifiedSecondFactorRepository  */
43
    private $unverifiedSecondFactorRepository;
44
    /** @var VerifiedSecondFactorRepository */
45
    private $verifiedSecondFactorRepository;
46
    /** @var InstitutionConfigurationOptionsRepository */
47
    private $institutionConfigurationRepository;
48
49
    public function __construct(
50
        IdentityRepository $identityRepository,
51
        UnverifiedSecondFactorRepository $unverifiedSecondFactorRepository,
52
        VerifiedSecondFactorRepository $verifiedSecondFactorRepository,
53
        InstitutionConfigurationOptionsRepository $institutionConfigurationOptionsRepository
54
    ) {
55
        $this->identityRepository = $identityRepository;
56
        $this->unverifiedSecondFactorRepository = $unverifiedSecondFactorRepository;
57
        $this->verifiedSecondFactorRepository = $verifiedSecondFactorRepository;
58
        $this->institutionConfigurationRepository = $institutionConfigurationOptionsRepository;
59
    }
60
61
    /**
62
     * @param $actorId
63
     * @return Identity|null
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
64
     */
65
    public function findIdentityById($actorId)
66
    {
67
        return $this->identityRepository->findOneBy(['id' => $actorId]);
68
    }
69
70
    /**
71
     * @param $institution
72
     * @return InstitutionConfigurationOptions
73
     * @throws NonUniqueResultException
74
     */
75
    public function findConfigurationOptionsFor($institution)
76
    {
77
        return $this->institutionConfigurationRepository->findConfigurationOptionsFor(new Institution($institution));
78
    }
79
80
    /**
81
     * @param $identityId
82
     * @param $tokenType
83
     * @return UnverifiedSecondFactor|null
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
84
     */
85
    public function findUnverifiedToken($identityId, $tokenType)
86
    {
87
        return $this->unverifiedSecondFactorRepository->findOneBy(
88
            ['identityId' => $identityId, 'type' => $tokenType]
89
        );
90
    }
91
92
    /**
93
     * @param $identityId
94
     * @param $tokenType
95
     * @return VerifiedSecondFactor|null
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
96
     */
97
    public function findVerifiedToken($identityId, $tokenType)
98
    {
99
        return $this->verifiedSecondFactorRepository->findOneBy(
100
            ['identityId' => $identityId, 'type' => $tokenType]
101
        );
102
    }
103
104
    /**
105
     * @param NameId $nameId
106
     * @param IdentityInstitution $institution
107
     * @return Identity
108
     */
109
    public function findOneByNameIdAndInstitution(NameId $nameId, IdentityInstitution $institution)
110
    {
111
        return $this->identityRepository->findOneByNameIdAndInstitution($nameId, $institution);
112
    }
113
114
    public function hasIdentityWithNameIdAndInstitution(NameId $nameId, IdentityInstitution $institution)
115
    {
116
        return $this->identityRepository->hasIdentityWithNameIdAndInstitution($nameId, $institution);
117
    }
118
}
119