RESTlet + JAX-RS 认证中间件

RESTlet + JAX-RS Authentication Middleware

我正在应用引擎上使用 RESTlet 和 JAX-RS 制作后端 API。我想制作一个在每个请求之前调用的方法来检查用户是否经过身份验证(必须通过 HTTP 向外部 API 查询)然后继续或停止取决于。

我该怎么做?

谢谢, 丹尼尔

原来很简单

创建 Authenticator 的子类 (http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/Authenticator.html?is-external=true) 并使用自定义身份验证和任何其他所需的功能实现 authenticate()。

例如,

public class MyAuthenticator extends Authenticator {

public MyAuthenticator(Context context) {
    super(context);
}

@Override
protected boolean authenticate(Request request, Response response) {
    // do your custom authentication here and return true or false depending on result
}