java.lang.ClassCastException: org.springframework.security.oauth2.core.user.OAuth2UserAuthority cannot be cast to org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority
at com.octo.frontendauth.config.SecurityConfiguration.lambda$null$1(SecurityConfiguration.java:108)
at java.lang.Iterable.forEach(Iterable.java:75)
at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1080)
at com.octo.frontendauth.config.SecurityConfiguration.lambda$userAuthoritiesMapper$2(SecurityConfiguration.java:106)
at org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:120)
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175)
at org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter.attemptAuthentication(OAuth2LoginAuthenticationFilter.java:186)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter.doFilterInternal(OAuth2AuthorizationRequestRedirectFilter.java:160)
Are you developing a monolith or a microservices architecture? If it’s just a monolith, can you show us your .yo-rc.json file and provide steps to reproduce?
You don’t need the “access-token-uri” and “user-authorization-uri” values. Can you try removing them? You might also check out my recent blog post on using JHipster 6 with Okta. It includes a screencast if you prefer video.
java.lang.ClassCastException: org.springframework.security.oauth2.core.user.OAuth2UserAuthority cannot be cast to org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority
at com.octo.frontendauth.config.SecurityConfiguration.lambda$null$1(SecurityConfiguration.java:108)
at java.lang.Iterable.forEach(Iterable.java:75)
at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1080)
at com.octo.frontendauth.config.SecurityConfiguration.lambda$userAuthoritiesMapper$2(SecurityConfiguration.java:106)
at org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:120)
You probably missed a configuration step where you need to add a “groups” claim to the ID token. There are instructions in the blog post and in JHipster’s security docs.
If it doesn’t work with this configuration, I’d try remove the “groups” claim that’s in the access token, as well as the “roles” claim. You only need one.
tried removing groups claims in access token and roles claim as well Still the same original error.
java.lang.ClassCastException: org.springframework.security.oauth2.core.user.OAuth2UserAuthority cannot be cast to org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority
Hi @mraible I delete .yo-rc-json file and recreated the project from scratch again and it worked fine this time. very weird. But anyways thank for your help !