diff --git a/config/services.yaml b/config/services.yaml index 7f782716..ad885408 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -48,3 +48,9 @@ services: Surfnet\StepupRa\RaBundle\Security\Authentication\AuthenticatedSessionStateHandler: alias: ra.security.authentication.session.session_storage + + Surfnet\SamlBundle\Security\Authentication\Handler\FailureHandler: + class: Surfnet\StepupRa\RaBundle\Security\Authentication\Handler\FailureHandler + public: false + arguments: + $exceptionController: '@Surfnet\StepupRa\RaBundle\Controller\ExceptionController' diff --git a/src/Surfnet/StepupRa/RaBundle/Security/Authentication/Handler/FailureHandler.php b/src/Surfnet/StepupRa/RaBundle/Security/Authentication/Handler/FailureHandler.php new file mode 100644 index 00000000..51360a92 --- /dev/null +++ b/src/Surfnet/StepupRa/RaBundle/Security/Authentication/Handler/FailureHandler.php @@ -0,0 +1,56 @@ + $options + */ + public function __construct( + HttpKernelInterface $httpKernel, + HttpUtils $httpUtils, + private readonly ExceptionController $exceptionController, + array $options = [], + ?LoggerInterface $logger = null, + ) { + parent::__construct($httpKernel, $httpUtils, $options, $logger); + } + + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response + { + $message = sprintf( + 'Authentication failure: %s: "%s"', + $exception->getMessageKey(), + $exception->getMessage(), + ); + $this->logger->notice($message); + // The exception controller is used to show the failed authentication + return $this->exceptionController->show($request, $exception); + } +}