user3818576
user3818576

Reputation: 3391

How to secure other controller using FOSUserbundle?

I'm trying to study the FOSUserBundle. I follow the steps of their documentation (link) and I successfully created a login form and registration. Now, I'm creating another controller name TodoController and I want to secure that TodoController. It needs the user to login first before they show the page of todo. How can I secure the TodoController?

Upvotes: 0

Views: 22

Answers (1)

Alexandru Cosoi
Alexandru Cosoi

Reputation: 1000

FOSUserBundle only extend the Symfony security layer, but all other Symfony security stuff remains the same, so you can use the default access control from symfony security

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/, role: ROLE_ADMIN }

You will find it mentioned in the link you provided, but you can read more about it here http://symfony.com/doc/current/security/access_control.html

Or if you want something more flexible and more powerful you can take a look at JMSSecurityExtraBundle http://jmsyst.com/bundles/JMSSecurityExtraBundle/1.2/annotations

Hope this helps,

Alexandru Cosoi

Upvotes: 1

Related Questions