简体   繁体   English

Symfony2.1:无法找到路径“/ login_check”的控制器

[英]Symfony2.1: Unable to find the controller for path “/login_check”

I used the "Using a traditional login form" tutorial from symfony.com to authentificate my users. 我使用symfony.com的“使用传统登录表单”教程来验证我的用户身份。 With a simple http auth it works great. 使用简单的http auth,它可以很好地工作。

After the login was submitted I get this Exception: 提交登录后,我得到以下异常:

Unable to find the controller for path "/login_check". 无法找到路径“/ login_check”的控制器。 Maybe you forgot to add the matching route in your routing configuration? 也许您忘了在路由配置中添加匹配路由?

Well, in the tutorial I read: 好吧,在教程中我读到:

You will not need to implement a controller for the /login_check URL as the firewall will automatically catch and process any form submitted to this URL. 您不需要为/ login_check URL实现控制器,因为防火墙将自动捕获并处理提交到此URL的任何表单。

I defined the routes and set the firewall settings: 我定义了路由并设置了防火墙设置:

security.yml security.yml

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    backend:
        pattern:    ^/backend
        anonymous: ~
        form_login:
            provider: entity
            login_path: /login
            check_path: /login_check
            #use_forward: true
        logout:
            path:   /logout
            target: /

routing.yml 使用routing.yml

login:
    pattern:   /login
    defaults:  { _controller: VitaSecurityBundle:Default:login }
login_check:
    pattern:   /login_check
logout:
    pattern:   /logout

The problem you are having is described here: 您遇到的问题在这里描述:

See http://symfony.com/doc/current/book/security.html , section "Avoid Common Pitfalls" 请参阅http://symfony.com/doc/current/book/security.html ,“避免常见陷阱”部分

  1. Be sure /login_check is behind a firewall Next, make sure that your check_path URL (eg /login_check) is behind the firewall you're using for your form login (in this example, the single firewall matches all URLs, including /login_check). 确保/login_check位于防火墙后面接下来,确保check_path URL(例如/ login_check)位于您用于表单登录的防火墙后面(在此示例中,单个防火墙匹配所有URL,包括/ login_check)。 If /login_check doesn't match any firewall, you'll receive a Unable to find the controller for path "/login_check" exception. 如果/ login_check与任何防火墙都不匹配,您将收到无法找到路径“/ login_check”异常的控制器。

In this example, your pattern specifies a prefix of /backend for secured paths. 在此示例中,您的模式为安全路径指定/ backend的前缀。 To work, your login check should be behind this same firewall. 要运行,您的登录检查应该在同一个防火墙后面。

So, to match the pattern which you have specified in your firewall, put login_check on a url path like this: /backend/login_check 因此,要匹配您在防火墙中指定的模式,请将login_check放在url路径上,如下所示:/ backend / login_check

I found the solution to my problem 我找到了解决问题的方法

I added the /backend prefix to my paths, removed the 'anonymous: ~' line and commented out the ACL for backend. 我将/ backend前缀添加到我的路径中,删除了'anonymous:〜'行并注释掉后端的ACL。

security.yml security.yml

    firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    login_firewall:
        pattern:    ^/backend/login$
        anonymous:  ~
    backend:
        pattern:    ^/backend
        form_login:
            provider: entity
            login_path: /backend/login
            check_path: /backend/login_check
            #use_forward: true
        logout:
            path:   /backend/logout
            target: /

access_control:
    #- { path: ^/backend, roles: ROLE_USER }

routing.yml 使用routing.yml

login:
    pattern:   /backend/login
    defaults:  { _controller: VitaSecurityBundle:Default:login }
login_check:
    pattern:   /backend/login_check
logout:
    pattern:   /backend/logout

The problem also tends to happen when you have two firewall with the same pattern. 当您有两个具有相同模式的防火墙时,也会发生此问题。 For example: 例如:

....
 backend:
            pattern:        ^/*
....
 frontend:
            pattern:        ^/*

You must change one of the two as follows: 您必须按如下方式更改其中一个:

....
 backend:
            pattern:        ^/(administrador|backend)/*
....
frontend:
            pattern:        ^/*

Here is a sample code I used in a real-life project: 以下是我在现实生活中使用的示例代码:

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    secured_area:
        pattern:    ^/cmd
        anonymous: ~
        form_login:
            check_path: /cmd/login_check
            login_path: /cmd/login
        remember_me:
            always_remember_me: true
            key:      "%secret%"
            path:     /cmd
            domain:   ~ # Defaults to the current domain from $_SERVER
        logout:
            path:   /cmd/logout
            target: /

    admin:
        pattern: ^/admin
        http_basic:
            realm: "Administration"

    free_area:
        pattern: ^/
        anonymous: ~

In my case, only the /cmd/ part is secured, the /admin/ part is also secured, but with HTTP security. 在我的例子中,只有/ cmd / part是安全的,/ admin / part也是安全的,但具有HTTP安全性。

Maybe you should try: security.yml 也许你应该尝试:security.yml

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    backend:
        pattern:    ^/backend
        anonymous: ~
        form_login:
            provider: entity
            login_path: /backend/login
            check_path: /backend/login_check
            #use_forward: true
        logout:
            path:   /backend/logout
            target: /

and as of routing.yml: 和routing.yml一样:

login:
    pattern:   /backend/login
    defaults:  { _controller: VitaSecurityBundle:Default:login }
login_check:
    pattern:   /backend/login_check
logout:
    pattern:   /backend/logout

I think your problem might come from the fact security is not activated in your / part (the pattern of your secured area is ^/backend) 我认为您的问题可能来自于您的/部分未激活安全性(您的安全区域的模式是^ / backend)

This was not workging for me and I try something else : 这不适合我,我尝试别的东西:

firewalls:
    dev:
        pattern:    ^/(_profiler|_wdt|css|js)
        security:   false

    login:
        pattern: ^/login$
        security: false

    secured_area:
        pattern: /(admin/.*|login_check)
        provider: in_memory
        form_login:
            check_path: /login_check
            login_path: /login
            default_target_path: /admin
            always_use_default_target_path: true
        logout:
            path:   /logout
            target: /

access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, roles: ROLE_ADMIN }

With the following explanation, simpler than the explanation from zabojad. 有了以下解释,比zabojad的解释简单。 The important thing is to put the login_check route inside a firewall and to let the login outside. 重要的是将login_check路由放在防火墙内并让登录到外面。 With a or pattern you can succeed. 使用或模式,您可以成功。

Max 马克斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法找到路径“/ login_check”的控制器 - symfony2 - Unable to find the controller for path “/login_check” - symfony2 Symfony 2无法找到路径/ login_check的控制器 - Symfony 2 Unable to find the controller for path /login_check 无法找到路径“/ login_check”的控制器 - Unable to find the controller for path “/login_check” Symfony登录尽管位于防火墙后仍无法找到路径login_check的控制器 - Symfony login unable to find controller for path login_check despite being behind firewall Symfony2:找不到路径“ / api / login_check”的控制器。 路由配置错误 - Symfony2 : Unable to find the controller for path “/api/login_check”. The route is wrongly configured 错误:无法找到路径“/login_check”的控制器。 路由配置错误。 (LexikJWTAuthentication) - Error: Unable to find the controller for path "/login_check". The route is wrongly configured. (LexikJWTAuthentication) 带有Sf4的Lexik JWT身份验证:未捕获的异常:无法找到路径“ / login_check”的控制器 - Lexik JWT Authentification with Sf4 : Uncaught Exception: Unable to find the controller for path “/login_check” 从 symfony 4.4 截取 login_check 路径 - Intercept the login_check path from symfony 4.4 找不到Symfony2身份验证“ login_check”路径 - Symfony2 Authentication “login_check” path not found Symfony 3.3无法找到路径“ / login / check”的控制器。 路由配置错误 - Symfony 3.3 Unable to find the controller for path “/login/check”. The route is wrongly configured
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM