Spring Security ACL-创建权限 [英] Spring Security ACL - create permission

查看:323
本文介绍了Spring Security ACL-创建权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用具有实体权限的Spring Security ACL,但我想知道如何测试用户是否有权访问类的创建(第2位)权限。



类似的东西:

  aclPermissionEvaluator.hasPermission(auth,clazz, create)

有人可以帮我吗?



先谢谢了

解决方案

我有完全相同的问题,可悲的是,没有开箱即用的解决方案。



如果您的域模型允许这样做,一种方法是将创建权限添加到要创建的父对象



<例如,假设您要为客户端创建用户。您可以为允许为该特定客户端创建用户的用户向客户端添加创建权限。我选择的路径。



如果您的域对象不允许这样做,那么我发现的唯一方法是:




  • 创建一个新表 acl_class_entry ,并在其中列出 acl_entry 等价但链接到 acl_class 而不链接到 acl_object_identity

  • 然后创建您自己的权限评估程序,使用方法 boolean hasPermission(Authentication authentication,Serializable targetId,String targetType,Object权限)来检查 acl_class_entry的权限如果 target_id 为空。这将允许您使用SPel表达式 hasPermission(nulll,'className','permission')

  • 当然,您还需要创建自己的 AclService 版本以创建此类权限。


I can use Spring Security ACL with permissions on entity but I'd like to know how to test if a user has access to the "create" (bit 2) permission on a class.

Something like :

aclPermissionEvaluator.hasPermission(auth, clazz, "create")

Could someone help me?

Thanks in advance

解决方案

I have exactly the same problem, and sadly, there is no "out of the box" solutions.

One way to do it, if your domain model allow for it, is to add the create permission to the parent object you want to create

For example, imagine you want to create an user for a client. You can add the create permission to the client for the user allowed to create user for this specific client. That the path I choose.

If your domain object doesn't allow for that, the only way I found to do it is:

  • to create a new table acl_class_entry, wich list acl_entry equivalent but linked to an acl_class and not to an acl_object_identity
  • Then you create your own permission evaluator, surcharging the method boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) to check the permission against the acl_class_entry if target_id is null. This will allow you to check permission against a class by using the SPel expression hasPermission(nulll, 'className', 'permission')
  • Of course, you will also need to create your own version of AclService for creating such permission.

这篇关于Spring Security ACL-创建权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆