Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2 authentication init fails with ClassCastException #500

Closed
asoltesz opened this issue Nov 22, 2023 · 5 comments
Closed

OAuth2 authentication init fails with ClassCastException #500

asoltesz opened this issue Nov 22, 2023 · 5 comments
Assignees
Labels
type: bug A general bug type: documentation A documentation update
Milestone

Comments

@asoltesz
Copy link

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.

@asoltesz asoltesz changed the title OAuth2 authentication fails with ClassCastException OAuth2 authentication init fails with ClassCastException Nov 22, 2023
@onobc
Copy link
Collaborator

onobc commented Nov 22, 2023

Hi @asoltesz ,
Looks like you found a bug in the docs. Can you try org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2 instead?

@onobc onobc added type: documentation A documentation update status: feedback-provided Feedback has been provided labels Nov 22, 2023
@asoltesz
Copy link
Author

With AuthenticationOAuth2, I get a different exception:

Caused by: org.apache.pulsar.client.api.PulsarClientException$UnsupportedAuthenticationException: org.apache.pulsar.shade.org.apache.commons.lang.NotImplementedException: Deprecated; use EncodedAuthenticationParameterSupport
	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]
	... 82 common frames omitted
Caused by: org.apache.pulsar.shade.org.apache.commons.lang.NotImplementedException: Deprecated; use EncodedAuthenticationParameterSupport
	at org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2.configure(AuthenticationOAuth2.java:91) ~[pulsar-client-3.1.0.jar:3.1.0]
	at org.apache.pulsar.client.impl.AuthenticationUtil.create(AuthenticationUtil.java:112) ~[pulsar-client-3.1.0.jar:3.1.0]
	... 84 common frames omitted

It looks like this AuthenticationOAuth2 doesn't support initializing with the "param" section (map of parameters).

@onobc
Copy link
Collaborator

onobc commented Nov 22, 2023

Thanks @asoltesz - sorry you are running into this and we will take a look in the next 24-48 hrs. In the meantime, a workaround may be to

If you need more control over the configuration, consider registering one or more PulsarClientBuilderCustomizer beans.

@onobc onobc added type: bug A general bug and removed status: feedback-provided Feedback has been provided labels Nov 22, 2023
@onobc onobc self-assigned this Dec 9, 2023
@onobc onobc added this to the 1.0.1 milestone Dec 9, 2023
onobc added a commit to onobc/spring-boot that referenced this issue Dec 16, 2023
The Pulsar authentication is currently configured using a map of auth
parameters. However, this avenue is deprecated in Pulsar and instead
needs to use an encoded auth parameters string. This commit simply
takes the auth params map and converts them to the expected encoded
json string of auth parameters.

Resolves spring-projects/spring-pulsar#500
@onobc
Copy link
Collaborator

onobc commented Dec 16, 2023

PR in Boot - hopefully we can get it squeezed in for the 3.2.1 release next week. 🤞🏻

@onobc
Copy link
Collaborator

onobc commented Dec 17, 2023

Closed via spring-projects/spring-boot@3d42dc7

@onobc onobc closed this as completed Dec 17, 2023
onobc added a commit to onobc/spring-pulsar that referenced this issue Dec 17, 2023
This commit fixes the name of the `pluginClassName` for the OAuth2
provider in authentication.adoc

See spring-projects#500
onobc added a commit that referenced this issue Dec 17, 2023
This commit fixes the name of the `pluginClassName` for the OAuth2
provider in authentication.adoc

See #500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug type: documentation A documentation update
Projects
None yet
2 participants