當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AuthenticationException::getMessage方法代碼示例

本文整理匯總了PHP中Symfony\Component\Security\Core\Exception\AuthenticationException::getMessage方法的典型用法代碼示例。如果您正苦於以下問題:PHP AuthenticationException::getMessage方法的具體用法?PHP AuthenticationException::getMessage怎麽用?PHP AuthenticationException::getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Security\Core\Exception\AuthenticationException的用法示例。


在下文中一共展示了AuthenticationException::getMessage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validateCookie

 /**
  * Validates WordPress authentication cookie
  *
  * @param UserProviderInterface $userProvider
  * @param Cookie $cookie
  * @return UserInterface UserInterface if valid.
  * @throws RuntimeException
  * @throws AuthenticationException
  */
 public function validateCookie(UserProviderInterface $userProvider, $cookie)
 {
     $cookieParts = $this->decodeCookie($cookie);
     switch (count($cookieParts)) {
         case 3:
             list($username, $expiration, $hmac) = $cookieParts;
             $token = null;
             break;
         case 4:
             list($username, $expiration, $token, $hmac) = $cookieParts;
             break;
         default:
             throw new AuthenticationException('Invalid WordPress cookie.');
     }
     if ($expiration < time()) {
         throw new AuthenticationException('The WordPress cookie has expired.');
     }
     try {
         $user = $userProvider->loadUserByUsername($username);
     } catch (Exception $exception) {
         if (!$exception instanceof AuthenticationException) {
             $exception = new AuthenticationException($exception->getMessage(), $exception->getCode(), $exception);
         }
         throw $exception;
     }
     if (!$user instanceof UserInterface) {
         throw new RuntimeException(sprintf('The UserProviderInterface implementation must return an instance of UserInterface, but returned "%s".', get_class($user)));
     }
     if ($token && $hmac !== $this->generateHmacWithToken($username, $expiration, $token, $user->getPassword()) || !$token && $hmac !== $this->generateHmac($username, $expiration, $user->getPassword())) {
         throw new AuthenticationException('The WordPress cookie\'s hash is invalid. Your logged in key and salt settings could be wrong.');
     }
     return $user;
 }
開發者ID:ninodafonte,項目名稱:KayueWordpressBundle,代碼行數:42,代碼來源:AuthenticationCookieManager.php

示例2: onAuthenticationFailure

 /**
  * @inheritDocs
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $request->getSession()->setFlash('error', $exception->getMessage());
     $this->disconnectAllConnections($request);
     $url = $this->container->get('router')->generate('login');
     return new RedirectResponse($url);
 }
開發者ID:Barathi07,項目名稱:Netopeer-GUI,代碼行數:10,代碼來源:AuthenticationHandler.php

示例3: onAuthenticationFailure

 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     //ladybug_dump_die($exception->getMessage());
     $url = $this->router->generate('fos_user_security_login', array("slug" => $exception->getMessage()));
     return new RedirectResponse($url);
     //$this->container->re
 }
開發者ID:ansitun,項目名稱:jyoti,代碼行數:7,代碼來源:AuthenticationFailureHandlerService.php

示例4: start

 public function start(Request $request, AuthenticationException $authException = null)
 {
     $response = new Response();
     $response->headers->set('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realmName));
     $response->setStatusCode(401, $authException->getMessage());
     return $response;
 }
開發者ID:nickaggarwal,項目名稱:sample-symfony2,代碼行數:7,代碼來源:BasicAuthenticationEntryPoint.php

示例5: onAuthenticationFailure

 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->request->has('_username')) {
         $username = $request->request->get('_username');
     } else {
         $username = '';
     }
     //if ($exception->getMessage() === 'Captcha is invalid') {
     //} else {
     $failedLoginIp = $request->getClientIp();
     $user = $this->fosUM->findUserByUsername($username);
     if ($user) {
         $failedLogin = $user->getFailedLogin();
         $failedLogin++;
         $user->setFailedLogin($failedLogin);
         $user->setFailedLoginIp($failedLoginIp);
         if ($failedLogin === 3) {
             //email do użytkownika i admina
             $message = \Swift_Message::newInstance()->setSubject('Nieautoryzowane próby dostępu do konta')->setFrom('noreply@bms.klimbest.pl')->setTo(array('pawel.zajder@klimbest.pl', $user->getEmail()))->setBody($username . ' próbował zalogować się zbyt wiele razy z adresu IP: ' . $failedLoginIp . ' ' . $exception->getMessage());
             $this->mailer->send($message);
         }
         if ($failedLogin === 5) {
             $user->setLocked(1);
         }
         $this->fosUM->updateUser($user);
     }
     //}
     $url = 'fos_user_security_login';
     $response = new RedirectResponse($this->router->generate($url));
     return $response;
 }
開發者ID:ZajdeR,項目名稱:bmsonline-main,代碼行數:31,代碼來源:LoginFailureHandler.php

示例6: onAuthenticationFailure

 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         return new Response(json_encode(array('has_error' => true, 'error' => $this->translator->trans($exception->getMessage()))));
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
開發者ID:vlastv,項目名稱:AjaxLoginBundle,代碼行數:10,代碼來源:AjaxAuthenticationFailureHandler.php

示例7: processAutoLoginCookie

 /**
  * {@inheritdoc}
  */
 protected function processAutoLoginCookie(array $cookieParts, Request $request)
 {
     if (count($cookieParts) !== 4) {
         throw new AuthenticationException('The cookie is invalid.');
     }
     list($class, $username, $expires, $hash) = $cookieParts;
     if (false === ($username = base64_decode($username, true))) {
         throw new AuthenticationException('$username contains a character from outside the base64 alphabet.');
     }
     try {
         $user = $this->getUserProvider($class)->loadUserByUsername($username);
     } catch (\Exception $ex) {
         if (!$ex instanceof AuthenticationException) {
             $ex = new AuthenticationException($ex->getMessage(), $ex->getCode(), $ex);
         }
         throw $ex;
     }
     if (!$user instanceof UserInterface) {
         throw new \RuntimeException(sprintf('The UserProviderInterface implementation must return an instance of UserInterface, but returned "%s".', get_class($user)));
     }
     if (true !== $this->compareHashes($hash, $this->generateCookieHash($class, $username, $expires, $user->getPassword()))) {
         throw new AuthenticationException('The cookie\'s hash is invalid.');
     }
     if ($expires < time()) {
         throw new AuthenticationException('The cookie has expired.');
     }
     return $user;
 }
開發者ID:Viduc,項目名稱:tiremoidlaold,代碼行數:31,代碼來源:TokenBasedRememberMeServices.php

示例8: onAuthenticationFailure

 /**
  * {@inheritdoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $result = array('success' => false, 'message' => $exception->getMessage());
         return new JsonResponse($result);
     }
 }
開發者ID:modera,項目名稱:foundation,代碼行數:10,代碼來源:Authenticator.php

示例9: onAuthenticationFailure

 /**
  * This is called when an interactive authentication attempt fails. This is
  * called by authentication listeners inheriting from
  * AbstractAuthenticationListener.
  *
  * @param Request                 $request
  * @param AuthenticationException $exception
  *
  * @return Response The response to return, never null
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $session = $this->entityManager->getRepository('BDNUserBundle:Session')->createBlock($request->getClientIp());
     $this->entityManager->persist($session);
     $this->entityManager->flush();
     return new JsonResponse(['result' => $exception->getMessage()], 401);
 }
開發者ID:Parabot,項目名稱:BDN-V3,代碼行數:17,代碼來源:AuthenticationListener.php

示例10: handle

 public function handle(GetResponseEvent $event)
 {
     // Don't do anything when the auto_login query parameter is not found
     if (!($autoLogin = $event->getRequest()->get('auto_login', false))) {
         return;
     }
     # Decode the parameter and split into username and key.
     $autoLogin = base64_decode($autoLogin);
     list($username, $autoLoginKey) = explode(':', $autoLogin);
     # Find the user in the user provider for the given class
     try {
         $user = $this->userProvider->loadUserByUsername($username);
     } catch (\Exception $ex) {
         if (!$ex instanceof AuthenticationException) {
             $ex = new AuthenticationException($ex->getMessage(), $ex->getCode(), $ex);
         }
         throw $ex;
     }
     // Try and authenticate the token
     try {
         $token = $this->authenticationManager->authenticate(new AutoLoginToken($user, $this->providerKey, $autoLoginKey));
     } catch (AuthenticationException $e) {
         return;
     }
     // If everything is ok, store the received authenticated token
     if ($token) {
         $this->tokenStorage->setToken($token);
     }
 }
開發者ID:jaytaph,項目名稱:symfony-security-autologin,代碼行數:29,代碼來源:AutoLoginListener.php

示例11: onAuthenticationFailure

 /**
  * This is called when an interactive authentication attempt fails. This is
  * called by authentication listeners inheriting from
  * AbstractAuthenticationListener.
  *
  * @param Request                 $request
  * @param AuthenticationException $exception
  * @return Response the response to return
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $response = $this->rf->getErrorResponse();
     $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
     $response->setErrors(array('message' => $exception->getMessage()));
     $response->setStatusCode(400);
     return $response;
 }
開發者ID:Pulpmedia,項目名稱:PulpmediaNgHttpBundle,代碼行數:17,代碼來源:AuthenticationHandler.php

示例12: onAuthenticationFailure

 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest() || $request->getRequestFormat() !== 'html') {
         $json = array('code' => 401, 'message' => $this->translator->trans($exception->getMessage()));
         return new Response(json_encode($json), 401);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
開發者ID:geoffreytran,項目名稱:zym,代碼行數:11,代碼來源:AjaxAuthenticationFailureHandler.php

示例13: onAuthenticationFailure

 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $json = array('has_error' => true, 'error' => $exception->getMessage());
         return new JsonResponse($json);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
開發者ID:ngydat,項目名稱:CoreBundle,代碼行數:11,代碼來源:AjaxAuthenticationFailureHandler.php

示例14: onAuthenticationFailure

 /**
  * onAuthenticationFailure
  *
  * @author     Joe Sexton <joe@webtipblog.com>
  * @param     Request $request
  * @param     AuthenticationException $exception
  * @return     Response
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $this->logger->warning(sprintf('%s.[%s].%s.[%s] => %s', 'AuthenticationFailure', 'This user fail to connect', $request->getClientIp(), $exception->getCode(), $exception->getMessage()));
     if ($request->isXmlHttpRequest()) {
         $array = array('success' => false, 'message' => $exception->getMessage());
         $response = new Response(json_encode($array));
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     } else {
         if ($request->headers->get('Referer')) {
             $request->getSession()->set(SecurityContextInterface::AUTHENTICATION_ERROR, $exception);
             return new RedirectResponse($request->headers->get('Referer'));
         } else {
             throw new AuthenticationException("No route used before");
         }
     }
 }
開發者ID:RomainMarecat,項目名稱:purchase_order,代碼行數:25,代碼來源:AuthenticationFailureHandlerService.php

示例15: onAuthenticationFailure

 /**
  * {@inheritDoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         $response = new JsonResponse(array('code' => 400, 'message' => $exception->getMessage()));
     } else {
         $response = parent::onAuthenticationFailure($request, $exception);
     }
     return $response;
 }
開發者ID:omidnematollahi,項目名稱:StoreRepo,代碼行數:12,代碼來源:AuthenticationFailureHandler.php


注:本文中的Symfony\Component\Security\Core\Exception\AuthenticationException::getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。