简体   繁体   English

Symfony2限制访问用户

[英]Symfony2 limit access user

I want to limit user access only for admin on some routers and I want to know how is it best practice to do that, is it possible from routing (example after call my function from controller I want to call one function who say true if I'm admin or false if not) or need for all function call my function first for verify. 我只想限制某些路由器上的admin用户访问权限,我想知道这样做的最佳实践,是否可以通过路由(例如,从控制器调用我的函数后,我想调用一个函数,如果我说的话,则为true 'm admin或false如果不是)或需要所有功能,请先调用我的功能进行验证。

I was read the documentation symfony2 but no specific noting if is possible. 我已经阅读了symfony2文档,但没有具体说明。

See http://symfony.com/doc/current/book/security.html#book-security-securing-controller in the Symfony2 documentation. 请参阅Symfony2文档中的http://symfony.com/doc/current/book/security.html#book-security-securing-controller You need to access the security.context service and return the proper value based on the user's roles. 您需要访问security.context服务并根据用户角色返回正确的值。

Since you need to limit access on specific routes, you can do so with Symfony's Access Control in your security.yml. 由于您需要限制对特定路由的访问,因此可以在security.yml中使用Symfony的访问控制来进行限制。 Read the docs in order to achieve this. 阅读文档以实现此目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM