O
O
Oldy7772015-11-22 15:10:46
symfony
Oldy777, 2015-11-22 15:10:46

How to do dynamic access control in Symfony2?

I need all the pages in the admin panel to be available to the superuser. And the rest are only those that the admin allowed. Suppose for the user Sergey, he can mark the available pages /admin/news/, /admin/articles/. And he can also set the same for the User Group. By default, only the home page is available to all users.
Accordingly, the questions are
: 1. how can access control be implemented along the paths
2. how can all paths that start with /admin/* be loaded into the admin interface
3. How can you set Names for paths, for example, display News instead of /admin/news/ . And it would be desirable that this, along with the paths, be prescribed somewhere

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Evgenievich, 2015-11-23
@banderos120

https://symfony.com/doc/master/book/security.html

B
bears, 2015-11-23
@bears

There is no standard solution to this problem. I did this: I saved all the admin routes in the database, + the roles also in the database and there is a many-to-many relationship between them, and I catch the onKernelRequest event and check if the current route is "managed", if yes, then there is a check - yes whether the role of the authorized user has a connection with the current route, if not, then we throw an exception with the code 403, if there is, then everything is OK. Of course, there is a page in the admin panel that lists everything that is in the admin panel and the permissions to view / edit / delete for each role.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question