sfguard 上的高级/动态权限 - symfony
我有一个 symfony 项目,想添加社区功能。
每个人都可以以管理员身份打开社区并邀请人们加入社区。
管理员比普通社区用户拥有更多的权限。
问题是,我想使用 Syfony 的 sfguarduser、sfguardgroup、sfguardpermission
- 为此目的使用 sfguard 架构是否有意义?
- 如何检查特定用户是否对特定组具有特定权限?
I have a symfony project and would like to add communities feature.
Everyone can open a community as an admin and invites people to join the community.
Admin has more permissions than a regular community user.
The thing is, I want to user Syfony's sfguarduser, sfguardgroup, sfguardpermission
- Does it make any sense to use the sfguard architecture for that purpose?
- how do I check if a specific user has a spcecific permission on a specific group?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿,这会对你有一点帮助;)
动作内部:
层内:
你可以考虑另外使用:
来源:层内的 Symfony
Hey, this will help you a little ;)
Inside the action :
Inside the layer :
You might consider using in addition :
Source : Symfony inside the layer
为此目的使用 sfguard 架构是否有意义?
当然,但您需要稍微修复一下。默认情况下,Symfony 在会话中存储凭证,这意味着它们在会话过期之前不会失效。当您希望通过将某人添加到组或授予他们权限来立即看到效果时,这是一个大问题。
要解决此问题,您需要执行以下操作之一:
无论哪种方式,您都必须熟悉 Symfony 和 sfGuardDoctrine 用户系统。查看
sfGuardSecurityUser::signIn
,以便您熟悉凭据默认情况下的工作方式。如何检查特定用户是否对特定组具有特定权限?
Tristan 对此进行了非常全面的介绍。您还需要查看 sfDoctrineGuard 自述文件。请注意,对于登录用户实时发生凭据更改的任何解决方案,您需要覆盖 Tristan 列出的大多数(如果不是全部)方法来执行某种失效。
另外,请查看此相关问题,它可能会有所帮助。
Does it make any sense to use the sfguard architecture for that purpose?
Absolutely, but you'll need to fix it up a little bit. By default, Symfony stores credentials on the session, which means that they won't get invalidated until your session expires. This is a big issue when you expect to see an immediate effect by adding someone to a group or granting them a permission.
To fix this, you'll want to do one of the following:
Either way, you're going to have to get familiar with Symfony and sfGuardDoctrine user system. Take a look at
sfGuardSecurityUser::signIn
so you're familiar with how credentials work by default.How do I check if a specific user has a spcecific permission on a specific group?
Tristan covered this pretty thoroughly. You'll also want to take a look at the sfDoctrineGuard readme. Note that for any solution in which credential changes happen live for signed in user's, you'll need to override most if not all of the methods listed by Tristan to perform some sort of invalidation.
Also, check out this related question, it may be helpful.