package com.gkhy.safePlatform.config.security.customzie;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
import org.springframework.stereotype.Component;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
|
/**
|
* 用来解决认证过的用户访问无权限资源时的异常
|
*/
|
@Component
|
public class CustomizeAccessDeniedHandler extends JSONAuthentication implements AccessDeniedHandler {
|
@Override
|
public void handle(HttpServletRequest req, HttpServletResponse resp, AccessDeniedException e) throws IOException {
|
ResultVO result = new ResultVO<>(ResultCodes.CLIENT_PERMISSION_NOT_ALLOW);
|
this.writeJSON(req,resp,JSONObject.toJSONString(result));
|
}
|
}
|