在Play 1.2中,有没有办法在不编辑模块源的情况下保护模块提供的控制器?
我想使用模块中提供的控制器,但控制器不安全。我不想编辑模块的源代码,因为这将成为维护开销。 Play 是否提供了针对此问题的任何解决方案?
I'd like to a use a Controller provided in a module but the Controller is not secured. I don't want to edit the source of the module as this will become a maintenance overhead. Does Play offer any kind of solution to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用安全模块,您就无法做到这一点。我正在开发一个模块来提供此类功能,但它尚未完成,因为我必须编写更多测试和用户管理部分以及一些标签。但是,如果您感兴趣,我可以向您发送存储库的链接。它应该符合您的要求。
Deadbolt 似乎也不起作用。
With the Secure-Module you can't do this. I'm working on a module to provide such functionality, but it's not finished, because I have to write more tests and a user management part and some Tags. However if you interested I can send you a link to the repository. It should fit your requirements.
Deadbolt doesn't seems to work too.
对此的强力方法是不包括模块的路由(或者至少不允许直接访问您想要保护的控制器),而是仅允许通过您自己的控制器之一来访问模块。然后可以在您自己的控制器中应用访问控制。
The brute-force approach to this is to not include the module's routes (or at least not allow direct access to the controllers you want to secure), and instead allow access to the module only by going through one of your own controllers. Access control can then be applied in your own controller.
您必须使用自己的控制器覆盖模块控制器,该控制器将使用您的方法委托对控制器方法的调用。假设您所要做的就是创建一个控制器来扩展您想要保护的模块控制器,向其添加 @With(Secure.class) 和 @Check 注释,然后更改路由以指向该新控制器而不是它所在的模块控制器延伸。
查看 CRUD 模块的示例 - https://www.playframework.com/documentation/1.2 .2/guide8
他们有 Posts 控制器,扩展了用安全模块保护的 CRUD。 Posts 控制器没有任何自己的方法,但有效地从 CRUD 继承了这些方法(从 Play 路由器的角度来看):
You have to override module controller with your own controller that delegates calls to controller methods with your methods. Supposedly all you have to do is create a controller that extends the module controller you want to secure, add @With(Secure.class) and @Check annotations to it, and change routes to point to that new controller instead of module's controller that it extends.
Look at the example of CRUD module - https://www.playframework.com/documentation/1.2.2/guide8
They have Posts controller extending CRUD secured with Secure module. The Posts controller doesn't have any methods of it's own, but effectively inherits those from CRUD (from Play router's point of view):