quarkus: Selecting OIDC tenant via annotation is not working with RESTEasy Reactive
Describe the bug
According to OIDC docs, one can select OIDC tenant via annotation as follows:
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface HrTenant {
}
@Interceptor
@HrTenant
public class HrTenantInterceptor {
@Inject
RoutingContext routingContext;
@AroundInvoke
Object setTenant(InvocationContext context) throws Exception {
routingContext.put(OidcUtils.TENANT_ID_ATTRIBUTE, "hr");
return context.proceed();
}
}
@Path("/hr")
public class HrResource {
@HrTenant
@GET
@Produces(MediaType.TEXT_PLAIN)
public String helloWorld() {
return "Hello World";
}
}
Expected behavior
Authentication of /hr endpoint should be based on quarkus.oidc.hr.* configs.
Actual behavior
Authentication of /hr endpoint uses the default tenant configs quarkus.oidc.* as authentication is triggered before HrTenantInterceptor, hence the authentication fails.
Quarkus version or git rev
3.2.0.Final
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 37 (36 by maintainers)
I think I found bit more generic solution in mind, because ability to connect method to request when
proactive=false(and RR started processing request) will help us in the future as well. I’ll take my time and look when possible. Thanks for feedback.Hey @michalvavrik Sorry, missed it, for the annotation based tenant id resolution it would not be a problem at all, it being called multiple times. Note if it were
TenantResolver(which can check request for some headers/queries) orTenantConfigResolver(likewise - when creating OIDC config dynamically) it would be a problem - we actually have tests verifying a givenTenantResolverandTenantConfigResolveris called only once, but for annotation based approach it is just a value - this security check should be able to haveRoutingContextinjected to be able to set the tenant id on itI don’t have answer for that - I’m wondering about that as well. Only thing that is clear to me is that at this very point https://github.com/quarkusio/quarkus/blob/65ca2dbf179846a09957e297cfc6f8d7b6c3262c/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/security/EagerSecurityHandler.java#L72 (or little later) we have knowledge of method annotation but security checks didn’t run yet, so we can do there something.
I will think, bring suggestions if you have them 😃
Thanks Michal
That’s correct. I am using RESTEasy Reactive:
@Eng-Fouad I’ve opened a PR which will fix this issue - but please reopen it if it will be merged before you get a chance to double check, and provide a reproducer, thanks