From fdff03e0f6f527fdc37c9a20bd9f54331c3412de Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 30 Jan 2012 11:15:07 -0700 Subject: [PATCH 1/2] fixes "A Token was not found in the SecurityContext" error --- .../custom_authentication_provider.rst | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index 66beba564d6..01f7c1f2737 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -116,30 +116,29 @@ set an authenticated token in the security context if successful. { $request = $event->getRequest(); - if (!$request->headers->has('x-wsse')) { - return; - } + if ($request->headers->has('x-wsse')) { - $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; + $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/'; - if (preg_match($wsseRegex, $request->headers->get('x-wsse'), $matches)) { - $token = new WsseUserToken(); - $token->setUser($matches[1]); + 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]; + $token->digest = $matches[2]; + $token->nonce = $matches[3]; + $token->created = $matches[4]; - try { - $returnValue = $this->authenticationManager->authenticate($token); + try { + $returnValue = $this->authenticationManager->authenticate($token); - if ($returnValue instanceof TokenInterface) { - return $this->securityContext->setToken($returnValue); - } else if ($returnValue instanceof Response) { - return $event->setResponse($returnValue); + if ($returnValue instanceof TokenInterface) { + return $this->securityContext->setToken($returnValue); + } else if ($returnValue instanceof Response) { + return $event->setResponse($returnValue); + } + } catch (AuthenticationException $e) { + // you might log something here } - } catch (AuthenticationException $e) { - // you might log something here } } From f62b6466efdeb25d2b6838726f93fbfa7f7fe8ce Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 31 Jan 2012 09:23:41 -0700 Subject: [PATCH 2/2] Removes deprecated 'security_factories' directive in the cookbook article in favor of adding the extension in the Bundle. --- .../custom_authentication_provider.rst | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index 01f7c1f2737..85166210c57 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -427,35 +427,27 @@ factory service, tagged as ``security.listener.factory``: -Now, import the factory configuration via the the ``factories`` key in your -security configuration: +As a final step, add the factory to the security extension in your bundle class. -.. configuration-block:: - - .. code-block:: yaml - - # app/config/security.yml - security: - factories: - - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.yml" +.. code-block:: php - .. code-block:: xml + // src/Acme/DemoBundle/AcmeDemoBundle.php + namespace Acme\DemoBundle; - - - - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.xml - - + use Acme\DemoBundle\DependencyInjection\Security\Factory\WsseFactory; + use Symfony\Component\HttpKernel\Bundle\Bundle; + use Symfony\Component\DependencyInjection\ContainerBuilder; - .. code-block:: php + class AcmeDemoBundle extends Bundle + { + public function build(ContainerBuilder $container) + { + parent::build($container); - // app/config/security.php - $container->loadFromExtension('security', array( - 'factories' => array( - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.php" - ), - )); + $extension = $container->getExtension('security'); + $extension->addSecurityListenerFactory(new WsseFactory()); + } + } You are finished! You can now define parts of your app as under WSSE protection. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy