当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception\AuthenticationException类代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\Exception\AuthenticationException的典型用法代码示例。如果您正苦于以下问题:PHP AuthenticationException类的具体用法?PHP AuthenticationException怎么用?PHP AuthenticationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AuthenticationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: start

 public function start(Request $request, AuthenticationException $authException = null)
 {
     $apiProblem = new ApiProblem(Response::HTTP_UNAUTHORIZED);
     $message = $authException ? $authException->getMessageKey() : 'Missing credentials';
     $apiProblem->set('detail', $message);
     return $this->responseFactory->createResponse($apiProblem);
 }
开发者ID:C3-TKO,项目名称:smash-api,代码行数:7,代码来源:JWTTokenAuthenticator.php

示例2: 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

示例3: 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

示例4: 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

示例5: onAuthenticationFailure

 /**
  * {@inheritdoc}
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['success' => false, 'message' => $exception->getMessageKey()], 401);
     }
     return parent::onAuthenticationFailure($request, $exception);
 }
开发者ID:gabiudrescu,项目名称:Sylius,代码行数:10,代码来源:AuthenticationFailureHandler.php

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: authenticate

 /**
  * Attempts to authenticate a TokenInterface object.
  *
  * @param TokenInterface $token The TokenInterface instance to authenticate
  *
  * @return TokenInterface An authenticated TokenInterface instance, never null
  *
  * @throws AuthenticationException if the authentication fails
  */
 public function authenticate(TokenInterface $token)
 {
     if (false === $this->supports($token)) {
         return null;
     }
     /** @var SamlSpResponseToken $token */
     $user = null;
     try {
         $user = $this->loadUser($token);
     } catch (UsernameNotFoundException $ex) {
         $user = $this->createUser($token);
     }
     if (null == $user && $this->force) {
         $user = $this->createDefaultUser($token);
     }
     if (null == $user) {
         $ex = new AuthenticationException('Unable to resolve user');
         $ex->setToken($token);
         throw $ex;
     }
     if ($this->userChecker && $user instanceof UserInterface) {
         $this->userChecker->checkPostAuth($user);
     }
     $attributes = $this->getAttributes($token);
     $result = new SamlSpToken($user instanceof UserInterface ? $user->getRoles() : [], $this->providerKey, $attributes, $user);
     return $result;
 }
开发者ID:BernardoSilva,项目名称:SpBundle,代码行数:36,代码来源:LightsSamlSpAuthenticationProvider.php

示例14: onAuthenticationFailure

 /**
  * NOTE: I chose to throw an HTTP Exception here to let the response be rendered elsewhere -
  *       separation of concerns and all... You could always return a JsonResponse here.
  */
 public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
 {
     $message = 'Invalid Credentials';
     if ($exception instanceof CustomUserMessageAuthenticationException) {
         $message = $exception->getMessageKey();
     }
     throw new HttpException(401, $message);
 }
开发者ID:tuimedia,项目名称:forum,代码行数:12,代码来源:JWTAuthenticator.php

示例15: 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


注:本文中的Symfony\Component\Security\Core\Exception\AuthenticationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。