/**
  * {@inheritdoc}
  */
 public function start(Request $request, AuthenticationException $authException = null)
 {
     if ($this->useForward) {
         return $event->getSubject()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST);
     }
     $response = new Response();
     $response->setRedirect(0 !== strpos($this->loginPath, 'http') ? $request->getUriForPath($this->loginPath) : $this->loginPath, 302);
     return $response;
 }
Esempio n. 2
0
 /**
  * 
  *
  * @param Event $event An Event instance
  */
 public function handle(Event $event)
 {
     $request = $event->getParameter('request');
     if ($this->logoutPath !== $request->getPathInfo()) {
         return;
     }
     $this->securityContext->setToken(null);
     $request->getSession()->invalidate();
     $response = new Response();
     $response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
     $event->setReturnValue($response);
     return true;
 }
Esempio n. 3
0
 /**
  * Performs the logout if requested
  *
  * @param Event $event An Event instance
  */
 public function handle(Event $event)
 {
     $request = $event->get('request');
     if ($this->logoutPath !== $request->getPathInfo()) {
         return;
     }
     $response = new Response();
     $response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
     $token = $this->securityContext->getToken();
     foreach ($this->handlers as $handler) {
         $handler->logout($request, $response, $token);
     }
     $this->securityContext->setToken(null);
     $event->setReturnValue($response);
     return true;
 }
 /**
  * Performs the logout if requested
  *
  * @param EventInterface $event An EventInterface instance
  */
 public function handle(EventInterface $event)
 {
     $request = $event->get('request');
     if ($this->logoutPath !== $request->getPathInfo()) {
         return;
     }
     $response = new Response();
     $response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
     // handle multiple logout attempts gracefully
     if ($token = $this->securityContext->getToken()) {
         foreach ($this->handlers as $handler) {
             $handler->logout($request, $response, $token);
         }
     }
     $this->securityContext->setToken(null);
     $event->setProcessed();
     return $response;
 }
 public function start(Request $request, AuthenticationException $authException = null)
 {
     $scheme = $request->isSecure() ? 'http' : 'https';
     if ('http' === $scheme && 80 != $this->httpPort) {
         $port = ':' . $this->httpPort;
     } elseif ('https' === $scheme && 443 != $this->httpPort) {
         $port = ':' . $this->httpsPort;
     } else {
         $port = '';
     }
     $qs = $request->getQueryString();
     if (null !== $qs) {
         $qs = '?' . $qs;
     }
     $url = $scheme . '://' . $request->getHost() . $port . $request->getScriptName() . $request->getPathInfo() . $qs;
     $response = new Response();
     $response->setRedirect($url, 301);
     return $response;
 }
 protected function onSuccess(Request $request, TokenInterface $token)
 {
     if (null !== $this->logger) {
         $this->logger->debug('User has been authenticated successfully');
     }
     $this->securityContext->setToken($token);
     $session = $request->getSession();
     $session->remove(SecurityContext::AUTHENTICATION_ERROR);
     $session->remove(SecurityContext::LAST_USERNAME);
     $response = new Response();
     $path = $this->determineTargetUrl($request);
     $response->setRedirect(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
     return $response;
 }
Esempio n. 7
0
 /**
  * Handles digest authentication.
  *
  * @param Event $event An Event instance
  */
 public function handle(Event $event)
 {
     $request = $event->getParameter('request');
     if (!$request->get($this->usernameParameter)) {
         return;
     }
     if ('_exit' === $request->get($this->usernameParameter)) {
         $this->securityContext->setToken($this->attemptExitUser($request));
     } else {
         try {
             $this->securityContext->setToken($this->attemptSwitchUser($request));
         } catch (AuthenticationException $e) {
             if (null !== $this->logger) {
                 $this->logger->debug(sprintf('Switch User failed: "%s"', $e->getMessage()));
             }
         }
     }
     $response = new Response();
     $request->server->set('QUERY_STRING', '');
     $response->setRedirect($request->getUri(), 302);
     $event->setReturnValue($response);
     return true;
 }
 protected function onSuccess(EventInterface $event, Request $request, TokenInterface $token)
 {
     if (null !== $this->logger) {
         $this->logger->debug('User has been authenticated successfully');
     }
     $this->securityContext->setToken($token);
     $session = $request->getSession();
     $session->remove(SecurityContext::AUTHENTICATION_ERROR);
     $session->remove(SecurityContext::LAST_USERNAME);
     if (null !== $this->eventDispatcher) {
         $this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token)));
     }
     if (null !== $this->successHandler) {
         $response = $this->successHandler->onAuthenticationSuccess($request, $token);
     } else {
         $response = new Response();
         $path = $this->determineTargetUrl($request);
         $response->setRedirect(0 !== strpos($path, 'http') ? $request->getUriForPath($path) : $path, 302);
     }
     if (null !== $this->rememberMeServices) {
         $this->rememberMeServices->loginSuccess($request, $response, $token);
     }
     return $response;
 }