Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

Redirect to a url when not authorised

I am having problems with the security in Symfony 2.1.

I have a firewall setup:

firewall:

    main:
        pattern: ^/
        anonymous: ~
        query_string: ~
        access_denied_url: /register

    access_control:
    - { path: ^/, roles: ROLE_USER }
    - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }

I was hoping this would redirect users to the /register page, but instead any secured route still tells me that Full authentication is required to access this resource..

Could anyone steer me in the correct solution here?

Upvotes: 1

Views: 1825

Answers (1)

Tim
Tim

Reputation: 8606

I'm doing this, but have not used access_denied_url. I think that's why you're getting the harsh denied page.

Using form_login - unauthenticated users will be directed to your /login route. You could render or link to a register form there, or change the form_login: login_path to /register

http://symfony.com/doc/2.0/cookbook/security/form_login.html

Upvotes: 1

Related Questions