Spring 错误:UsernamePasswordAuthenticationToken无法强制转换为CustomAuthenticationTok
你好。 请帮助遇到此问题的任何人 我想运行自定义项目设置。 第3行的CustomUserDetailsAuthenticationProvider类中: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
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),响应在这里。