초기소스
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.wb.domainserver.security.handler;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); // 1
|
||||
response.setStatus(HttpStatus.FORBIDDEN.value());
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
|
||||
response.getWriter().write("권한 불충분 %s".formatted(accessDeniedException.getMessage())); // 2
|
||||
response.getWriter().flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user