Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

php - Silex SecurityServiceProvider throws 'Identifier "security.authentication_providers" is not defined.'

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 SilexProviderSecurityServiceProvider());

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 SilexProviderTwigServiceProvider(), array(
    'twig.path' => sprintf("%s/../views", __DIR__),
));

// Security service

$app["security.firewalls"] = array();
$app->register(new SilexProviderSecurityServiceProvider());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...