授予对 spring 安全 ACL 中对象的读取权限

Granting read permission to an object in spring security ACL

我正在使用 spring 安全 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);

如有任何关于如何实施的建议,我们将不胜感激。

我能够使用以下方法实现此目的:

@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;
}

有更好的方法吗?欣赏你的想法。