dstnlhhv791576 2013-08-02 17:34
浏览 56
已采纳

Silex SecurityServiceProvider抛出'Identifier'security.authentication_providers“未定义。”

I can't figure out how to use SecurityServiceProvider in Silex. My configuration is:

$app['security.firewalls'] = array(
    'admin' => array(
        'pattern' => '^/_admin/.+',
        'form' => array('login_path' => '/_admin/', 'check_path' => '/_admin/login_check'),
        'logout' => array('logout_path' => '/_admin/logout'),
        'users' => array(
            'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsR...'),
        ),
    ),
);
$app->register(new Silex\Provider\SecurityServiceProvider());

This just throws:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "security.authentication_providers" is not defined.'

According to the documentation in some cases when you want to access Security features outside of the handling of a request you have to call $app->boot(); but this isn't my situation.
If I call $app->boot(); before $app->register(...) it doesn't raise any exception but it probably doesn't boot at all because then in generating login form Twig throws:

Unable to generate a URL for the named route "_admin_login_check" as such route does not exist.

There's an issue a few months ago with probably the same problem but it's closed so I guess it should be fixed now

  • 写回答

3条回答 默认 最新

  • douchengjue9892 2013-12-23 18:07
    关注

    I was getting the same exception when trying to register the SecurityServiceProvider before the TwigServiceProvider.

    I just changed the registering order (Security after Twig) and everything started to work fine:

    // Twig service
    
    $app->register(new Silex\Provider\TwigServiceProvider(), array(
        'twig.path' => sprintf("%s/../views", __DIR__),
    ));
    
    // Security service
    
    $app["security.firewalls"] = array();
    $app->register(new Silex\Provider\SecurityServiceProvider());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题