feat: 集群数据同步初步完成
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.fateverse.common.security.handle;
|
||||
|
||||
import cn.fateverse.common.security.utils.ResponseRender;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
@@ -35,24 +36,9 @@ public class AuthenticationEntryPointImpl implements AccessDeniedHandler, Authen
|
||||
|
||||
public void accessDenied(HttpServletRequest request, HttpServletResponse response) {
|
||||
String msg = StrFormatter.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
||||
renderString(response,Result.unauthorized(msg));
|
||||
ResponseRender.renderString(response,Result.unauthorized(msg));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将字符串渲染到客户端
|
||||
*
|
||||
* @param response 渲染对象
|
||||
* @param result 返回的错误对象
|
||||
*/
|
||||
public static void renderString(HttpServletResponse response, Result<String> result) {
|
||||
try {
|
||||
response.setStatus(result.getStatus().value());
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.fateverse.common.security.utils;
|
||||
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2024/4/19 9:09
|
||||
*/
|
||||
public class ResponseRender {
|
||||
/**
|
||||
* 将字符串渲染到客户端
|
||||
*
|
||||
* @param response 渲染对象
|
||||
* @param result 返回的错误对象
|
||||
*/
|
||||
public static void renderString(HttpServletResponse response, Result<Object> result) {
|
||||
try {
|
||||
response.setStatus(result.getStatus().value());
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.getWriter().print(JSON.toJSONString(result));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user