GssfPossessionProvenEvent   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 120
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuditLogMetadata() 0 10 1
A __construct() 0 17 1
A deserialize() 0 18 2
A serialize() 0 11 1
A setSensitiveData() 0 7 1
A getAllowlist() 0 3 1
A obtainUserData() 0 5 1
A getSensitiveData() 0 6 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
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\Stepup\Identity\Event;
20
21
use Surfnet\Stepup\Identity\AuditLog\Metadata;
22
use Surfnet\Stepup\Identity\Value\CommonName;
23
use Surfnet\Stepup\Identity\Value\Email;
24
use Surfnet\Stepup\Identity\Value\EmailVerificationWindow;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Identity\...EmailVerificationWindow was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Surfnet\Stepup\Identity\Value\GssfId;
26
use Surfnet\Stepup\Identity\Value\IdentityId;
27
use Surfnet\Stepup\Identity\Value\Institution;
28
use Surfnet\Stepup\Identity\Value\Locale;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Identity\Value\Locale was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Surfnet\Stepup\Identity\Value\SecondFactorId;
30
use Surfnet\Stepup\Identity\Value\StepupProvider;
31
use Surfnet\StepupBundle\Value\SecondFactorType;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable;
33
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
34
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData;
35
36
class GssfPossessionProvenEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class GssfPossessionProvenEvent
Loading history...
37
{
38
    /**
39
     * @var string[]
40
     */
41
    private array $allowlist = [
42
        'identity_id',
43
        'identity_institution',
44
        'second_factor_id',
45
        'stepup_provider',
46
        'preferred_locale',
47
        'second_factor_identifier',
48
        'common_name',
49
        'email',
50
    ];
51
52
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $identityId should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $identityInstitution should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $secondFactorId should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $stepupProvider should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $gssfId should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $emailVerificationRequired should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $emailVerificationWindow should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $emailVerificationNonce should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $commonName should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $email should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $preferredLocale should have a doc-comment as per coding-style.
Loading history...
53
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
54
     */
55
    public function __construct(
56
        IdentityId              $identityId,
57
        Institution             $identityInstitution,
58
        public SecondFactorId          $secondFactorId,
59
        public StepupProvider          $stepupProvider,
60
        public GssfId                  $gssfId,
61
        public bool             $emailVerificationRequired,
62
        public EmailVerificationWindow $emailVerificationWindow,
63
        public string           $emailVerificationNonce,
64
        public CommonName              $commonName,
65
        public Email                   $email,
66
        /**
67
         * @var Locale Eg. "en_GB"
68
         */
69
        public Locale                  $preferredLocale,
70
    ) {
71
        parent::__construct($identityId, $identityInstitution);
72
    }
73
74
    public function getAuditLogMetadata(): Metadata
75
    {
76
        $metadata = new Metadata();
77
        $metadata->identityId = $this->identityId;
78
        $metadata->identityInstitution = $this->identityInstitution;
79
        $metadata->secondFactorId = $this->secondFactorId;
80
        $metadata->secondFactorType = new SecondFactorType((string)$this->stepupProvider);
81
        $metadata->secondFactorIdentifier = $this->gssfId;
82
83
        return $metadata;
84
    }
85
86
    public static function deserialize(array $data): self
87
    {
88
        if (!isset($data['email_verification_required'])) {
89
            $data['email_verification_required'] = true;
90
        }
91
92
        return new self(
93
            new IdentityId($data['identity_id']),
94
            new Institution($data['identity_institution']),
95
            new SecondFactorId($data['second_factor_id']),
96
            new StepupProvider($data['stepup_provider']),
97
            GssfId::unknown(),
98
            $data['email_verification_required'],
99
            EmailVerificationWindow::deserialize($data['email_verification_window']),
100
            $data['email_verification_nonce'],
101
            CommonName::unknown(),
102
            Email::unknown(),
103
            new Locale($data['preferred_locale']),
104
        );
105
    }
106
107
    /**
108
     * The data ending up in the event_stream, be careful not to include sensitive data here!
109
     *
110
     * @return array<string, mixed>
111
     */
112
    public function serialize(): array
113
    {
114
        return [
115
            'identity_id' => (string)$this->identityId,
116
            'identity_institution' => (string)$this->identityInstitution,
117
            'second_factor_id' => (string)$this->secondFactorId,
118
            'stepup_provider' => (string)$this->stepupProvider,
119
            'email_verification_required' => $this->emailVerificationRequired,
120
            'email_verification_window' => $this->emailVerificationWindow->serialize(),
121
            'email_verification_nonce' => $this->emailVerificationNonce,
122
            'preferred_locale' => (string)$this->preferredLocale,
123
        ];
124
    }
125
126
    public function getSensitiveData(): SensitiveData
127
    {
128
        return (new SensitiveData)
129
            ->withCommonName($this->commonName)
130
            ->withEmail($this->email)
131
            ->withSecondFactorIdentifier($this->gssfId, new SecondFactorType((string)$this->stepupProvider));
132
    }
133
134
    public function setSensitiveData(SensitiveData $sensitiveData): void
135
    {
136
        $this->email = $sensitiveData->getEmail();
137
        $this->commonName = $sensitiveData->getCommonName();
138
        $gssfId = $sensitiveData->getSecondFactorIdentifier();
139
        assert($gssfId instanceof GssfId);
140
        $this->gssfId = $gssfId;
141
    }
142
143
    public function obtainUserData(): array
144
    {
145
        $serializedPublicUserData = $this->serialize();
146
        $serializedSensitiveUserData = $this->getSensitiveData()->serialize();
147
        return array_merge($serializedPublicUserData, $serializedSensitiveUserData);
148
    }
149
150
    /**
151
     * @return string[]
152
     */
153
    public function getAllowlist(): array
154
    {
155
        return $this->allowlist;
156
    }
157
}
158