我有这样的路线:
GET /job$id<[0-9]+>/ controllers.Jobs.index(id)
POST /job$id<[0-9]+>/done controllers.Jobs.done(id)
POST /job$id<[0-9]+>/update controllers.Jobs.update(id)
DELETE /job$id<[0-9]+>/remove controllers.Jobs.remove(id)
我想保护它。每个作业都有一个所有者。所以我做了
public class Secured extends Security.Authenticator {
...
}
然后我尝试通过“@With()”注释来保护我所有的操作,但我需要将“Id”参数传递给我的安全方法,所以我写得像:
@With(IsOwner.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Owner {
long value() default 0;
}
public static class IsOwner extends Action<Owner>{
@Override
public Promise<SimpleResult> call(Context ctx) throws Throwable {
if(!isOwner(configuration.value())){
return Promise.pure(redirect(..));
}
return delegate.call(ctx);
}
}
但我无法将我的操作参数传递给注释。
@Security.Authenticated(Secured.class)
@Owner(id) //**this part I want to work**
public class Jobs extends Controller {
//@Owner(id) - or at list there
public static Result index(Long Id){
//I have too many Actions and don't want to do every time this
/*if(!Secured.isOwnerMethod(Id)){
return forbidden();
}*/
return ok();
}
我看到的其他方法是在 IsOwner.call() 方法中从 Context 获取参数...
对于这种情况,请给我一个建议或好的做法。
谢谢。
最佳答案
我遇到了这个问题并提出了一个 Play 扩展,它将所有 url 参数公开为公共(public)请求参数...您可以在此处查看 => https://github.com/asouza/reverse-route-plugin
基本上,您必须从我的 Global 类进行扩展。
干杯,
阿尔贝托
关于java - 玩! java 。将请求参数传递给@With 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23698339/