安全性 – Check_path不在symfony的防火墙后面,如何解决这个问题?

我正在尝试对symfony2防火墙进行身份验证,这是我的安全配置

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    providers:
        in_memory:
            users:
                user:  { password: user, roles: [ 'ROLE_USER' ] }
                admin: { password: admin, roles: [ 'ROLE_ADMIN' ]}
        #main:
            #entity: { class: Surgeworks\CoreBundle\Entity\User, property: username}
    firewalls:
        public:
           pattern: .*
           security: false
           anonymous: true
           form_login:
                check_path: /{_locale}/admin/logincheck
        login:
           pattern: ^/{_locale}/admin/login$
           security: false
           anonymous:  ~
        dev:
           pattern:  ^/(_(profiler|wdt)|css|images|js)/
           security: false
           anonymous:  ~
        secured_area :
            provider:   in_memory
            pattern: ^/{_locale}/admin/.*
            form_login:
                check_path: /{_locale}/admin/logincheck
                login_path: /{_locale}/admin/login
            logout:
                path : /{_locale}/admin/logout
                target : /{_locale}/admin/
            remember_me:
               key:      aSecretKey
               lifetime: 3600
               path:     /admin/
               domain:   ~ # Defaults to the current domain from $_SERVER 
    access_control:
        - { path: ^/{_locale}/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/{_locale}/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/ar/admin/logincheck, roles: ROLE_ADMIN }
        - { path: ^/(ar|en|fr)/admin/, roles: ROLE_ADMIN }

这是我在DaghoSiteBundle / Resources / config / routing.yml中的路由:

_admin:
    pattern: /admin/
    defaults: { _controller: DaghoSiteBundle:Login:login , _locale : ar }
    requirements:
     _locale: (ar|en|fr)
login:
    pattern: /admin/login
    defaults : { _controller: DaghoSiteBundle:Login:login , _locale : ar }
    requirements:
        _locale: (ar|en|fr)
logincheck:
    pattern: /admin/logincheck
    #defaults: { _controller: DaghoSiteBundle:Login:logincheck , _locale: ar }
    #requirements:
        #_locale: (ar|en|fr)
logout:
    pattern: /admin/logout

我无法通过这些设置登录,
它总是抛出异常

Unable to find the controller for path “/ar/admin/logincheck”. Maybe
you forgot to add the matching route in your routing configuration

即使设置了路径check_path页面>>我可以在不重定向到登录页面的情况下查看check_path.

/en/admin >> login page 
/en/logincheck >> display the logincheck template (i.e  /en/logincheck isn't behind firewall )

如何解决或调试此问题,请指教

更新:
对不起,我可能会忘记写道,我已经使用{_locale}这样的前缀
在我的routing.yml中

DaghoSiteBundle:
    resource: "@DaghoSiteBundle/Resources/config/routing.yml"
    prefix:   /{_locale}
    requirements:
        _locale: ar|en|fr
    defaults: { _locale: ar }

最佳答案 我认为您必须更改路由模式以包含_locale参数.而不是,例如,模式:/ admin / logincheck你应该使用模式:{_locale} / admin / logincheck

您还可以使用控制台命令app / console router调试路由:debug.

我并非100%确定这可以解决您的问题,但我希望它可以帮助您收集有关您的问题的更多信息.

点赞