quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Keycloak admin client fail with "authHeader" is null when using classic extensions

Open majugurci opened this issue 1 year ago • 6 comments

Describe the bug

Here is a previous issue which seems to be fixed and closed, could be related: https://github.com/quarkusio/quarkus/issues/30089.

When I inject org.keycloak.admin.client.Keycloak and try to call some method (e.g. keycloak.serverInfo().getInfo()) it is giving me the following error:

Caused by: java.lang.NullPointerException: Cannot invoke "String.startsWith(String)" because "authHeader" is null
        at org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:53)
        at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:644)

It is only happening when using classic extensions, when using reactive extensions it is working fine. For the test I'm using latest Quarkus (3.4.2) and latest LTS version (3.2.6.Final), with these extensions it is not working:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-keycloak-admin-client</artifactId>
</dependency>

But if I use reactive extensions it is working fine:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-keycloak-admin-client-reactive</artifactId>
</dependency>

Expected behavior

Behaviour should be the same as when using reactive extensions.

Actual behavior

It is throwing NPE error.

How to Reproduce?

code-with-quarkus.zip

Here is a minimum reproduction case (freshly generated Quarkus project). In pom there are classic extensions and commented out reactive extension. Also in the application properties there are basic properties for keycloak admin client.

Output of uname -a or ver

No response

Output of java -version

java version "1.8.0_381" Java(TM) SE Runtime Environment (build 1.8.0_381-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)

and

openjdk version "17.0.8" 2023-07-18 OpenJDK Runtime Environment Temurin-17.0.8+7 (build 17.0.8+7) OpenJDK 64-Bit Server VM Temurin-17.0.8+7 (build 17.0.8+7, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.4.2 and 3.2.6.Final

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

apache-maven-3.9.5

Additional information

No response

majugurci avatar Oct 11 '23 20:10 majugurci

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

quarkus-bot[bot] avatar Oct 11 '23 20:10 quarkus-bot[bot]

Sadge, getting the same error in 3.6.4 as wel. With all reactive extensions:

  • quarkus-resteasy-reactive-jackson. or quarkus-resteasy-reactive-jsonb
  • quarkus-keycloak-admin-client-reactive

It also occurs in 3.6.4 with the following setup:

  • quarkus-resteasy
  • quarkus-resteasy-jsonb
  • quarkus-keycloak-admin-client

The issue is solved when using the following combination:

  • quarkus-resteasy
  • quarkus-resteasy-jackson
  • quarkus-keycloak-admin-client

@sberyozkin this issue is an impedement for us to go to production. Can this be fixed in 3.7 🚀

appiepollo14 avatar Jan 08 '24 14:01 appiepollo14

Detected the same issue as well with 3.7.3 using:

  • quarkus-resteasy-reactive
  • quarkus-resteasy-reactive-jsonb
  • quarkus-rest-client-reactive-jsonb
  • quarkus-keycloak-admin-client-reactive

maxlam79 avatar Feb 17 '24 04:02 maxlam79

hello @maxlam79 this is issue for RESTEasy Classic, there is palpable difference on implementation side. If you provide a reproduce for RESTEasy Reactive, I'll have a look.

michalvavrik avatar Feb 17 '24 10:02 michalvavrik

@michalvavrik , ooppss...sorry. I have created a separate issue here. Thank you.

maxlam79 avatar Feb 17 '24 14:02 maxlam79

I'll check what we can do for RESTEasy Classic version.

michalvavrik avatar Feb 18 '24 21:02 michalvavrik