@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)该如何实现???
Rewrite this class and add verification code verification to it;
Here is another example of Shiro’s method of adding verification code
public class CaptchaFormAuthenticationFilter extends FormAuthenticationFilter{
}
public class CaptchaUsernamePasswordToken extends UsernamePasswordToken {
}