spring-security ACL如何授予权限
我目前正在将 springs-security 集成到我们新的 Web 应用程序堆栈中。我们需要能够向用户或角色授予访问特定对象或某种类型的所有对象的权限。然而,这是我在阅读文档和示例时没有真正理解的一件事:
ACL 是否只向用户/角色授予单个对象的权限,还是为整个类型授予权限?据我了解,域对象意味着类型,但示例和教程似乎将权限分配给特定对象。我只是感到困惑还是我可以两者都做?如果没有的话,其他的我该怎么办?
谢谢!
I'm currently integrating springs-security into our new web application stack. We will need to be able to grant permissions for a user or role to access a specific object or all objects of a certain type. However that's one thing I didn't really get when working through documentations and examples:
Does an ACL only grant permissions to a user/role for a single object or does it do that for the entire type? As I understand it, domain object
means the type but the examples and tutorials seem like they assign permissions to specific objects. Am I just confused or can I do both? If not, how do I do the other?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有了 spring-security,你就可以做到这两点。这是可能的,因为 spring-security 支持所谓的权限规则 - 在 spring-security 术语中,他们称之为权限评估器。权限规则包含 ACL,而且您还可以在对象实例处于某种状态时保护它们的安全......等等。
这是它的工作原理:
您需要扩展 PermissionEvaluator - 这允许您拥有超级自定义逻辑来确定访问权限 - 您可以检查对象的类型或检查特定的 id,或检查用户是否调用方法是创建该对象的用户等:
现在你有了安全规则,你需要通过注释来应用它:
为了使其正常工作,应在 applicationContext.xml 中启用安全注释>:
With spring-security you can do both. It's possible because spring-security supports the so called permission rules - within the spring-security terminology they call it permission evaluators. Permission rules encompass ACL, but also you can secure instances of objects when they're in a certain state...etc.
This is how it works:
You need to extend the PermissionEvaluator - this allows you to have super custom logic for determining access rights - you can check the type of the object or check for a particular id, or check if the user invoking the method is the user that created the object, etc.:
Now that you have a security rule, you need to apply it through annotations:
In order for this to work the security annotations should be enabled in the applicationContext.xml: