/** * {@InheritDoc} */ protected function attemptAuthentication(Request $request) { $username = $request->get('_username', null, true); $request->getSession()->set(Security::LAST_USERNAME, $username); $token = new ChoiceAuthToken(); $token->setUsername($username); $token->setProviderKey($this->providerKey); return $this->authenticationManager->authenticate($token); }
public function authenticate(TokenInterface $token) { $user = $this->userProvider->loadUserByUsername($token->getUsername()); if (!$user) { throw new AuthenticationException('The authentication failed.'); } $authenticatedToken = new ChoiceAuthToken($user->getRoles()); $authenticatedToken->setAttributes($token->getAttributes()); $authenticatedToken->setUser($user); $authenticatedToken->setProviderKey($this->providerKey); $authenticatedToken->setAuthenticated(true); return $authenticatedToken; }