【问题标题】:Granting read permission to an object in spring security ACL在 Spring Security ACL 中授予对象读取权限
【发布时间】:2018-11-03 02:43:52
【问题描述】:

我正在使用 Spring Security ACL。但我有一个要求,即所有人都可以访问一个特定对象,而无需检查 hasPermission 或 hasRole。

我不确定如何实现这一点,我尝试了以下方法:

@NotNull
@PostAuthorize("hasPermission(returnObject, 'read') or #aLong==1")
@Override
Optional<DBO_TYPE> findById(@NotNull Long aLong);

并且还使用了 returnObject

@NotNull
@PostAuthorize("hasPermission(returnObject, 'read') or returnObject.id==1")
@Override
Optional<DBO_TYPE> findById(@NotNull Long aLong);

感谢任何有关如何实现此功能的建议。

【问题讨论】:

    标签: java spring-boot spring-security acl


    【解决方案1】:

    我能够使用以下方法实现这一点:

    @NotNull
    @PostAuthorize("hasPermission(returnObject, 'read') or isExceptionObject(returnObject)")
    @Override
    Optional<DBO_TYPE> findById(@NotNull Long aLong);
    

    并在 isExceptionObject 对象中进行了我需要的检查,如下所示:

    public boolean isExceptionObject(Object target) {
        if (target != null          
            && ((Optional) target).get().getId() == 1)
            return true;
        return false;
    }
    

    有没有更好的方法来做到这一点?感谢您的想法。

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 2014-02-18
      • 2011-11-20
      • 2013-10-14
      • 2013-09-30
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多