4
votes

I know this is a common problem. And several questions on this topic have been posted. I have tried all those solutions recommended in those questions, but none worked.

I found that this problem occurs if I put my form_login behind a firewall. But I'm not having any extra layer in firewall so the path should be simple as described in documentation.

My security.yml

# app/config/security.yml
security:
    encoders:
        Joy\JoyBundle\Entity\User:
            algorithm:        sha512
            encode_as_base64: true
            iterations:       1

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        administrators:
            entity: { class: JoyBundle:User, property: username }

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

        login:
            pattern:  ^/login
            security: false

        secured_area:
            pattern: ^/
            anonymous: ~
            form_login:
                login_path: login
                check_path: login_check
            logout:
                path:   /logout
                target: /login

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

My routing.yml in app/config

# app/config/routing.yml
login:
    path: /login
    defaults: { _controller: JoyBundle:Security:login }

login_check:
    path: /login_check

joy_hello:
    resource: "@JoyBundle/Resources/config/routing.yml"
    prefix: /

So I'm performing login check while accessing app_dev.php/ But it's showing that error after pressing submit in login form.

Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration? 404 Not Found - NotFoundHttpException

I tried

login_path: /login
check_path: /login_check

Didn't work. What I'm missing ?? Please help.....

2
what does php app/console router:debug says? - Flask
@Flask I'm new to symfony2. So don't know all the meanings. Giving that command shows a list of name,method,scheme,host,path. And in that list there is login_check ANY ANY ANY /login_check - AtanuCSE
login_check: path: /login_check set a default controller and action - sas
@crack where?? my routing.yml already contains login_check: path: /login_check - AtanuCSE
are you using fosuserbundle? - sas

2 Answers

6
votes

The route login_check is not behind the firewall because the login_check route pattern matches the login firewall which has no security.

login:
    pattern:  ^/login     # This matches /login_check
    security: false

Solution 1: Change this to

login:
    pattern:  ^/login$
    security: false

Solution 2: Remove the login firewall altogether and add this rule to access_control

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
0
votes

In security.yml try setting the provider at the secured_area section:

secured_area:
    provider: administrators
    pattern: ^/
    anonymous: ~