pio*_*oto 5 spring-security spring-boot
我的应用程序中有一些复杂的访问限制,基本上需要查看用户角色的组合以及域对象的某些深层属性才能做出访问决定。
对于我的某些方法(特别是诸如getItem(Integer id)和updateItem(Integer id, FormBean form)),我真的无法提前知道是否允许他们访问该项目,因为我还没有,所以我一直在使用@PostAuthorize。
但是,后一个示例updateItem(id, form)提出了挑战。我只想允许他们在某些特定情况下更新表单。现在,我确实看到@PostAuthorize导致他们执行不应该执行的操作时获得HTTP 403响应的原因,但是数据库更改没有回滚。
在这种情况下@PreAuthorize,是否有可能获得,@Transactional并且@PostAuthorize所有人都能很好地比赛?(我认为也许可以通过调整一些建议的顺序...但是我对如何完成该顺序尚不完全清楚)。
或者,我的系统是否变得足够复杂,以至于我真的不应该对Domain ACL感兴趣?不幸的是,关于这些的文档感觉很薄……
Spring框架使用Ordered来定义bean的顺序。显式定义 @Transactional 和 @PostAuthorize 顺序的最简单方法是通过注释:
@EnableTransactionManagement(order = 0)
@EnableGlobalMethodSecurity(prePostEnabled = true, order = 1)
Run Code Online (Sandbox Code Playgroud)
Mil*_*vić -2
为什么不使用@PreAuthorize("hasPermission(#id, 'read')")和@PreAuthorize("hasPermission(#id, 'update')")并实现您自己的版本PermissionEvaluator?
但如果您确实希望使用@PostAuthorize,那么您可以尝试调整安全性和事务方面的顺序,如此处所述。
我的猜测是:
// perform security check first, will throw exception if bad
@EnableGlobalMethodSecurity(prePostEnabled = true, order = 0)
// apply tm around security check and update, allowing for rollback
@EnableTransactionManagement(order = 1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
475 次 |
| 最近记录: |