fix(api): return forbidden for ownership denials
这个提交包含在:
父节点
63cc21d812
当前提交
f24e0356a7
@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.security.authorization.AuthorizationDeniedException;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
@ -69,8 +69,8 @@ public class GlobalExceptionHandler {
|
||||
.body(ApiResponse.error(405, "请求方法不支持: " + ex.getMethod()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(AuthorizationDeniedException.class)
|
||||
public ResponseEntity<ApiResponse<Void>> handleAuthorizationDenied(AuthorizationDeniedException ex, HttpServletRequest request) {
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
public ResponseEntity<ApiResponse<Void>> handleAuthorizationDenied(AccessDeniedException ex, HttpServletRequest request) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
String principal = authentication == null ? "anonymous" : String.valueOf(authentication.getPrincipal());
|
||||
String authorities = authentication == null ? "[]" : authentication.getAuthorities().toString();
|
||||
|
||||
@ -8,7 +8,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.security.authorization.AuthorizationDeniedException;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
@ -71,8 +71,8 @@ public class GlobalExceptionHandler {
|
||||
.body(ApiResponse.error(405, "请求方法不支持: " + ex.getMethod()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(AuthorizationDeniedException.class)
|
||||
public ResponseEntity<ApiResponse<Void>> handle(AuthorizationDeniedException ex, HttpServletRequest request) {
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
public ResponseEntity<ApiResponse<Void>> handle(AccessDeniedException ex, HttpServletRequest request) {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
String principal = auth == null ? "anonymous" : String.valueOf(auth.getPrincipal());
|
||||
String authorities = auth == null ? "[]" : auth.getAuthorities().toString();
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户