优化Auth

This commit is contained in:
Richie 2024-03-17 21:49:36 +08:00
parent 2e82dc2b49
commit 1f6eb35fad
2 changed files with 5 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package com.qihang.security;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.qihang.common.common.R; import com.qihang.common.common.R;
import com.qihang.common.enums.HttpStatus;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@ -32,7 +33,7 @@ public class AuthenticationExceptionHandler implements AuthenticationEntryPoint
if (message == null) { if (message == null) {
message = "认证失败!"; message = "认证失败!";
} }
R res = R.error(500, message); R res = R.error(HttpStatus.ERROR, message);
writer = response.getWriter(); writer = response.getWriter();
writer.append(JSON.toJSONString(res)); writer.append(JSON.toJSONString(res));
} catch (IOException e) { } catch (IOException e) {

View File

@ -3,6 +3,7 @@ package com.qihang.security;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.qihang.common.common.R; import com.qihang.common.common.R;
import com.qihang.common.enums.HttpStatus;
import jakarta.servlet.FilterChain; import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -71,9 +72,9 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
PrintWriter writer = null; PrintWriter writer = null;
try { try {
if (message == null) { if (message == null) {
message = "403 Forbidden"; message = "401 Forbidden";
} }
R res = R.error(403, message); R res = R.error(HttpStatus.UNAUTHORIZED, message);
writer = response.getWriter(); writer = response.getWriter();
writer.append(JSON.toJSONString(res)); writer.append(JSON.toJSONString(res));
} catch (IOException e) { } catch (IOException e) {