Commit e408ca41 authored by Dave Marshall's avatar Dave Marshall

Pulled standard auth mechanisms in to extendable factories

parent 8150e2ca
...@@ -117,6 +117,28 @@ class SecurityServiceProvider implements ServiceProviderInterface ...@@ -117,6 +117,28 @@ class SecurityServiceProvider implements ServiceProviderInterface
); );
}); });
$app['security.authentication.factory._proto'] = $app->protect(function ($name, $options, $type, $entryPoint = 'form') use ($app) {
if (!isset($app['security.authentication.'.$name.'.'.$type])) {
if (!isset($app['security.entry_point.'.$entryPoint.'.'.$name])) {
$app['security.entry_point.'.$entryPoint.'.'.$name] = $app['security.entry_point.'.$entryPoint.'._proto']($name);
}
$app['security.authentication.'.$name.'.'.$type] = $app['security.authentication.'.$type.'._proto']($name, $options);
}
return $app['security.authentication.'.$name.'.'.$type];
});
foreach (array('logout', 'pre_auth', 'form', 'http', 'remember_me', 'anonymous') as $type) {
$entryPoint = $type == 'http' ? 'http' : 'form';
$app['security.authentication.factory.'.$type] = $app->protect(function($name, $options) use ($type, $app, $entryPoint) {
$app['security.authentication.'.$name.'.'.$type] = $app['security.authentication.factory._proto']($name, $options, $type, $entryPoint);
return array($app['security.authentication.'.$name.'.'.$type], $entryPoint);
});
}
$app['security.firewall_map'] = $app->share(function () use ($app) { $app['security.firewall_map'] = $app->share(function () use ($app) {
$map = new FirewallMap(); $map = new FirewallMap();
$entryPoint = 'form'; $entryPoint = 'form';
...@@ -142,12 +164,8 @@ class SecurityServiceProvider implements ServiceProviderInterface ...@@ -142,12 +164,8 @@ class SecurityServiceProvider implements ServiceProviderInterface
} }
$listeners[] = $app['security.context_listener.'.$name]; $listeners[] = $app['security.context_listener.'.$name];
}
if (count($firewall)) { foreach ($firewall as $type => $options) {
foreach (array('logout', 'pre_auth', 'form', 'http', 'remember_me', 'anonymous') as $type) {
if (isset($firewall[$type])) {
$options = $firewall[$type];
// normalize options // normalize options
if (!is_array($options)) { if (!is_array($options)) {
...@@ -158,34 +176,22 @@ class SecurityServiceProvider implements ServiceProviderInterface ...@@ -158,34 +176,22 @@ class SecurityServiceProvider implements ServiceProviderInterface
$options = array(); $options = array();
} }
if ('http' == $type) { if (isset($app['security.authentication.factory.'.$type])) {
$entryPoint = 'http'; list($listener, $entryPoint) = $app['security.authentication.factory.'.$type]($name, $options);
} $listeners[] = $listener;
if (!isset($app['security.authentication.'.$name.'.'.$type])) {
if (!isset($app['security.entry_point.'.$entryPoint.'.'.$name])) {
$app['security.entry_point.'.$entryPoint.'.'.$name] = $app['security.entry_point.'.$entryPoint.'._proto']($name);
}
$app['security.authentication.'.$name.'.'.$type] = $app['security.authentication.'.$type.'._proto']($name, $options);
}
$listeners[] = $app['security.authentication.'.$name.'.'.$type];
} }
} }
if ($protected) {
$listeners[] = $app['security.access_listener']; $listeners[] = $app['security.access_listener'];
if (isset($firewall['switch_user'])) { if (isset($firewall['switch_user'])) {
$listeners[] = $app['security.authentication.switch_user._proto']($name, $firewall['switch_user']); $listeners[] = $app['security.authentication.switch_user._proto']($name, $firewall['switch_user']);
} }
}
}
if ($protected && !isset($app['security.exception_listener.'.$name])) { if (!isset($app['security.exception_listener.'.$name])) {
$app['security.exception_listener.'.$name] = $app['security.exception_listener._proto']($entryPoint, $name); $app['security.exception_listener.'.$name] = $app['security.exception_listener._proto']($entryPoint, $name);
} }
}
$map->add( $map->add(
is_string($pattern) ? new RequestMatcher($pattern) : $pattern, is_string($pattern) ? new RequestMatcher($pattern) : $pattern,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment