/** * Handles basic authentication. * * @param GetResponseEvent $event A GetResponseEvent instance */ public function handle(GetResponseEvent $event) { $request = $event->getRequest(); if (false === ($username = $request->headers->get('PHP_AUTH_USER', false))) { return; } if (null !== ($token = $this->securityContext->getToken())) { if ($token instanceof OrganizationContextTokenInterface && $token->isAuthenticated() && $token->getUsername() === $username) { return; } } $this->logProcess($username); try { $organizationId = $request->headers->get('PHP_AUTH_ORGANIZATION'); if ($organizationId) { $authToken = new UsernamePasswordOrganizationToken($username, $request->headers->get('PHP_AUTH_PW'), $this->providerKey, $this->manager->getOrganizationById($organizationId)); } else { $authToken = new UsernamePasswordToken($username, $request->headers->get('PHP_AUTH_PW'), $this->providerKey); } $this->securityContext->setToken($this->authenticationManager->authenticate($authToken)); } catch (AuthenticationException $failed) { $token = $this->securityContext->getToken(); if ($token instanceof UsernamePasswordToken && $this->providerKey === $token->getProviderKey()) { $this->securityContext->setToken(null); } $this->logError($username, $failed->getMessage()); if ($this->ignoreFailure) { return; } $event->setResponse($this->authenticationEntryPoint->start($request, $failed)); } }
public function handle(GetResponseEvent $event) { $request = $event->getRequest(); //find out if the current request contains any information by which the user might be authenticated if (!$request->headers->has('X-WSSE')) { return; } $ae_message = null; $this->wsseHeader = $request->headers->get('X-WSSE'); $wsseHeaderInfo = $this->parseHeader(); if ($wsseHeaderInfo !== false) { $token = new Token($wsseHeaderInfo['Username'], $wsseHeaderInfo['PasswordDigest'], $this->providerKey); $token->setAttribute('nonce', $wsseHeaderInfo['Nonce']); $token->setAttribute('created', $wsseHeaderInfo['Created']); try { $returnValue = $this->authenticationManager->authenticate($token); if ($returnValue instanceof TokenInterface) { return $this->tokenStorage->setToken($returnValue); } else { if ($returnValue instanceof Response) { return $event->setResponse($returnValue); } } } catch (AuthenticationException $ae) { $event->setResponse($this->authenticationEntryPoint->start($request, $ae)); } } }
/** * {@inheritDoc} */ public function handle(GetResponseEvent $event) { $request = $event->getRequest(); // Requests require an Authorization header. if (!$request->headers->has('Authorization')) { $event->setResponse($this->entryPoint->start($request)); return; } $token = new HmacToken($request); try { $authToken = $this->authManager->authenticate($token); $this->tokenStorage->setToken($authToken); $request->attributes->set('hmac.key', $authToken->getCredentials()); } catch (AuthenticationException $e) { $event->setResponse($this->entryPoint->start($request, $e)); } }