0

I have a traditional Oauth2 setup for my micro services. When i try to use

CustomUserDetails principal = (CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

It always gives me ClassCastException string can not cast to CustomUserDetails. SecurityContextHolder.getContext().getAuthentication().getPrincipal() is always string , i.e : my username.

Please help if any one solved this problem.

Eugen
  • 877
  • 6
  • 16
Sivannarayan
  • 31
  • 1
  • 3
  • Can you show how you have defined your custom UserDetailService please ? – e.g78 Dec 21 '18 at 12:26
  • Seems like it’s duplicate of the following questions: https://stackoverflow.com/questions/6161985/get-userdetails-object-from-security-context-in-spring-mvc-controller – Rauf Aghayev Dec 22 '18 at 20:18

0 Answers0