Deadbolt-Play Framework-如何使用控制器中的参数检查@RestrictedResource? [英] Deadbolt - Play Framework - How to check a @RestrictedResource with parameters in a controller?

查看:89
本文介绍了Deadbolt-Play Framework-如何使用控制器中的参数检查@RestrictedResource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Deadbolt的模块,我们可以在视图中使用资源名称和参数来检查strictedResource.

With Deadbolt's module we can check the restrictedResource with a ressource name and parameters in the view.

例如,在我看来,它就可以了,而且效果很好:

For example in my view, I have it, and it works well:

#{deadbolt.restrictedResource resourceKeys:['Domain'] , resourceParameters:['domainid':domain.id]}
   <li><a href="@{Admin.showDomain(domain.id)}">${domain.title}</a></li>
#{/deadbolt.restrictedResource}

但是在我的控制器中,我只能检查资源名称,但是找不到在将Domainid传递给我的RestrictedResourcesHandler中进行检查的方法.

But in my controller, I just can check the ressource name but I don't find a way to check it in my RestrictedResourcesHandler passing the domainid with.

我正在寻找一种解决方案,例如:

I am looking for a solution to do something like that:

@RestrictedResource(name = {"Domain"}, params = {domainid})
public static void showDomain(String domainid)
{
}

预先感谢

推荐答案

注释中不可能包含动态信息,但是您可以使用params定义请求中传入值的名称.但是,此信息目前尚未传递到处理程序中,因为它需要映射.虽然您可以从strictedResource标记中传递参数映射,但不能从注释中执行此操作,因此会将空映射传递到处理程序中.

It's not possible to have dynamic information in an annotation, but you can use params to define the name of an incoming value in the request. However, this information isn't passed into the handler at the moment because it expects a map. While you can pass in a map of parameters from the restrictedResource tag, you can't do this from an annotation so an empty map is passed into the handler.

这里最好的方法是从请求对象中提取一个众所周知的参数名称.我需要重新考虑在不破坏向后兼容性的情况下的最佳方法.

Your best approach here is to pull a well-known parameter name from the request object. I need to have a rethink about the best way to do this without breaking backwards compatibility.

Steve(Deadbolt的作者)

Steve (author of Deadbolt)

这篇关于Deadbolt-Play Framework-如何使用控制器中的参数检查@RestrictedResource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆