Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 错误:UsernamePasswordAuthenticationToken无法强制转换为CustomAuthenticationTok_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Spring 错误:UsernamePasswordAuthenticationToken无法强制转换为CustomAuthenticationTok

Spring 错误:UsernamePasswordAuthenticationToken无法强制转换为CustomAuthenticationTok,spring,spring-mvc,spring-security,Spring,Spring Mvc,Spring Security,你好。 请帮助遇到此问题的任何人 我想运行自定义项目设置。 第3行的CustomUserDetailsAuthenticationProvider类中: public class CustomUserDetailsAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { ... 1 @Override 2 protected UserDetails retrieveUser(String user

你好。

请帮助遇到此问题的任何人

我想运行自定义项目设置。 第3行的CustomUserDetailsAuthenticationProvider类中:

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

3        CustomAuthenticationToken auth = (CustomAuthenticationToken) authentication;
我得到一个错误:

java.lang.ClassCastException:org.springframework.security.authentication.UsernamePasswordAuthenticationToken不能强制转换为secyry.authentication.loginpassworld.CustomAuthenticationToken

С诘问给出错误的答案

  if(auth instanceof UsernamePasswordAuthenticationToken){ //auth=null
            auth= (CustomAuthenticationToken) authentication;
        }
我理解这个错误,但我不能理解

  • 为什么应用此解决方案
  • 如何解决这个问题


  • 我用谷歌翻译了所有内容

    CustomAuthenticationToken是从UsernamePasswordAuthenticationToken扩展而来的吗<代码>公共类CustomAuthenticationToken扩展用户名PasswordAuthenticationToken欢迎使用stackoveflow。参观并获取您的第一个徽章是从UsernamePasswordAuthenticationToken扩展而来的CustomAuthenticationToken吗?公共类CustomAuthenticationToken扩展UsernamePasswordAuthenticationToken-是。一切正常,我找到了原因,它没有正确打开。addFilterBefore(authenticationFilter(),UsernamePasswordAuthenticationFilter.class),响应在这里。CustomAuthenticationToken是否从UsernamePasswordAuthenticationToken扩展而来<代码>公共类CustomAuthenticationToken扩展用户名PasswordAuthenticationToken欢迎使用stackoveflow。参观并获取您的第一个徽章是从UsernamePasswordAuthenticationToken扩展而来的CustomAuthenticationToken吗?公共类CustomAuthenticationToken扩展UsernamePasswordAuthenticationToken-是。一切正常,我找到了原因,它没有正确打开。addFilterBefore(authenticationFilter(),UsernamePasswordAuthenticationFilter.class),响应在这里。