Error: UsernamePasswordAuthenticationToken cannot be cast to CustomAuthenticationToke

Viewed 1124

HI.

Please help anyone who has encountered this problem.

I want to run an example Custom Project Setup. In class CustomUserDetailsAuthenticationProvider in line 3:

 public class CustomUserDetailsAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
...
1 @Override
2    protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
            throws AuthenticationException {

3        CustomAuthenticationToken auth = (CustomAuthenticationToken) authentication;

I get an error:

java.lang.ClassCastException: org.springframework.security.authentication.UsernamePasswordAuthenticationToken cannot be cast to secyriry.authentication.loginpassworld.CustomAuthenticationToken

Сhecking gives false

  if(auth instanceof UsernamePasswordAuthenticationToken){ //auth=null
            auth= (CustomAuthenticationToken) authentication;
        }

I understand the error but I can't understand it

  1. Why this solution was applied
  2. How to fix the situation

sreen1

sreen2


I translated everything using GOOGLE

0 Answers
Related