@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)该如何实现???
このクラスを書き換えて、それに検証コード検証を追加します
これは、Shiro による検証コードを追加する別の例です
public class CaptchaFormAuthenticationFilter extends FormAuthenticationFilter{
リーリー}
public class CaptchaUsernamePasswordToken extends UsernamePasswordToken {
リーリー}