getRequest()->attributes->get('_controller'); \assert(is_string($controller)); if (!str_contains($controller, self::class)) { return; } // redirect user if they are already authenticated if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY') || $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') ) { $redirectUrl = $this->generateUrl('mautic_dashboard_index'); $event->setResponse(new RedirectResponse($redirectUrl)); } } /** * Generates login form and processes login. */ public function loginAction(Request $request, AuthenticationUtils $authenticationUtils, IntegrationHelper $integrationHelper, TranslatorInterface $translator): Response { $error = $authenticationUtils->getLastAuthenticationError(); if (null !== $error) { if ($error instanceof WeakPasswordException) { $this->addFlash(FlashBag::LEVEL_ERROR, $translator->trans('mautic.user.auth.error.weakpassword', [], 'flashes')); return $this->forward('Mautic\UserBundle\Controller\PublicController::passwordResetAction'); } elseif ($error instanceof Exception\BadCredentialsException) { $msg = 'mautic.user.auth.error.invalidlogin'; } elseif ($error instanceof Exception\DisabledException) { $msg = 'mautic.user.auth.error.disabledaccount'; } else { $msg = $error->getMessage(); } $this->addFlashMessage($msg, [], FlashBag::LEVEL_ERROR, null, false); } $request->query->set('tmpl', 'login'); // Get a list of SSO integrations $integrations = $integrationHelper->getIntegrationObjects(null, ['sso_service'], true, null, true); return $this->delegateView([ 'viewParameters' => [ 'last_username' => $authenticationUtils->getLastUsername(), 'integrations' => $integrations, ], 'contentTemplate' => '@MauticUser/Security/login.html.twig', 'passthroughVars' => [ 'route' => $this->generateUrl('login'), 'mauticContent' => 'user', 'sessionExpired' => true, ], ]); } /** * Do nothing. */ public function loginCheckAction(): void { } /** * The plugin should be handling this in it's listener. */ public function ssoLoginAction($integration): RedirectResponse { return new RedirectResponse($this->generateUrl('login')); } /** * The plugin should be handling this in it's listener. */ public function ssoLoginCheckAction($integration): RedirectResponse { // The plugin should be handling this in it's listener return new RedirectResponse($this->generateUrl('login')); } public function samlLoginRetryAction(Request $request, SAMLHelper $samlHelper, SessionInterface $session): Response { if (!$samlHelper->isSamlEnabled()) { return new RedirectResponse($this->generateUrl('login')); } $session->invalidate(); $this->addFlashMessage('mautic.user.security.saml.clearsession', [], FlashBag::LEVEL_ERROR); return $this->delegateView([ 'viewParameters' => [ 'loginRoute' => $this->generateUrl('lightsaml_sp.discovery'), ], 'contentTemplate' => '@MauticUser/Security/saml_login_retry.html.twig', 'passthroughVars' => [ 'route' => $this->generateUrl('mautic_base_index'), 'mauticContent' => 'user', 'sessionExpired' => true, ], ]); } /** * @return array */ public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => 'onRequest', ]; } }