From 2621a850a9cec2c9d656e43df8da1ea9f9715755 Mon Sep 17 00:00:00 2001 From: moec42frf <3378620026@qq.com> Date: Sun, 30 Apr 2023 09:14:28 +0800 Subject: [PATCH] ADD file via upload --- .../AuthenticationAccessDeniedHandler.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 blogserver/src/main/java/org/sang/config/AuthenticationAccessDeniedHandler.java diff --git a/blogserver/src/main/java/org/sang/config/AuthenticationAccessDeniedHandler.java b/blogserver/src/main/java/org/sang/config/AuthenticationAccessDeniedHandler.java new file mode 100644 index 0000000..7aec317 --- /dev/null +++ b/blogserver/src/main/java/org/sang/config/AuthenticationAccessDeniedHandler.java @@ -0,0 +1,23 @@ +package org.sang.config; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + + +public class AuthenticationAccessDeniedHandler implements AccessDeniedHandler { + @Override + public void handle(HttpServletRequest httpServletRequest, HttpServletResponse resp, AccessDeniedException e) throws IOException, ServletException { + resp.setStatus(HttpServletResponse.SC_FORBIDDEN); + resp.setCharacterEncoding("UTF-8"); + PrintWriter out = resp.getWriter(); + out.write("权限不足,请联系管理员!"); + out.flush(); + out.close(); + } +}