* 重写父类方法,在shiro执行登录时先对比验证码,正确后在登录,否则直接登录失败
*/
@Override
protected boolean executeLogin(ServletRequest request,ServletResponse response) throws Exception {
Session session = SystemVariableUtils.createSessionIfNull();
//获取登录错误次数
Integer number = (Integer) session.getAttribute(getLoginIncorrectNumberKeyAttribute());
//首次登录,将该数量记录在session中
if (number == null) {
number = new Integer(1);
session.setAttribute(getLoginIncorrectNumberKeyAttribute(), number);
}
//如果登录次数大于allowIncorrectNumber,需要判断验证码是否一致
if (number > getAllowIncorrectNumber()) {
//获取当前验证码
String currentCaptcha = (String) session.getAttribute(getSessionCaptchaKeyAttribute());
//获取用户输入的验证码
String submitCaptcha = getCaptcha(request);
//如果验证码不匹配,登录失败
if (StringUtils.isEmpty(submitCaptcha) || !StringUtils.equals(currentCaptcha,submitCaptcha.toLowerCase())) {
return onLoginFailure(this.createToken(request, response), new AccountException("验证码不正确"), request, response);