-
Notifications
You must be signed in to change notification settings - Fork 6k
ClassCastException when use oidcUserService delegate #9512
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
Comments
@kazakovav I took a look at your sample and it needs to be simplified so it follows a Minimal Reproducible Example. Your sample is expecting a running Keycloak instance and there are no directions on how to reproduce the error. Please update the sample so it's easy for me to reproduce. As an FYI, this sample uses Keycloak, so you might want to look at it and compare to your sample. |
Sorry!
|
@kazakovav The following error:
seems like it's related to the docker image as I've never seen such an error. I'd rather take docker out of the mix to ensure the sample is as minimal as possible. This sample uses Keycloak without docker. Please modify your sample to exclude docker. |
I have a similar error message: Caused by: java.lang.ClassCastException: class com.nimbusds.jose.Algorithm cannot be cast to class com.nimbusds.jose.JWSAlgorithm (com.nimbusds.jose.Algorithm and com.nimbusds.jose.JWSAlgorithm are in unnamed module of loader 'app')
at org.springframework.security.oauth2.jwt.JwtDecoderProviderConfigurationUtils.getSignatureAlgorithms(JwtDecoderProviderConfigurationUtils.java:93) ~[spring-security-oauth2-jose-5.5.0-M3.jar:5.5.0-M3]
at org.springframework.security.oauth2.jwt.JwtDecoders.withProviderConfiguration(JwtDecoders.java:122) ~[spring-security-oauth2-jose-5.5.0-M3.jar:5.5.0-M3]
at org.springframework.security.oauth2.jwt.JwtDecoders.fromOidcIssuerLocation(JwtDecoders.java:66) ~[spring-security-oauth2-jose-5.5.0-M3.jar:5.5.0-M3]
at ec.edu.ups.talos.config.SecurityConfiguration.jwtDecoder(SecurityConfiguration.java:100) ~[main/:na] I was trying to create a Decoder with: NimbusJwtDecoder jwtDecoder = JwtDecoders.fromOidcIssuerLocation(issuer); |
Thanks for your feedback @wsaca. This is a similar error message that @kazakovav is getting. Is your application deployed within a container, e.g. docker image? |
@jgrandja I'm not running the app on docker, it's using JDK 15 and the configuration is not complex: http
.csrf()
.disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/graphql/**").authenticated()
.and()
.oauth2ResourceServer()
.jwt()
.decoder(jwtDecoder()) |
Thanks @wsaca. Ok then it looks like a JDK version incompatibility. Can you try with JDK 11 (or older) and let me know if the problem persists. @kazakovav Can you try as well. |
@jgrandja I tested with JDK 11 and 1.8 but Im getting the same error. Caused by: java.lang.ClassCastException: com.nimbusds.jose.Algorithm cannot be cast to com.nimbusds.jose.JWSAlgorithm
at org.springframework.security.oauth2.jwt.JwtDecoderProviderConfigurationUtils.getSignatureAlgorithms(JwtDecoderProviderConfigurationUtils.java:93) ~[spring-security-oauth2-jose-5.5.0-M3.jar:5.5.0-M3]
at org.springframework.security.oauth2.jwt.JwtDecoders.withProviderConfiguration(JwtDecoders.java:122) ~[spring-security-oauth2-jose-5.5.0-M3.jar:5.5.0-M3]
at org.springframework.security.oauth2.jwt.JwtDecoders.fromOidcIssuerLocation(JwtDecoders.java:66) ~[spring-security-oauth2-jose-5.5.0-M3.jar:5.5.0-M3] Im using Spring Boot 2.5.0-M3, maybe this is not about my configuration because with Spring Boot 2.4.4 it's working. |
Algorithm is not an interface or abstract class, nimbus is creating the Algorithm using this method: public static Algorithm parse(String s) {
return s == null ? null : new Algorithm(s);
} This line cant be parsed on JwtDecoderProviderConfigurationUtils.getSignatureAlgorithms(...): jwsAlgorithms.add((JWSAlgorithm)jwk.getAlgorithm()); I think this code should be: jwsAlgorithms.add(JWSAlgorithm.parse(jwk.getAlgorithm().getName())); or work with the class Algorithm: Set<Algorithm> jwsAlgorithms = new HashSet<>(); |
@wsaca Can you please put together a minimal reproducible sample and I'll take a look. |
@wsaca Also, please log a new ticket as your issue is similar BUT different than this issue. This issue is related to
And your issue is related to |
I have the same problem, delegate OidcUserService works fine in Spring Boot 2.3.7.Release, but an error occurs after upgrading to version 2.4.4. Error log:
This is my minimum reproduction sample. login.zip |
@XhstormR Thanks for providing a sample. I got a different error on my end:
The reason for this is because there is a binary incompatibility with the Nimbus dependency managed by Spring Boot and Spring Security. Spring Boot |
@kazakovav @wsaca See comment. Recently there was a binary incompatibility (see gh-9399 gh-9400) issue with the Nimbus dependency managed by Spring Boot and Spring Security. Please ensure your application is using supported release versions, e.g. Spring Boot I believe if you try with Spring Boot I'm going to close this issue as resolved. If you're still experiencing the issue we can reopen. |
@jgrandja I try to run the example of @kazakovav, but the same issue displayed with Spring Boot 2.4.4 and newest version, with older version like 2.3.9.REALESE app can't even start |
To start change
to
|
Hello!
I try to login user in my application, when using OAuth2 client and spring-boot-starter-parent:2.4.4.
But, When I use spring-boot-starter-parent:2.3.9.RELEASE, it's works correctly
run application and try to log in
please, see example in
https://github.com/kazakovav/spring-boot-keycloak/tree/main/demo-keycloak-oauth
The text was updated successfully, but these errors were encountered: