添加了一些注释,删除了一些无效注释

master
ArgonarioD 2023-01-14 17:05:06 +08:00
parent 1cfed731e7
commit 817746871a
2 changed files with 3 additions and 7 deletions

View File

@ -25,29 +25,24 @@ public class ExceptionHandlerAdvice {
@ExceptionHandler(UnauthorizedException.class) @ExceptionHandler(UnauthorizedException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseStatus(HttpStatus.UNAUTHORIZED)
public ResponseMap handleUnauthorizedException(Exception e) { public ResponseMap handleUnauthorizedException(Exception e) {
// log.error(ExceptionUtils.getStackTrace(e));
// log.error(e.getMessage(), e);
return ResponseMap.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage()); return ResponseMap.of(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
} }
@ExceptionHandler(BadRequestException.class) @ExceptionHandler(BadRequestException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseMap handleBadRequestException(BadRequestException e) { public ResponseMap handleBadRequestException(BadRequestException e) {
// log.error(e.getMessage(), e);
return ResponseMap.of(HttpStatus.BAD_REQUEST.value(), e.getMessage()); return ResponseMap.of(HttpStatus.BAD_REQUEST.value(), e.getMessage());
} }
@ExceptionHandler(ForbiddenException.class) @ExceptionHandler(ForbiddenException.class)
@ResponseStatus(HttpStatus.FORBIDDEN) @ResponseStatus(HttpStatus.FORBIDDEN)
public ResponseMap handleForbiddenException(ForbiddenException e) { public ResponseMap handleForbiddenException(ForbiddenException e) {
// log.error(e.getMessage(), e);
return ResponseMap.of(HttpStatus.FORBIDDEN.value(), e.getMessage()); return ResponseMap.of(HttpStatus.FORBIDDEN.value(), e.getMessage());
} }
@ExceptionHandler(BindException.class) @ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseMap handleBindException(BindException e) { public ResponseMap handleBindException(BindException e) {
// log.error(e.getMessage(), e);
return ResponseMap.of(HttpStatus.BAD_REQUEST.value(), return ResponseMap.of(HttpStatus.BAD_REQUEST.value(),
e.getAllErrors().stream() e.getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage) .map(DefaultMessageSourceResolvable::getDefaultMessage)
@ -58,7 +53,6 @@ public class ExceptionHandlerAdvice {
@ExceptionHandler(TooManyRequestException.class) @ExceptionHandler(TooManyRequestException.class)
@ResponseStatus(HttpStatus.TOO_MANY_REQUESTS) @ResponseStatus(HttpStatus.TOO_MANY_REQUESTS)
public ResponseMap handleTooManyRequestException(TooManyRequestException e) { public ResponseMap handleTooManyRequestException(TooManyRequestException e) {
// log.error(e.getMessage(), e);
return ResponseMap.of(HttpStatus.TOO_MANY_REQUESTS.value(), e.getMessage()); return ResponseMap.of(HttpStatus.TOO_MANY_REQUESTS.value(), e.getMessage());
} }
} }

View File

@ -48,15 +48,17 @@ public class ProjectAuthorizeAOP {
Integer projectAccessLevel = null; Integer projectAccessLevel = null;
if (expression.contains("a")) { // 如果涉及到项目权限 if (expression.contains("a")) { // 如果涉及到项目权限
Integer staffId = HttpUtils.getAttribute(attributes, TokenUtils.STAFF_ID); Integer staffId = HttpUtils.getAttribute(attributes, TokenUtils.STAFF_ID);
// 获取路径参数中的projectId
Map<String, String> pathVariables = ((Map<String, String>) (attributes Map<String, String> pathVariables = ((Map<String, String>) (attributes
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST))); .getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)));
assert pathVariables != null; assert pathVariables != null;
Integer projectId = Integer.parseInt(pathVariables.get("projectId")); Integer projectId = Integer.parseInt(pathVariables.get("projectId"));
// 获取项目权限并将项目权限和项目记录本身放入RequestAttribute中
projectAccessLevel = projectGroupService.getProjectAccessLevel(staffId, globalAccessLevel, projectId); projectAccessLevel = projectGroupService.getProjectAccessLevel(staffId, globalAccessLevel, projectId);
attributes.setAttribute(TokenUtils.PROJECT_ACCESS_LEVEL, projectAccessLevel, RequestAttributes.SCOPE_REQUEST); attributes.setAttribute(TokenUtils.PROJECT_ACCESS_LEVEL, projectAccessLevel, RequestAttributes.SCOPE_REQUEST);
attributes.setAttribute(TokenUtils.TARGET_PROJECT, projectService.getById(projectId), RequestAttributes.SCOPE_REQUEST); attributes.setAttribute(TokenUtils.TARGET_PROJECT, projectService.getById(projectId), RequestAttributes.SCOPE_REQUEST);
} }
// 解析SpEL表达式 // 解析SpEL表达式,进行鉴权
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
Boolean result = parser.parseExpression(expression) Boolean result = parser.parseExpression(expression)
.getValue(new ValidateObject(globalAccessLevel, projectAccessLevel), Boolean.class); .getValue(new ValidateObject(globalAccessLevel, projectAccessLevel), Boolean.class);