Play 2 Java 身份验证插件 - HTTP 状态代码响应而不是重定向 [英] Play 2 Java authenticate plugin - HTTP status code response instead of redirect

查看:67
本文介绍了Play 2 Java 身份验证插件 - HTTP 状态代码响应而不是重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 Play 2 身份验证插件 作为 REST API,我想简单地登录尝试返回 200 或 403.

We are using Play 2 authenticate plugin for a REST API and I would like to simply return 200 or 403 for login attempts.

插件的代码如下:

public static Result loginAndRedirect(final Context context,
        final AuthUser loginUser) {
    storeUser(context.session(), loginUser);
    return Controller.redirect(getJumpUrl(context));
}

有没有办法在不fork插件项目的情况下避免重定向?

Is there any way to avoid the redirect without forking the plugin project?

推荐答案

我只是偶然发现了同样的场景,正如 nico_ekito 指出的,这可以通过扩展 PlayAuthenticate.Resolver 并覆盖来实现:

I just stumbled in the same scenario, and as nico_ekito pointed out, this can be achieved by extending PlayAuthenticate.Resolver and overriding:

@Override
    public Call afterAuth() {
        return routes.Application.restAfterAuth();
    }

因此您可以返回应用的任何路径.

So you can return any route of your app.

这篇关于Play 2 Java 身份验证插件 - HTTP 状态代码响应而不是重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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