|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
package com.baiye.handle;
|
|
|
|
|
|
|
|
|
|
import com.baiye.http.CommonResponse;
|
|
|
|
|
import com.baiye.http.LoginResponse;
|
|
|
|
|
import com.baiye.http.ResponseCode;
|
|
|
|
|
import com.baiye.util.ResponseUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -24,38 +24,38 @@ import java.io.IOException;
|
|
|
|
|
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
|
|
|
|
|
CommonResponse<?> result;
|
|
|
|
|
LoginResponse<?> result;
|
|
|
|
|
String username = request.getParameter("username");
|
|
|
|
|
if (exception instanceof AccountExpiredException) {
|
|
|
|
|
// 账号过期
|
|
|
|
|
log.info("[登录失败] - 用户[{}]账号过期", username);
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_ACCOUNT_EXPIRED.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_ACCOUNT_EXPIRED.getDesc());
|
|
|
|
|
} else if (exception instanceof BadCredentialsException) {
|
|
|
|
|
// 密码错误
|
|
|
|
|
log.info("[登录失败] - 用户[{}]密码错误", username);
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_PASSWORD_ERROR.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_PASSWORD_ERROR.getDesc());
|
|
|
|
|
} else if (exception instanceof CredentialsExpiredException) {
|
|
|
|
|
// 密码过期
|
|
|
|
|
log.info("[登录失败] - 用户[{}]密码过期", username);
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_PASSWORD_EXPIRED.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_PASSWORD_EXPIRED.getDesc());
|
|
|
|
|
} else if (exception instanceof DisabledException) {
|
|
|
|
|
// 用户被禁用
|
|
|
|
|
log.info("[登录失败] - 用户[{}]被禁用", username);
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_DISABLED.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_DISABLED.getDesc());
|
|
|
|
|
|
|
|
|
|
} else if (exception instanceof LockedException) {
|
|
|
|
|
// 用户被锁定
|
|
|
|
|
log.info("[登录失败] - 用户[{}]被锁定", username);
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_LOCKED.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_LOCKED.getDesc());
|
|
|
|
|
|
|
|
|
|
} else if (exception instanceof InternalAuthenticationServiceException) {
|
|
|
|
|
// 内部错误
|
|
|
|
|
log.error(String.format("[登录失败] - [%s]内部错误", username));
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_LOGIN_FAIL.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_LOGIN_FAIL.getDesc());
|
|
|
|
|
} else {
|
|
|
|
|
// 其他错误
|
|
|
|
|
log.error(String.format("[登录失败] - [%s]其他错误", username), exception);
|
|
|
|
|
result = CommonResponse.createByErrorMessage(ResponseCode.USER_LOGIN_FAIL.getDesc());
|
|
|
|
|
result = LoginResponse.createByErrorMessage(ResponseCode.USER_LOGIN_FAIL.getDesc());
|
|
|
|
|
}
|
|
|
|
|
ResponseUtil.responseWriter(response, "UTF-8", HttpStatus.UNAUTHORIZED.value(), result);
|
|
|
|
|
}
|
|
|
|
|