我正在使用 Spring Boot 构建一个简单的 HATEOAS REST 服务。
我有一个 MongoDB 存储库和资源,我想在其中允许 GET,但不允许其他所有内容。(发布、更新删除等)
一般的想法是允许“用户”按照自己的意愿使用资源并允许“公共”只读访问。
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends MongoRepository<Person, String>
{
@Secured("ROLE_USER")
public void delete(Person person);
@Secured("ROLE_USER")
public Person save(Person person);
@Secured("ROLE_USER, ROLE_PUBLIC")
public Person findOne(String id);
}
我不觉得我以正确的角度接近这个。这样做的首选方法是什么?