Esempio n. 1
0
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $wsseRegex = '/ApiKey="([^"]+)"/';
     $pregmatchCactcumajonejsaqer = preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches);
     if (!$request->headers->has('x-wsse') || 1 !== preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) {
         return FALSE;
     }
     $token = new WsseUserToken();
     $token->setUser($matches[1]);
     try {
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($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->securityContext->getToken();
         // if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
         //     $this->securityContext->setToken(null);
         // }
         // return;
     } catch (\Symfony\Component\Security\Core\Exception\NonceExpiredException $failed) {
     }
     // By default deny authorization
     $response = new Response();
     $response->setStatusCode(403);
     $event->setResponse($response);
 }
Esempio n. 2
0
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user) {
         $authenticatedToken = new WsseUserToken($user->getRoles());
         $authenticatedToken->setUser($user);
         return $authenticatedToken;
     }
     throw new AuthenticationException('The WSSE authentication failed.');
 }