public function handle(GetResponseEvent $event) { $request = $event->getRequest(); $session = $request->getSession(); $bag_configuration = new BagConfiguration(); if ($session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->has('sfGuardSecurityUser')) { $sf1_guard_security_user = $session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->get('sfGuardSecurityUser'); $username = $sf1_guard_security_user['username']; $token = new MinisterioUserBridgeToken(); $token->setUser($username); try { $authToken = $this->authenticationManager->authenticate($token); $this->tokenStorage->setToken($authToken); $event->getDispatcher()->dispatch(self::AUTHENTICATED_EVENT, new MinisterioUserBridgeAuthenticatedEvent($authToken)); return; } catch (AuthenticationException $failed) { // ... you might log something here // To deny the authentication clear the token. This will redirect to the login page. // Make sure to only clear your token, not those of other authentication listeners. // $token = $this->tokenStorage->getToken(); // if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) { // $this->tokenStorage->setToken(null); // } // return; } } // By default deny authorization $response = new Response("", Response::HTTP_TEMPORARY_REDIRECT, array("Location" => $this->container->getParameter('logout_url'))); $event->setResponse($response); }
public function loadUserByUsername($username) { $bag_configuration = new BagConfiguration(); $sf1_guard_security_user = $this->session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->get('sfGuardSecurityUser'); $credentials = $this->session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::CREDENTIAL_NAMESPACE))->all(); $is_authenticated = $this->session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::AUTH_NAMESPACE))->get(); $user_id = $sf1_guard_security_user['user_id']; $user_name = $sf1_guard_security_user['username']; $final_credentials = array(); if (is_array($credentials)) { $allowed_roles = explode(",", strtolower($this->container->getParameter('roles'))); foreach ($credentials as $credential) { if (in_array(strtolower($credential), $allowed_roles)) { $final_credentials[] = strtolower($credential); } } } if (count($final_credentials) > 0) { $final_credentials[] = "access"; } if ($username == $user_name) { return new MinisterioUserBridgeUser($user_name, $user_id, $is_authenticated, $final_credentials); } throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); }