Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 33 additions & 42 deletions cookbook/security/custom_authentication_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -428,35 +427,27 @@ factory service, tagged as ``security.listener.factory``:
</services>
</container>

Now, import the factory configuration via the the ``factories`` key in your
security configuration:

.. configuration-block::
As a final step, add the factory to the security extension in your bundle class.

.. 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;

<!-- app/config/security.xml -->
<config>
<factories>
"%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.xml
</factories>
</config>
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.

Expand Down