gpt4 book ai didi

java - RESTlet + JAX-RS 身份验证中间件

转载 作者:行者123 更新时间:2023-12-01 11:08:19 26 4
gpt4 key购买 nike

我正在应用程序引擎上使用 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
}

关于java - RESTlet + JAX-RS 身份验证中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32681125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com