Skip to content

Commit

Permalink
Handle registration mail command
Browse files Browse the repository at this point in the history
The previous solution where the RegistrationEmailProcessor would send
the registration mail messages was decomissioned. As this would also
send reg mail messages for other vetting types (self asserted, self
vetting).

Now, the SS SP will trigger a SendSecondFactorRegistrationEmailCommand
via the middleware client bundle. And that command is now sending the
mail message via the existing RegistrationMailService.

Some of the control logic that was in the processor mas moved to the
mail service.

See: OpenConext/Stepup-SelfService#276
  • Loading branch information
MKodde committed Dec 8, 2022
1 parent 1d5a78c commit fdc9c05
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 430 deletions.
240 changes: 0 additions & 240 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ public function all_available_commands_should_be_tested()
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\RevokeRegistrantsSecondFactorCommand',
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\SaveVettingTypeHintCommand',
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\SelfVetSecondFactorCommand',
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\SendSecondFactorRegistrationEmailCommand',
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\SendVerifiedSecondFactorRemindersCommand',
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\UpdateIdentityCommand',
'Surfnet\\StepupMiddleware\\CommandHandlingBundle\\Identity\\Command\\VerifyEmailCommand',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* Copyright 2022 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\StepupMiddleware\CommandHandlingBundle\Identity\Command;

use Surfnet\StepupMiddleware\CommandHandlingBundle\Command\AbstractCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Command\SelfServiceExecutable;
use Symfony\Component\Validator\Constraints as Assert;

class SendSecondFactorRegistrationEmailCommand extends AbstractCommand implements SelfServiceExecutable
{
/**
* The ID of an identity.
*
* @Assert\NotBlank()
* @Assert\Type(type="string")
*
* @var string
*/
public $identityId;

/**
* The ID of a second factor token
*
* @Assert\NotBlank()
* @Assert\Type(type="string")
*
* @var string
*/
public $secondFactorId;

public function getIdentityId()
{
return $this->identityId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\RevokeRegistrantsRecoveryTokenCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\RevokeRegistrantsSecondFactorCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\SelfVetSecondFactorCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\SendSecondFactorRegistrationEmailCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\UpdateIdentityCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\VerifyEmailCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\VetSecondFactorCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\CommandHandler\Exception\DuplicateIdentityException;
use function sprintf;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\RegistrationMailService;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -126,6 +127,14 @@ class IdentityCommandHandler extends SimpleCommandHandler
*/
private $recoveryTokenSecretHelper;

/**
* @var RegistrationMailService
*/
private $registrationMailService;

/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
RepositoryInterface $eventSourcedRepository,
IdentityRepository $identityProjectionRepository,
Expand All @@ -135,7 +144,8 @@ public function __construct(
SecondFactorProvePossessionHelper $provePossessionHelper,
InstitutionConfigurationOptionsService $institutionConfigurationOptionsService,
LoaResolutionService $loaResolutionService,
RecoveryTokenSecretHelper $recoveryTokenSecretHelper
RecoveryTokenSecretHelper $recoveryTokenSecretHelper,
RegistrationMailService $registrationMailService
) {
$this->eventSourcedRepository = $eventSourcedRepository;
$this->identityProjectionRepository = $identityProjectionRepository;
Expand All @@ -146,6 +156,7 @@ public function __construct(
$this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService;
$this->loaResolutionService = $loaResolutionService;
$this->recoveryTokenSecretHelper = $recoveryTokenSecretHelper;
$this->registrationMailService = $registrationMailService;
}

public function handleCreateIdentityCommand(CreateIdentityCommand $command)
Expand Down Expand Up @@ -504,6 +515,11 @@ public function handleRevokeRegistrantsRecoveryTokenCommand(RevokeRegistrantsRec
$this->eventSourcedRepository->save($identity);
}

public function handleSendSecondFactorRegistrationEmailCommand(SendSecondFactorRegistrationEmailCommand $command)
{
$this->registrationMailService->send($command->identityId, $command->secondFactorId);
}

public function handleExpressLocalePreferenceCommand(ExpressLocalePreferenceCommand $command)
{
$preferredLocale = new Locale($command->preferredLocale);
Expand Down
Loading

0 comments on commit fdc9c05

Please sign in to comment.