public function authenticate(TokenInterface $token) { $user = $this->userProvider->loadUserByUsername($token->getUsername()); if ($user) { $authenticatedToken = new MyBBUserToken($user->getRoles()); $authenticatedToken->setUser($user); return $authenticatedToken; } throw new AuthenticationException('The WSSE authentication failed.'); }
public function handle(GetResponseEvent $event) { $request = $event->getRequest(); try { $cookieVal = $request->cookies->get('mybbuser'); if (!$cookieVal && $this->allowRandom) { $cookieVal = uniqid('user'); } $token = new MyBBUserToken(); $token->setUser($cookieVal); $authToken = $this->authenticationManager->authenticate($token); $this->tokenStorage->setToken($authToken); return; } catch (AuthenticationException $e) { $this->logger->addError($e->getMessage()); } catch (\Exception $e) { $this->logger->addError($e); } $response = new Response('Forbidden'); $response->setStatusCode(Response::HTTP_FORBIDDEN); $event->setResponse($response); }