41 lines
1.6 KiB
Java
41 lines
1.6 KiB
Java
package business.common.handler;
|
||
|
||
import business.common.utils.ResponseTool;
|
||
import business.common.vo.result.ResponseCode;
|
||
import business.common.vo.result.ResponseVo;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.http.MediaType;
|
||
import org.springframework.security.core.AuthenticationException;
|
||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import java.io.IOException;
|
||
|
||
/**
|
||
* @author charry 用来解决匿名用户访问无权限资源时的异常
|
||
*/
|
||
@Slf4j
|
||
@Component
|
||
public class RedStarAuthExceptionEntryPoint implements AuthenticationEntryPoint {
|
||
|
||
@Override
|
||
public void commence(HttpServletRequest request, HttpServletResponse response,
|
||
AuthenticationException authException) throws IOException {
|
||
int status = HttpServletResponse.SC_OK;
|
||
String message = "token不合法";
|
||
if (StringUtils.containsIgnoreCase(message, "Invalid access token")) {
|
||
message = "访问令牌不正确";
|
||
}
|
||
if (StringUtils.containsIgnoreCase(message, "Full authentication is required to access this resource")) {
|
||
message = "请求头client信息不正确,烦请核对";
|
||
status = HttpServletResponse.SC_OK;
|
||
}
|
||
log.error(message, authException);
|
||
ResponseVo vo = new ResponseVo(ResponseCode.SYSTEM_LOGIN_EXPIRE_EXCEPTION.getCode(), message);
|
||
ResponseTool.makeResponse(response, MediaType.APPLICATION_JSON_VALUE, status, vo);
|
||
}
|
||
}
|