1

我正在为 Play 开发一个具有动作组合的安全实现。

出于安全原因,在 JSON 请求负载中发送了一个访问令牌,而不是在请求的标头中。我要做的是,在一个动作(SecureAction)中提取令牌并继续下一个动作......因为可以修改Http.Context中的请求吗?一些代码..

@With(SecureAction.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Inherited
@Documented
public @interface Secured {
    //TODO ver parametros de acceso ..... al metodo

}

public class SecureAction extends Action.Simple {

    @Override
    public Result call(Http.Context ctx) throws Throwable {
        //TODO extract token of request "ctx.request().body()"
        //TODO change request with new body witout token and delegate to the next action
        return delegate.call(ctx);
    }
 }

 @actions.security.Secured
 public static Result addAccount() {

     Form<Account> f = form(Account.class).bindFromRequest();
        if (f.hasErrors()) {
            return badRequest();
        }

        .....
 }

问候!!!!

4

0 回答 0