Spring security 包括Spring数据存储库中的域对象安全@PostFilter可分页端点

Spring security 包括Spring数据存储库中的域对象安全@PostFilter可分页端点,spring-security,spring-data,spring-data-rest,spring-security-acl,Spring Security,Spring Data,Spring Data Rest,Spring Security Acl,在我的项目中,我使用Spring数据、Spring数据Rest和Spring安全性 我需要完成的是在这些存储库上实现域对象安全性(ACL)。特别是@PostFilteroverPageable.findAll()方法 方法级安全性很容易实现,如所述 文档中还有一节介绍如何在@Query中使用安全表达式 但是,尽管我也可以在@Query中使用hasPermission(..)方法,但无法在此方法中包含对象(SQL行)-具体地说,请执行以下操作: @Query("select u from #{#e

在我的项目中,我使用Spring数据、Spring数据Rest和Spring安全性

我需要完成的是在这些存储库上实现域对象安全性(ACL)。特别是
@PostFilter
over
Pageable.findAll()
方法

方法级安全性很容易实现,如所述

文档中还有一节介绍如何在
@Query
中使用安全表达式

但是,尽管我也可以在
@Query
中使用
hasPermission(..)
方法,但无法在此方法中包含对象(SQL行)-具体地说,请执行以下操作:

@Query("select u from #{#entityName} u where 1 = ?#{security.hasPermission(u, 'read') ? 1 : 0}")
现在我了解到,这与修改查询预执行的方式不同,如下所示:

@Query("select m from Message m where m.to.id = ?#{ principal?.id }")
我还发现了以下jira问题: 我怀疑一旦问题得到解决,就会有一个解决办法,但似乎不会很快出现

我仍然需要实现这个功能,为此,我希望得到您的输入和可能的解决方案的指针

现在我正在考虑创建我的自定义注释,它将mimmick
@PostFilter
one并使用相同的语法,但将在我自己的BaseRepositoryImplementation中手动调用。在那里,我将从type和
Repositories#getRepositoryInformationFor(type)#getRepositoryInterface()
获取存储库接口,找到相应方法的注释并手动调用安全检查

您是否有不同的解决方案,或者我建议的解决方案的一些注释


另外,您是否知道在提到的jira问题上是否有时间表?

一种轻量级方法是使用hasPermission()方法,并在控制器级别实现您自己的“权限计算器”(如果您可以选择的话)

@PreAuthorize("hasPermission(#employee, 'edit')")
public void editEmployee(Employee employee) {
   ...
}

@Component
public class PermissionEvaluatorImpl implements PermissionEvaluator {
    @Override
    public boolean hasPermission(Authentication auth,
            Object targetDomainObject, Object permission) {
        // return true if "auth" has "permission" permission for the user.
        // Current-user can be obtained from auth.
    }
    ...
}
这里更详细地描述了这一点: