[英]RESTlet + JAX-RS Authentication Middleware
I'm making a backend API using RESTlet and JAX-RS on app engine. 我正在使用App Engine上的RESTlet和JAX-RS制作后端API。 I'd like to make a method that is called before each request to check whether the user is authenticated (has to make a query to an external API via HTTP) and then continue or stop depending. 我想制作一个在每次请求之前都会被调用的方法,以检查用户是否已通过身份验证(必须通过HTTP对外部API进行查询),然后继续或停止依赖。
How could I do this? 我该怎么办?
Thanks, Daniel 谢谢,丹尼尔
Turns out to be very simple. 事实证明非常简单。
Create a subclass of Authenticator ( http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/Authenticator.html?is-external=true ) and implement authenticate() with custom authentication and any other functions that are needed. 创建Authenticator的子类( http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/security/Authenticator.html?is-external=true )并实现authenticate( )以及自定义身份验证和其他所需功能。
For example, 例如,
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.