Skip to content

Instantly share code, notes, and snippets.

@kwisatz
Last active August 29, 2015 14:02
Show Gist options
  • Save kwisatz/5242e1612ece39489269 to your computer and use it in GitHub Desktop.
Save kwisatz/5242e1612ece39489269 to your computer and use it in GitHub Desktop.
Trying to get a Simple_preauth listener for symfony security working…
<?php
/**
* ApiKeyAuthenticator for the Symfony Security Component
*/
namespace Ttf\Security\Provider;
use Silex\Application,
Silex\ServiceProviderInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Ttf\Mapping\User,
Ttf\Security\ApiKeyAuthenticator,
Ttf\Security\Provider\ApiKeyUserProvider;
class ApiKeyAuthenticationServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['apikey.authenticator'] = $app->protect(function () use ($app) {
return new ApiKeyAuthenticator(new ApiKeyUserProvider($app['user.repository']));
});
$app['security.authentication_listener.factory.simple_preauth'] = $app->protect(function ($name, $options) use ($app) {
if (!isset($app['security.authentication_provider.'.$name.'.dao'])) {
$app['security.authentication_provider.'.$name.'.dao'] = $app['security.authentication_provider.dao._proto']($name);
}
$app['security.authentication_listener.' . $name . '.simple_preauth'] = $app->share(function () use ($app, $name, $options) {
return new SimplePreAuthenticationListener(
$app['security'],
$app['security.authentication_manager'],
$name,
$options['authenticator'](),
$app['logger']
);
});
return array(
'security.authentication_provider.'.$name.'.dao',
'security.authentication_listener.'.$name.'.simple_preauth',
null, // entrypoint
'pre_auth' // position of the listener in the stack
);
});
return true;
}
public function boot(Application $app)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment