在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.
发布评论