我尝试在Symfony 2中创建自定义身份验证提供程序,只是为了好玩。我按照此文档http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html。
我在这做什么:
providers:
facebook_provider:
id: facebook.security.provider
firewalls:
admin_area:
pattern: ^/
facebook:
check_path: /login_check
default_target_path: /
provider: facebook_provider
我使用命名空间Kmelkez \ AuthBundle
创建一个包在命名空间Kmelkez \ AuthBundle \ Security中,我创建自定义文件FacebookFactory,FacebookListener,FacebookProvider,FacebookToken。
我将它们加载到我的services.yml文件中
services:
facebook.security.provider:
class: Kmelkez\AuthBundle\Security\FacebookProvider
abstract_listener:
abstract: true
class: Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener
facebook.security.listener:
class: Kmelkez\AuthBundle\Security\FacebookListener
parent: abstract_listener
最后,在我的工厂定制课程中,现在我保持简单,我打电话给听众&这样的提供者:
class FacebookFactory extends AbstractFactory
{
protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId)
{
$providerID = 'facebook.security.provider' . $id;
return $providerID;
}
protected function getListenerId()
{
return 'facebook.security.listener';
}
public function getPosition()
{
return 'pre_auth';
}
public function getKey()
{
return 'facebook';
}
}
当我转到/ login_check路线时,我有一个例外:
OutOfBoundsException: The index "4" is not in the range [0, -1].
有用的堆栈跟踪:
在Symfony \ Component \ DependencyInjection \ Definition.php中 第255行 at Definition->在Symfony \ Component \ DependencyInjection \ Compiler \ ResolveDefinitionTemplatesPass.php中的replaceArgument('4','admin_area') 第127行 at ResolveDefinitionTemplatesPass> resolveDefinition('facebook.security.listener.admin_area',object(DefinitionDecorator))在Symfony \ Component \ DependencyInjection \ Compiler \ ResolveDefinitionTemplatesPass.php第50行
任何想法?
THX
答案 0 :(得分:4)
最后,我发现了问题:
我的侦听器扩展了一个抽象类:AbstractAuthenticationListener
所以,我编辑services.yml有类似的东西:
facebook.security.listener:
class: Kmelkez\AuthBundle\Security\FacebookListener
parent: security.authentication.listener.abstract #this key is defined in security_listeners.xml
abstract: true