master
parent
6b1f14facd
commit
c5aaca5163
|
|
@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
|
|
@ -67,8 +68,14 @@ public class SecurityHandlerConfig {
|
||||||
@Override
|
@Override
|
||||||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
||||||
AuthenticationException exception) throws IOException, ServletException {
|
AuthenticationException exception) throws IOException, ServletException {
|
||||||
ResponseInfo info = ResponseInfo.builder().code(HttpStatus.UNAUTHORIZED.value() + "")
|
String msg = null;
|
||||||
.message(exception.getMessage()).build();
|
if (exception instanceof BadCredentialsException) {
|
||||||
|
msg = "密码错误";
|
||||||
|
} else {
|
||||||
|
msg = exception.getMessage();
|
||||||
|
}
|
||||||
|
ResponseInfo info = ResponseInfo.builder().code(HttpStatus.UNAUTHORIZED.value() + "").message(msg)
|
||||||
|
.build();
|
||||||
ResponseUtil.responseJson(response, HttpStatus.UNAUTHORIZED.value(), info);
|
ResponseUtil.responseJson(response, HttpStatus.UNAUTHORIZED.value(), info);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue