public function handle(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->headers->has('x-wsse')) { return; } $wsseRegex = '/UsernameToken Username="******"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; if (preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) { $token = new WsseUserToken(); $token->setUser($matches[1]); $token->digest = $matches[2]; $token->nonce = $matches[3]; $token->created = $matches[4]; try { $returnValue = $this->authenticationManager->authenticate($token); if ($returnValue instanceof TokenInterface) { $result = $this->securityContext->setToken($returnValue); //throw new \Exception($returnValue->getUsername()); return $result; } else { if ($returnValue instanceof Response) { return $event->setResponse($returnValue); } } } catch (\Exception $e) { echo "exception caught " . $e->getMessage(); } } $response = new Response(); $response->setStatusCode(403); $event->setResponse($response); }
public function handle(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->headers->has('x-wsse')) { return; } $wsseHeader = trim($request->headers->get('x-wsse')); if (!strlen($wsseHeader)) { return; } $wsseRegex = '/UsernameToken Username="******"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; if (preg_match($wsseRegex, $wsseHeader, $matches)) { $token = new WsseUserToken(); $token->setUser($matches[1]); $token->digest = $matches[2]; $token->nonce = $matches[3]; $token->created = $matches[4]; try { $returnValue = $this->authenticationManager->authenticate($token); if ($returnValue instanceof TokenInterface) { return $this->securityContext->setToken($returnValue); } else { if ($returnValue instanceof Response) { return $event->setResponse($returnValue); } } } catch (\Exception $e) { //echo "exception caught " . $e->getMessage(); } } $event->setResponse($this->entryPoint->start($request, new AuthenticationException("Foo"))); }
public function authenticate(TokenInterface $token) { $user = $this->userProvider->loadUserByUsername($token->getUsername()); if ($user) { if ($this->validateDigest((string) $token->digest, $token->getUsername(), $token->nonce, $token->created, $user->getAuthSecret())) { $authenticatedToken = new WsseUserToken(array('IS_AUTHENTICATED')); $authenticatedToken->setUser($user); $authenticatedToken->setAuthenticated(TRUE); return $authenticatedToken; } } throw new AuthenticationException('The WSSE authentication failed.'); }