quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.78k stars 2.68k forks source link

OIDC client: quarkus.oidc-client.enabled does not working in combinatie with @RegisterProvider(OidcClientRequestReactiveFilter.class). #41827

Closed argenstijn closed 1 month ago

argenstijn commented 4 months ago

Describe the bug

While testing you can disabled the oidc client by setting quarkus.oidc-client.enabled to false. This work perfectly in combination with @OidcClientFilter. But not when you are using @RegisterProvider using the default class or custom class.

Expected behavior

oidc Client is disabled when using @RegisterProvider

Actual behavior

Caused by: java.lang.NullPointerException: Cannot invoke "io.quarkus.oidc.client.OidcClients.getClient()" because "oidcClients" is null
    at io.quarkus.oidc.client.runtime.AbstractTokensProducer.init(AbstractTokensProducer.java:43)
    at io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter_Bean.doCreate(Unknown Source)
    at io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter_Bean.create(Unknown Source)
    at io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter_Bean.get(Unknown Source)
    at io.quarkus.oidc.client.reactive.filter.OidcClientRequestReactiveFilter_Bean.get(Unknown Source)
    at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:559)
    at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:539)
    at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:572)
    at io.quarkus.arc.impl.ArcContainerImpl.instanceHandle(ArcContainerImpl.java:534)
    at io.quarkus.arc.impl.ArcContainerImpl.instance(ArcContainerImpl.java:294)
    at io.quarkus.rest.client.reactive.runtime.RestClientBuilderImpl.register(RestClientBuilderImpl.java:292)
    at io.quarkus.rest.client.reactive.runtime.RestClientBuilderImpl.build(RestClientBuilderImpl.java:408)
    at io.quarkus.rest.client.reactive.runtime.QuarkusRestClientBuilderImpl.build(QuarkusRestClientBuilderImpl.java:267)
    at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.build(RestClientCDIDelegateBuilder.java:67)
    at io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilder.createDelegate(RestClientCDIDelegateBuilder.java:49)
    at io.quarkus.rest.client.reactive.runtime.RestClientReactiveCDIWrapperBase.delegate(RestClientReactiveCDIWrapperBase.java:76)
    at io.quarkus.rest.client.reactive.runtime.RestClientReactiveCDIWrapperBase.<init>(RestClientReactiveCDIWrapperBase.java:30)

How to Reproduce?

  1. create oidc client and disabled it
  2. activate the client by using the annotation @RegisterProvider

Output of uname -a or ver

Microsoft Windows [Version 10.0.19045.4529]

Output of java -version

openjdk 21.0.2 2024-01-16 LTS OpenJDK Runtime Environment Corretto-21.0.2.13.1 (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Corretto-21.0.2.13.1 (build 21.0.2+13-LTS, mixed mode, sharing)

Quarkus version or git rev

3.12.2

Build tool (ie. output of mvnw --version or gradlew --version)

3.9.6

Additional information

No response

quarkus-bot[bot] commented 4 months ago

/cc @pedroigor (oidc), @sberyozkin (oidc)

sberyozkin commented 4 months ago

@argenstijn

When you use @RegisterProvider it is done at the REST client level to which OidcClientRequestReactiveFilter.class means only that it is just some provider class, it does not know anything about OIDC client or if the feature is disabled.

@OidcClient is managed directly at the OIDC client build steps level which is only activated if the OIDC client feature is enabled.

We can probably add a check at the filter level to avoid NPEs