CompliedWithRevocationEvent   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setSensitiveData() 0 3 1
A serialize() 0 8 1
A deserialize() 0 11 1
A getAuditLogMetadata() 0 10 1
A obtainUserData() 0 5 1
A getSensitiveData() 0 4 1
A __construct() 0 9 1
A getAllowlist() 0 3 1
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\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\SecondFactorId;
25
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifier;
26
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifierFactory;
27
use Surfnet\StepupBundle\Value\SecondFactorType;
28
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
29
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
30
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
31
32
abstract class CompliedWithRevocationEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface
33
{
34
    /**
35
     * @var string[]
36
     */
37
    private array $allowlist = [
38
        'identity_id',
39
        'identity_institution',
40
        'second_factor_identifier',
41
        'second_factor_type',
42
        'authority_id',
43
    ];
44
45
    final public function __construct(
46
        IdentityId $identityId,
47
        Institution $identityInstitution,
48
        public SecondFactorId $secondFactorId,
49
        public SecondFactorType $secondFactorType,
50
        public SecondFactorIdentifier $secondFactorIdentifier,
51
        public IdentityId $authorityId,
52
    ) {
53
        parent::__construct($identityId, $identityInstitution);
54
    }
55
56
    public function getAuditLogMetadata(): Metadata
57
    {
58
        $metadata = new Metadata();
59
        $metadata->identityId = $this->identityId;
60
        $metadata->identityInstitution = $this->identityInstitution;
61
        $metadata->secondFactorId = $this->secondFactorId;
62
        $metadata->secondFactorType = $this->secondFactorType;
63
        $metadata->secondFactorIdentifier = $this->secondFactorIdentifier;
64
65
        return $metadata;
66
    }
67
68
    final public static function deserialize(array $data): self
69
    {
70
        $secondFactorType = new SecondFactorType($data['second_factor_type']);
71
72
        return new static(
73
            new IdentityId($data['identity_id']),
74
            new Institution($data['identity_institution']),
75
            new SecondFactorId($data['second_factor_id']),
76
            $secondFactorType,
77
            SecondFactorIdentifierFactory::unknownForType($secondFactorType),
78
            new IdentityId($data['authority_id']),
79
        );
80
    }
81
82
    /**
83
     * The data ending up in the event_stream, be careful not to include sensitive data here!
84
     */
85
    final public function serialize(): array
86
    {
87
        return [
88
            'identity_id' => (string)$this->identityId,
89
            'identity_institution' => (string)$this->identityInstitution,
90
            'second_factor_id' => (string)$this->secondFactorId,
91
            'second_factor_type' => (string)$this->secondFactorType,
92
            'authority_id' => (string)$this->authorityId,
93
        ];
94
    }
95
96
    public function getSensitiveData(): SensitiveData
97
    {
98
        return (new SensitiveData)
0 ignored issues
show
Coding Style introduced by
Parentheses must be used when instantiating a new class
Loading history...
99
            ->withSecondFactorIdentifier($this->secondFactorIdentifier, $this->secondFactorType);
100
    }
101
102
    public function setSensitiveData(SensitiveData $sensitiveData): void
103
    {
104
        $this->secondFactorIdentifier = $sensitiveData->getSecondFactorIdentifier();
105
    }
106
107
    public function obtainUserData(): array
108
    {
109
        $serializedPublicUserData = $this->serialize();
110
        $serializedSensitiveUserData = $this->getSensitiveData()->serialize();
111
        return array_merge($serializedPublicUserData, $serializedSensitiveUserData);
112
    }
113
114
    /**
115
     * @return string[]
116
     */
117
    public function getAllowlist(): array
118
    {
119
        return $this->allowlist;
120
    }
121
}
122