SaiUpadhyayula / spring-reddit-clone

Reddit clone built using Spring Boot, Spring Security with JWT Authentication, Spring Data JPA with MySQL, Spring MVC. The frontend is built using Angular - You can find the frontend source code here - https://github.com/SaiUpadhyayula/angular-reddit-clone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Class cast exception while getting UserDetails from Principal

VladyslavHolik opened this issue · comments

org.springframework.security.core.userdetails.User principal = (org.springframework.security.core.userdetails.User) SecurityContextHolder.

image
Issue occures while creating Post using JWT, since Authentication has JWT object, not UserDetails.
In order to fix, just change type, or simply get username without casting Principle

Hello @VladyslavHolik can you please give a working example about the fix when you say "just change type, or simply get username without casting Principle". I'm still facing this issue. Thank you in advance.

Hello @VladyslavHolik I'm also having the same issue and couldn't fix it on my own. Tried so many solutions on stack overflow and none worked. Could you please provide a working example or a quick fix ?
Thank you in advance

I will check this out tomorrow, I am traveling today. @samwel89 @Anas-Ben-Oughrem

Fixed as part of this commit - 4f389dc

Thanks @SaiUpadhyayula, the fix works !

Thank you @SaiUpadhyayula it works just fine. I would loke to note in the same occasion that swagger doesn't work for me. The index page always shows a 404 error