如何限制Spring Roo中的menu.jspx对其他用户的实体执行CRUD操作
假设我正在创建一个 Web 应用程序 mypets,并且我有两个实体 User 和 Pet。一个用户可以拥有许多宠物。当我搭建 Pet 实体时,menu.jspx 允许更新和删除其他用户的 Pet。
有没有办法限制创建 Pet 实体的用户访问它们?
Say I am creating an web application mypets and I have two entities User and Pet. A User can have many Pets. When I scaffold the Pet entity the menu.jspx allows updates and deletes Pets of other users.
Is there a way to restrict access to Pet entities to Users who create them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以使用 Spring Security 插件来实现此目的。您将需要做一些修改。
首先,您需要为每个宠物创建一个字段来包含创建它的用户。使用带有
@PrePersist
的方法来设置登录用户详细信息以存储此信息。然后,您必须创建一个查找器来列出用户创建的所有宠物。
修改 Roo 生成的控制器以使用您创建的新查找器列出元素,并传递来自登录用户的 User 参数。
这样就可以了。
干杯,祝 Roo 一切顺利。
Yes, you can use Spring Security addon for this. There will be a little bit of tinkering you will have to do.
First you will need to have a field for each Pet to contain the User who created it. Use a method with
@PrePersist
to set the logged in user details to store this information.Then you will have to create a finder to list all the Pets that were created by the User.
Modify the Roo generated controller to list elements using the new finder you created, and pass the User argument taking from the logged in User.
That will do.
Cheers and all the best with Roo.