|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2022 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\StepupSelfService\SelfServiceBundle\Service; |
|
20
|
|
|
|
|
21
|
|
|
use Exception; |
|
22
|
|
|
use Psr\Log\LoggerInterface; |
|
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
|
24
|
|
|
|
|
25
|
|
|
class SelfAssertedTokensMarshaller implements VettingMarshaller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var AuthorizationService |
|
29
|
|
|
*/ |
|
30
|
|
|
private $authorizationService; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var LoggerInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $logger; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
AuthorizationService $authorizationService, |
|
39
|
|
|
LoggerInterface $logger |
|
40
|
|
|
) { |
|
41
|
|
|
$this->authorizationService = $authorizationService; |
|
42
|
|
|
$this->logger = $logger; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function isAllowed(Identity $identity, string $secondFactorId): bool |
|
46
|
|
|
{ |
|
47
|
|
|
$this->logger->info('Determine if self-asserted token registration is allowed'); |
|
48
|
|
|
try { |
|
49
|
|
|
$decision = $this->authorizationService->mayRegisterSelfAssertedTokens($identity); |
|
50
|
|
|
} catch (Exception $e) { |
|
51
|
|
|
$this->logger->warning(sprintf('Self-asserted token registration is not allowed. Message "%s"', $e->getMessage())); |
|
52
|
|
|
return false; |
|
53
|
|
|
} |
|
54
|
|
|
$this->logger->info( |
|
55
|
|
|
sprintf( |
|
56
|
|
|
'Self-asserted token registration is %s for %s', |
|
57
|
|
|
$decision === true ? 'allowed' : 'not allowed', |
|
58
|
|
|
$identity->id |
|
59
|
|
|
) |
|
60
|
|
|
); |
|
61
|
|
|
return $decision; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|