4

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.....

8
  • what does php app/console router:debug says? Commented Jan 6, 2014 at 12:36
  • @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 Commented Jan 6, 2014 at 12:45
  • login_check: path: /login_check set a default controller and action Commented Jan 6, 2014 at 12:48
  • @crack where?? my routing.yml already contains login_check: path: /login_check Commented Jan 6, 2014 at 12:53
  • are you using fosuserbundle? Commented Jan 6, 2014 at 12:59

2 Answers 2

6

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 }
Sign up to request clarification or add additional context in comments.

3 Comments

this solution now keeps circulating in same page. Login page is coming over and over again after clicking submit.
But the user is already logged in, according to Symfony's profiler? I guess that if you want to go to another route after a successful login, yo have to make an authentication handler, that implements the AuthenticationSuccessHandlerInterface. Or the easiest way, try to access a secured route, and if you are not logged in, Symfony will redirect you to the login page, and after a successful login, it will automatically redirect to the requested page.
let me try more. I think this will work. May be I'm missing something else
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.