Пример #1
0
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     try {
         $password = $request->get('password');
         $user = $token->getUser();
         AuthSuccessHandler::encryptDataKeyAndPutIntoSession($request, $user, $password, $this->saltKey);
     } catch (Exception $e) {
         $request->getSession()->invalidate();
         throw new AccessDeniedException("Unexpected exception occurred.");
     }
     if ($request->isXmlHttpRequest()) {
         $redirectUrl = $request->getSession()->get('_security.main.target_path');
         return new Response('{' . '"user": {' . '"id":"' . $user->getId() . '",' . '"role":"' . $user->getRole() . '",' . '"username":"******",' . '"isReal":"' . ($user->isReal() ? '1' : '0') . '"' . '},' . '"url":"' . $redirectUrl . '"' . '}');
     }
     return parent::onAuthenticationSuccess($request, $token);
 }
Пример #2
0
 protected function processAutoLoginCookie(array $cookieParts, Request $request)
 {
     $user = parent::processAutoLoginCookie($cookieParts, $request);
     try {
         $hash = $cookieParts[3];
         $key = $this->createKey($hash);
         if ($cookieAppendum = $request->cookies->get($this->options['name'] . '_A')) {
             $this->logger->debug('cookieAppendum with name ' . $this->options['name'] . '_A found.');
             $password = Crypto::decrypt($cookieAppendum, $key);
             AuthSuccessHandler::encryptDataKeyAndPutIntoSession($request, $user, $password, $this->saltKey);
         } else {
             throw new AuthenticationException("Unexpected exception occurred.");
         }
     } catch (Exception $ex) {
         $this->logger->error('unexpected exception occurred, while decrypting the rememberMe cookie' . "\n" . $ex->getTraceAsString());
         throw new AuthenticationException("Unexpected exception occurred.");
     }
     return $user;
 }