修改401返回

This commit is contained in:
sh
2026-05-20 12:47:33 +08:00
parent f2f12d72a1
commit 587e98cfa8
2 changed files with 22 additions and 1 deletions

View File

@@ -152,6 +152,27 @@ public class ServletUtils
}
}
/**
* 将字符串渲染到客户端——不转移
*
* @param response 渲染对象
* @param string 待渲染的字符串
*/
public static void renderStringRaw(HttpServletResponse response, String string)
{
try
{
response.setStatus(200);
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
response.getWriter().print(string);
}
catch (IOException e)
{
e.printStackTrace();
}
}
/**
* HTML转义修复XSS漏洞
* @param content

View File

@@ -29,7 +29,7 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
{
int code = HttpStatus.UNAUTHORIZED;
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.unAuth(code, msg)));
ServletUtils.renderStringRaw(response, JSON.toJSONString(AjaxResult.unAuth(code, msg)));
// response.setStatus(HttpStatus.UNAUTHORIZED);
}
}