-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Earlier on it was not possible to restore identities after they were forgotten. Now logic is added to restore and reset the identity email, name and tokens in the identity aggregate so the identity is reset. #525
- Loading branch information
1 parent
ad83840
commit 77bb441
Showing
11 changed files
with
238 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/Surfnet/Stepup/Identity/Event/IdentityRestoredEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2025 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\Stepup\Identity\Event; | ||
|
||
use Surfnet\Stepup\Identity\AuditLog\Metadata; | ||
use Surfnet\Stepup\Identity\Value\CommonName; | ||
use Surfnet\Stepup\Identity\Value\Email; | ||
use Surfnet\Stepup\Identity\Value\IdentityId; | ||
use Surfnet\Stepup\Identity\Value\Institution; | ||
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; | ||
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface; | ||
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; | ||
|
||
class IdentityRestoredEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface | ||
{ | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private array $allowlist = [ | ||
'id', | ||
'common_name', | ||
'email', | ||
'institution', | ||
]; | ||
|
||
public function __construct( | ||
private readonly IdentityId $id, | ||
private readonly Institution $institution, | ||
public CommonName $commonName, | ||
public Email $email, | ||
) { | ||
parent::__construct($id, $institution); | ||
} | ||
|
||
public function getAuditLogMetadata(): Metadata | ||
{ | ||
$metadata = new Metadata(); | ||
$metadata->identityId = $this->id; | ||
$metadata->identityInstitution = $this->institution; | ||
|
||
return $metadata; | ||
} | ||
|
||
/** | ||
* @param array<string,string> $data | ||
*/ | ||
public static function deserialize(array $data): self | ||
{ | ||
return new self( | ||
new IdentityId($data['id']), | ||
new Institution($data['institution']), | ||
new CommonName($data['common_name']), | ||
new Email($data['email']), | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string,string> | ||
*/ | ||
public function serialize(): array | ||
{ | ||
return [ | ||
'id' => (string)$this->id, | ||
'institution' => (string)$this->institution, | ||
'common_name' => (string)$this->commonName, | ||
'email' => (string)$this->email, | ||
]; | ||
} | ||
|
||
public function getSensitiveData(): SensitiveData | ||
{ | ||
return (new SensitiveData) | ||
->withCommonName($this->commonName) | ||
->withEmail($this->email); | ||
} | ||
|
||
public function setSensitiveData(SensitiveData $sensitiveData): void | ||
{ | ||
$this->commonName = $sensitiveData->getCommonName(); | ||
$this->email = $sensitiveData->getEmail(); | ||
} | ||
|
||
/** | ||
* @return array<string,string> | ||
*/ | ||
public function obtainUserData(): array | ||
{ | ||
$serializedPublicUserData = $this->serialize(); | ||
$serializedSensitiveUserData = $this->getSensitiveData()->serialize(); | ||
return array_merge($serializedPublicUserData, $serializedSensitiveUserData); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getAllowlist(): array | ||
{ | ||
return $this->allowlist; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent; | ||
use Surfnet\Stepup\Identity\Event\IdentityEmailChangedEvent; | ||
use Surfnet\Stepup\Identity\Event\IdentityRenamedEvent; | ||
use Surfnet\Stepup\Identity\Event\IdentityRestoredEvent; | ||
use Surfnet\Stepup\Identity\Event\LocalePreferenceExpressedEvent; | ||
use Surfnet\Stepup\Identity\Event\PhonePossessionProvenEvent; | ||
use Surfnet\Stepup\Identity\Event\RegistrationAuthorityInformationAmendedEvent; | ||
|
@@ -293,6 +294,14 @@ public function eventProvider(): array | |
new Locale('en_GB'), | ||
), | ||
], | ||
'IdentityRestoredEvent' => [ | ||
new IdentityRestoredEvent( | ||
new IdentityId($this->UUID()), | ||
new Institution('BabelFish Inc'), | ||
new CommonName('Henk Westbroek'), | ||
new Email('[email protected]'), | ||
), | ||
], | ||
'IdentityEmailChangedEvent' => [ | ||
new IdentityEmailChangedEvent( | ||
new IdentityId($this->UUID()), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.