RecoveryTokenRevokedEvent::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 RecoveryTokenRevokedEvent extends IdentityEvent implements RightToObtainDataInterface
29
{
30
    /**
31
     * @var string[]
32
     */
33
    private array $allowlist = [
34
        'identity_id',
35
        'identity_institution',
36
        'recovery_token_id',
37
        'recovery_token_type',
38
    ];
39
40
    final public function __construct(
41
        IdentityId $identityId,
42
        Institution $identityInstitution,
43
        public RecoveryTokenId $recoveryTokenId,
44
        public RecoveryTokenType $recoveryTokenType,
45
    ) {
46
        parent::__construct($identityId, $identityInstitution);
47
    }
48
49
    final public static function deserialize(array $data): self
50
    {
51
        $recoveryTokenType = new RecoveryTokenType($data['recovery_token_type']);
52
53
        return new static(
54
            new IdentityId($data['identity_id']),
55
            new Institution($data['identity_institution']),
56
            new RecoveryTokenId($data['recovery_token_id']),
57
            $recoveryTokenType,
58
        );
59
    }
60
61
    public function getAuditLogMetadata(): Metadata
62
    {
63
        $metadata = new Metadata();
64
        $metadata->identityId = $this->identityId;
65
        $metadata->identityInstitution = $this->identityInstitution;
66
        $metadata->recoveryTokenId = $this->recoveryTokenId;
67
        $metadata->recoveryTokenType = $this->recoveryTokenType;
68
69
        return $metadata;
70
    }
71
72
    public function obtainUserData(): array
73
    {
74
        return $this->serialize();
75
    }
76
77
    /**
78
     * The data ending up in the event_stream, be careful not to include sensitive data here!
79
     */
80
    final public function serialize(): array
81
    {
82
        return [
83
            'identity_id' => (string)$this->identityId,
84
            'identity_institution' => (string)$this->identityInstitution,
85
            'recovery_token_id' => (string)$this->recoveryTokenId,
86
            'recovery_token_type' => (string)$this->recoveryTokenType,
87
        ];
88
    }
89
90
    /**
91
     * @return string[]
92
     */
93
    public function getAllowlist(): array
94
    {
95
        return $this->allowlist;
96
    }
97
}
98