Quarkus / vertx httpauthentication mechanicm中的访问资源Info

发布于 2025-02-10 06:03:54 字数 1236 浏览 4 评论 0 原文

在Quarkus(Resteasy Reactive)中,是否有一种方法可以在HTTP身份验证机制中掌握“ ResourceInfo”? 我要做的是阅读在资源类或方法上定义的注释,以便根据其选择一种身份验证机制。

直接在机制类中注入资源INFO不起作用(而且,它是应用程序范围且不要求范围的,因此不确定它是否有效)。我也找不到在RoutingContext参数中需要的信息。 我还尝试过添加一个容器RequestFilter,其中将ResourceInfo注入@Context效果很好,但是我认为也许在httpauthenticationmechanism.authenticate()之后调用过滤器,因为它在我的测试中未在端点需要地点时在我的测试中调用。

还有另一种方法吗?

---->要使用代码澄清我想做的:

具有不同的jax-rs资源,具有自定义@Authorization注释,具有不同的“ API名称”:

@Path("/jwttest")
@ApplicationScoped
@Authorization("jwttest")
public class JWTTestController {
...
}

@Path("/oidctest")
@ApplicationScoped
@Authorization("myoidc")
public class OIDCTestController {
...
}

然后像这样的不同配置:

myframework.auth.jwttest.type=jwt
myframework.auth.jwttest.issuer=123
myframework.auth.jwttest.audience=456

myframework.auth.myoidc.type=oidc
myframework.auth.myoidc.auth-server-url=myurl

在httpauthentication mechanism中,找到@Authorization的值,基于它,请致电带有正确的API名称,以便可以加载配置。

In Quarkus (resteasy reactive), is there a way to get hold of the "ResourceInfo" in an HTTP Authentication Mechanism?
What I'm trying to do is read an annotation that is defined on the resource class or method, in order to choose an authentication mechanism based on it.

Injecting the ResourceInfo directly in the mechanism class does not work (and also, it is application scoped and not request scoped, so not sure it could work). I also couldn't find the info I need in the RoutingContext parameter.
I have also tried adding a ContainerRequestFilter, in which injecting the ResourceInfo with @Context works well, but I think perhaps the filters are called after the httpAuthenticationMechanism.authenticate(), because it's not called in my test when the endpoint requires authentication.

Is there another way to do this?

----> To clarify with code what I would like to do:

have different JAX-RS resources with a custom @Authorization annotations with different "api names" like this:

@Path("/jwttest")
@ApplicationScoped
@Authorization("jwttest")
public class JWTTestController {
...
}

@Path("/oidctest")
@ApplicationScoped
@Authorization("myoidc")
public class OIDCTestController {
...
}

and then different configs like this:

myframework.auth.jwttest.type=jwt
myframework.auth.jwttest.issuer=123
myframework.auth.jwttest.audience=456

myframework.auth.myoidc.type=oidc
myframework.auth.myoidc.auth-server-url=myurl

And in the HttpAuthenticationMechanism, find the value of @Authorization, and based on it, call another provider like suggested in https://quarkus.io/guides/security-customization#dealing-with-more-than-one-httpauthenticationmechanism with the right api name so that it can load the config.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文