Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing deprovision data #521

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Surfnet/Stepup/Identity/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,6 @@ public function expressPreferredLocale(Locale $preferredLocale): void

public function forget(): void
{
$this->assertNotForgotten();

if ($this->registrationAuthorities->count() !== 0) {
throw new DomainException('Cannot forget an identity that is currently accredited as an RA(A)');
}
Expand Down
31 changes: 31 additions & 0 deletions src/Surfnet/Stepup/Projector/Projector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Copyright 2025 SURFnet B.V.
*
* 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\Projector;

use Broadway\EventHandling\EventListener;
use Broadway\ReadModel\Projector as BroadwayProjector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;

/**
* @SuppressWarnings(PHPMD.NumberOfChildren) we simply have a lot of projectors
*/
abstract class Projector extends BroadwayProjector implements EventListener
{
abstract protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Configuration\Event\AllowedSecondFactorListUpdatedEvent;
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\AllowedSecondFactor;
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\AllowedSecondFactorRepository;
Expand All @@ -40,4 +41,9 @@ public function applyAllowedSecondFactorListUpdatedEvent(AllowedSecondFactorList
$this->allowedSecondFactorRepository->save($allowedSecondFactor);
}
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\ConfiguredInstitution;
Expand All @@ -40,4 +41,9 @@ public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurati
{
$this->configuredInstitutionRepository->removeConfigurationFor($event->institution);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
use Surfnet\Stepup\Configuration\Event\SelectRaaOptionChangedEvent;
Expand Down Expand Up @@ -72,4 +73,9 @@ public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurati
$event->institution,
);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
use Surfnet\Stepup\Configuration\Event\NumberOfTokensPerIdentityOptionChangedEvent;
Expand All @@ -32,6 +33,9 @@
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\AllowedSecondFactorRepository;
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionConfigurationOptionsRepository;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
final class InstitutionConfigurationOptionsProjector extends Projector
{
public function __construct(
Expand Down Expand Up @@ -131,4 +135,9 @@ public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurati
$this->institutionConfigurationOptionsRepository->removeConfigurationOptionsFor($event->institution);
$this->allowedSecondFactorRepository->clearAllowedSecondFactorListFor($event->institution);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent;
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent;
Expand Down Expand Up @@ -100,4 +101,9 @@ private function fetchRaLocationById(RaLocationId $raLocationId): RaLocation

return $raLocation;
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Surfnet\Stepup\Exception\DomainException;
use Surfnet\Stepup\Helper\UserDataFormatterInterface;
use Surfnet\StepupMiddleware\ApiBundle\Service\DeprovisionServiceInterface;
use Surfnet\StepupMiddleware\ApiBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;

class DeprovisionController extends AbstractController
Expand All @@ -42,11 +41,12 @@ public function deprovision(string $collabPersonId): JsonResponse
if ($userData !== []) {
$this->deprovisionService->deprovision($collabPersonId);
}
} catch (DomainException) {
} catch (DomainException $e) {
// On domain exceptions, like when the identity is forgotten, we return OK, with empty data
// just so the deprovision run does not end prematurely. At this point, no other domain exceptions
// are thrown.
$userData = [];
$errors = [$e->getMessage()];
} catch (Exception $e) {
$userData = [];
$errors = [$e->getMessage()];
Expand All @@ -57,8 +57,11 @@ public function deprovision(string $collabPersonId): JsonResponse
public function dryRun(string $collabPersonId): JsonResponse
{
$this->denyAccessUnlessGrantedOneOff(['ROLE_DEPROVISION']);

$errors = [];
try {
$this->deprovisionService->assertIsAllowed($collabPersonId);

$userData = $this->deprovisionService->readUserData($collabPersonId);
} catch (Exception $e) {
$userData = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class AuditLogEntry implements JsonSerializable
public ?string $secondFactorType = null;

#[ORM\Column(length: 255, nullable: true)]
public ?string $recoveryTokenIdentifier;
public ?string $recoveryTokenIdentifier = null;

#[ORM\Column(length: 36, nullable: true)]
public ?string $recoveryTokenType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\Domain\DomainMessage;
use Broadway\EventHandling\EventListener;
use DateTime as CoreDateTime;
use Ramsey\Uuid\Uuid;
use Surfnet\Stepup\DateTime\DateTime;
Expand All @@ -33,6 +32,7 @@
use Surfnet\Stepup\Identity\Value\RecoveryTokenIdentifierFactory;
use Surfnet\Stepup\Identity\Value\RecoveryTokenType;
use Surfnet\Stepup\Identity\Value\VettingType;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\StepupMiddleware\ApiBundle\Exception\RuntimeException;
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\AuditLogEntry;
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity;
Expand All @@ -42,7 +42,7 @@
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AuditLogProjector implements EventListener
class AuditLogProjector extends Projector
{
public function __construct(
private readonly AuditLogRepository $auditLogRepository,
Expand Down Expand Up @@ -138,7 +138,7 @@ private function applyAuditableEvent(AuditableEvent $event, DomainMessage $domai
$this->auditLogRepository->save($entry);
}

private function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
$entries = $this->auditLogRepository->findByIdentityId($event->identityId);
foreach ($entries as $auditLogEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent;
use Surfnet\Stepup\Identity\Event\IdentityEmailChangedEvent;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Identity\Event\IdentityRenamedEvent;
use Surfnet\Stepup\Identity\Event\LocalePreferenceExpressedEvent;
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
Expand Down Expand Up @@ -95,4 +96,9 @@ private function determinePossessionOfSelfAssertedToken(VettingType $vettingType
}
}
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
$this->identityRepository->updateStatusByIdentityIdToForgotten($event->identityId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent;
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
use Surfnet\Stepup\Identity\Event\SecondFactorVettedWithoutTokenProofOfPossession;
Expand Down Expand Up @@ -81,4 +82,9 @@ private function determinePossessionOfToken(VettingType $vettingType, IdentityId
$identitySelfAssertedTokenOptions->possessedToken = true;
$this->repository->save($identitySelfAssertedTokenOptions);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent;
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\InstitutionListingRepository;

Expand All @@ -36,4 +37,9 @@ public function applyIdentityCreatedEvent(IdentityCreatedEvent $event): void
{
$this->institutionListingRepository->addIfNotExists($event->identityInstitution);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\AppointedAsRaaEvent;
use Surfnet\Stepup\Identity\Event\AppointedAsRaaForInstitutionEvent;
use Surfnet\Stepup\Identity\Event\AppointedAsRaEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\CompliedWithUnverifiedSecondFactorRevocationEvent;
use Surfnet\Stepup\Identity\Event\CompliedWithVerifiedSecondFactorRevocationEvent;
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\CompliedWithRecoveryCodeRevocationEvent;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Identity\Event\PhoneRecoveryTokenPossessionProvenEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\CompliedWithUnverifiedSecondFactorRevocationEvent;
use Surfnet\Stepup\Identity\Event\CompliedWithVerifiedSecondFactorRevocationEvent;
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\Domain\DomainMessage;
use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use DateTime as CoreDateTime;
use Ramsey\Uuid\Uuid;
use Surfnet\Stepup\DateTime\DateTime;
Expand Down Expand Up @@ -61,4 +62,9 @@ protected function applyCompliedWithVettedSecondFactorRevocationEvent(

$this->repository->save($revocation);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Configuration\Event\SraaUpdatedEvent;
use Surfnet\Stepup\Identity\Value\NameId;
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Sraa;
Expand All @@ -41,4 +42,9 @@ public function applySraaUpdatedEvent(SraaUpdatedEvent $event): void

$this->sraaRepository->saveAll($sraaList);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace Surfnet\StepupMiddleware\ApiBundle\Identity\Projector;

use Broadway\ReadModel\Projector;
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
use Surfnet\Stepup\Projector\Projector;
use Surfnet\Stepup\Identity\Event\VettingTypeHintsSavedEvent;
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VettingTypeHint;
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VettingTypeHintRepository;
Expand All @@ -45,4 +46,9 @@ public function applyVettingTypeHintsSavedEvent(VettingTypeHintsSavedEvent $even
$entity->hints = $event->hints;
$this->vettingTypeHintRepository->save($entity);
}

protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
{
// do nothing, no sensitive data in this projection
}
}
Loading
Loading