getAllowlist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2022 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\Stepup\Identity\Event;
20
21
use Surfnet\Stepup\Identity\AuditLog\Metadata;
22
use Surfnet\Stepup\Identity\Value\IdentityId;
23
use Surfnet\Stepup\Identity\Value\Institution;
24
use Surfnet\Stepup\Identity\Value\RecoveryTokenId;
25
use Surfnet\Stepup\Identity\Value\RecoveryTokenType;
26
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
27
28
class CompliedWithRecoveryCodeRevocationEvent extends IdentityEvent implements RightToObtainDataInterface
29
{
30
    /**
31
     * @var string[]
32
     */
33
    private array $allowlist = [
34
        'identity_id',
35
        'identity_institution',
36
        'recovery_token_type',
37
        'authority_id',
38
    ];
39
40
    final public function __construct(
41
        IdentityId $identityId,
42
        Institution $identityInstitution,
43
        public RecoveryTokenId $recoveryTokenId,
44
        public RecoveryTokenType $recoveryTokenType,
45
        public IdentityId $authorityId,
46
    ) {
47
        parent::__construct($identityId, $identityInstitution);
48
    }
49
50
    final public static function deserialize(array $data): self
51
    {
52
        $recoveryTokenType = new RecoveryTokenType($data['recovery_token_type']);
53
54
        return new static(
55
            new IdentityId($data['identity_id']),
56
            new Institution($data['identity_institution']),
57
            new RecoveryTokenId($data['recovery_token_id']),
58
            $recoveryTokenType,
59
            new IdentityId($data['authority_id']),
60
        );
61
    }
62
63
    public function getAuditLogMetadata(): Metadata
64
    {
65
        $metadata = new Metadata();
66
        $metadata->identityId = $this->identityId;
67
        $metadata->identityInstitution = $this->identityInstitution;
68
        $metadata->recoveryTokenId = $this->recoveryTokenId;
69
        $metadata->recoveryTokenType = $this->recoveryTokenType;
70
71
        return $metadata;
72
    }
73
74
    public function obtainUserData(): array
75
    {
76
        return $this->serialize();
77
    }
78
79
    /**
80
     * The data ending up in the event_stream, be careful not to include sensitive data here!
81
     */
82
    final public function serialize(): array
83
    {
84
        return [
85
            'identity_id' => (string)$this->identityId,
86
            'identity_institution' => (string)$this->identityInstitution,
87
            'recovery_token_id' => (string)$this->recoveryTokenId,
88
            'recovery_token_type' => (string)$this->recoveryTokenType,
89
            'authority_id' => (string)$this->authorityId,
90
        ];
91
    }
92
93
    /**
94
     * @return string[]
95
     */
96
    public function getAllowlist(): array
97
    {
98
        return $this->allowlist;
99
    }
100
}
101