@Component
public class MyAuthenticationProvider implements AuthenticationProvider {
@Autowired
private CustomUserDetailsService userService;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
String password = (String) authentication.getCredentials();
CustomUserDetails user = (CustomUserDetails) userService.loadUserByUsername(username);
if(user == null){
throw new BadCredentialsException("用户不存在");
}
if (!password.equals(user.getPassword())) {
throw new BadCredentialsException("错误的密码");
}
Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
return new UsernamePasswordAuthenticationToken(user, password, authorities);
}
@Override
public boolean supports(Class<?> arg0) {
return true;
}
}
在springBoot项目中有这个类验证用户名和密码。现在想添加图片验证码(Kaptcha)该如何实现???
Hanya tulis semula kelas ini dan tambahkan pengesahan kod pengesahan padanya;
Berikut ialah satu lagi contoh kaedah Shiro untuk menambah kod pengesahan
CatchaFormAuthenticationFilter kelas awam memanjangkan FormAuthenticationFilter{
}
kelas awam CaptchaUsernamePasswordToken memanjangkan UsernamePasswordToken {
}