Skip to content

OAuth2 authentication init fails with ClassCastException #500

@asoltesz

Description

@asoltesz

I am using Spring Pulsar with Spring Boot 3.2.0-M3 with the Pulsar Client 3.1.0.

I am configuring the OAuth2 (with JWT) like this (as the docs says here):

spring:
    pulsar:
        client:
            authentication:
                plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2
                param:
                    issuerUrl: https://idp.mycompany.com
                    privateKey: ...

I get the following error at application startup:

Caused by: java.lang.IllegalStateException: Unable to configure Pulsar authentication
...
Caused by: org.apache.pulsar.client.api.PulsarClientException$UnsupportedAuthenticationException: java.lang.ClassCastException: class org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2 cannot be cast to class org.apache.pulsar.client.api.Authentication (org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2 and org.apache.pulsar.client.api.Authentication are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @2b71fc7e)
	at org.apache.pulsar.client.impl.AuthenticationUtil.create(AuthenticationUtil.java:118) ~[pulsar-client-3.1.0.jar!/:3.1.0]
	at org.apache.pulsar.client.impl.PulsarClientImplementationBindingImpl.createAuthentication(PulsarClientImplementationBindingImpl.java:133) ~[pulsar-client-3.1.0.jar!/:3.1.0]
	at org.apache.pulsar.client.api.AuthenticationFactory.create(AuthenticationFactory.java:108) ~[pulsar-client-api-3.1.0.jar!/:3.1.0]
	... 85 common frames omitted
Caused by: java.lang.ClassCastException: class org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2 cannot be cast to class org.apache.pulsar.client.api.Authentication (org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2 and org.apache.pulsar.client.api.Authentication are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @2b71fc7e)
	at org.apache.pulsar.client.impl.AuthenticationUtil.create(AuthenticationUtil.java:111) ~[pulsar-client-3.1.0.jar!/:3.1.0]
	... 87 common frames omitted

Looks like the code assumes that the factory can be cast to the Authentication class which doesn't look like the class design at all.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions