【发布时间】:2016-02-22 16:32:49
【问题描述】:
类Dog 使用私有字段owner 将所有者用户名保留在类User 中(实现UserDetails):
@Document
public class Dog {
@Id
private ObjectId id;
private String owner;
}
@Document
public class User implements UserDetails {
@Id
private ObjectId id;
private String username;
}
这些文档使用spring-data-mongodb 持久化并使用spring-data-rest 公开。用户使用 Spring Security 进行身份验证,因此可以使用 @AuthenticationPrincipal。
要求 REST 只能访问用户拥有的狗。是否可以调整 spring-data-rest 以仅返回集合 dogs 中的文档子集,具有“所有者”字段的文档与身份验证主体返回的 User 实例中的用户名相同?
【问题讨论】:
标签: java spring spring-security spring-data-mongodb spring-data-rest