Skip to content

Commit

Permalink
Optimize login detection
Browse files Browse the repository at this point in the history
Signed-off-by: Zzm0809 <[email protected]>
  • Loading branch information
Zzm0809 committed Apr 16, 2024
1 parent ecd6ff9 commit c8e9d65
Show file tree
Hide file tree
Showing 53 changed files with 147 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Result<Void> busException(BusException e) {

@ExceptionHandler
@ResponseBody
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public Result<Void> notLoginException(NotLoginException notLoginException) {
ServletRequestAttributes servletRequestAttributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
Expand All @@ -91,7 +92,7 @@ public Result<Void> notLoginException(NotLoginException notLoginException) {
}

/**
* 参数异常处理程序 设置状态码为 400
* Parameter exception handler sets status code to 400
*
* @param e e
* @return {@link Result}<{@link String}>
Expand All @@ -101,11 +102,11 @@ public Result<Void> notLoginException(NotLoginException notLoginException) {
@ResponseBody
public Result<String> paramExceptionHandler(MethodArgumentNotValidException e) {
BindingResult exceptions = e.getBindingResult();
// 判断异常中是否有错误信息,如果存在就使用异常中的消息,否则使用默认消息
// Check if there is any error message in the exception. If there is, use the message in the exception. Otherwise, use the default message
if (exceptions.hasErrors()) {
List<ObjectError> errors = exceptions.getAllErrors();
if (!errors.isEmpty()) {
// 这里列出了全部错误参数,按正常逻辑,只需要第一条错误即可
// All incorrect parameters are listed here. According to normal logic, only the first error is needed
FieldError fieldError = (FieldError) errors.get(0);
if (StringUtils.isNotBlank(fieldError.getDefaultMessage())) {
return Result.paramsError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import com.fasterxml.jackson.databind.node.ObjectNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
Expand All @@ -62,6 +63,7 @@
@Api(tags = "OpenAPI & Task API Controller")
@RequestMapping("/openapi")
@RequiredArgsConstructor
@SaCheckLogin
public class APIController {

private final TaskService taskService;
Expand All @@ -70,7 +72,7 @@ public class APIController {
@GetMapping("/version")
@ApiOperation(value = "Query Service Version", notes = "Query Dinky Service Version Number")
public Result<String> getVersionInfo() {
return Result.succeed(DinkyVersion.getVersion(), "Get success");
return Result.succeed(DinkyVersion.getVersion(), Status.QUERY_SUCCESS);
}

@PostMapping("/submitTask")
Expand Down Expand Up @@ -200,6 +202,6 @@ public Result<String> exportSql(@RequestParam Integer id) {
dataTypeClass = Integer.class)
public Result getTaskLineage(@RequestParam Integer id) {
taskService.initTenantByTaskId(id);
return Result.succeed(taskService.getTaskLineage(id), "获取成功");
return Result.succeed(taskService.getTaskLineage(id), Status.QUERY_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dinky.data.result.Result;
import org.dinky.service.UserService;

import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -35,7 +36,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.Api;
Expand Down Expand Up @@ -92,8 +95,13 @@ public Result<Void> outLogin() {
*/
@GetMapping("/current")
@ApiOperation(value = "Current User Info", notes = "Current User Info")
public Result<UserDTO> getCurrentUserInfo() {
return userService.queryCurrentUserInfo();
@SaCheckLogin
public Result<UserDTO> getCurrentUserInfo(@CookieValue(name = "tenantId") Integer tenantId) {
if (tenantId == null) {
throw NotLoginException.newInstance(
"LOCAL", NotLoginException.NOT_TOKEN, NotLoginException.NOT_TOKEN_MESSAGE, null);
}
return userService.queryCurrentUserInfo(tenantId);
}

/**
Expand All @@ -105,6 +113,7 @@ public Result<UserDTO> getCurrentUserInfo() {
@PostMapping("/chooseTenant")
@ApiImplicitParam(name = "tenantId", value = "tenantId", required = true, dataTypeClass = Integer.class)
@ApiOperation(value = "Choose Tenant To Login", notes = "Choose Tenant To Login")
@SaCheckLogin
public Result<Tenant> switchingTenant(@RequestParam("tenantId") Integer tenantId) {
return userService.chooseTenant(tenantId);
}
Expand All @@ -116,12 +125,14 @@ public Result<Tenant> switchingTenant(@RequestParam("tenantId") Integer tenantId
*/
@GetMapping("/tokenInfo")
@ApiOperation(value = "Query Current User Token Info", notes = "Query Current User Token Info")
@SaCheckLogin
public Result<SaTokenInfo> getTokenInfo() {
return Result.succeed(StpUtil.getTokenInfo());
}

@GetMapping("/version")
@ApiOperation(value = "Query Service Version", notes = "Query Dinky Service Version Number")
@SaCheckLogin
public Result<Object> getVersionInfo() {
return Result.succeed((Object) DinkyVersion.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -51,6 +52,7 @@
@Api(tags = "Alert Group Controller")
@RequestMapping("/api/alertGroup")
@RequiredArgsConstructor
@SaCheckLogin
public class AlertGroupController {

private final AlertGroupService alertGroupService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
Expand All @@ -50,6 +51,7 @@
@Api(tags = "Alert History Controller")
@RequestMapping("/api/alertHistory")
@RequiredArgsConstructor
@SaCheckLogin
public class AlertHistoryController {

private final AlertHistoryService alertHistoryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -60,6 +61,7 @@
@Api(tags = "Alert Instance Controller")
@RequestMapping("/api/alertInstance")
@RequiredArgsConstructor
@SaCheckLogin
public class AlertInstanceController {

private final AlertInstanceService alertInstanceService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -53,6 +54,7 @@
@RestController
@RequestMapping("/api/alertRule")
@Api(tags = "Alert Rule Controller")
@SaCheckLogin
public class AlertRuleController {

private final AlertRuleService alertRuleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -48,6 +49,7 @@
@RestController
@RequestMapping("/api/alertTemplate")
@Api(tags = "Alert Template Controller")
@SaCheckLogin
public class AlertTemplateController {

private final AlertTemplateService alertTemplateService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import io.swagger.annotations.Api;
Expand All @@ -60,6 +61,7 @@
@Api(tags = "Catalogue Controller")
@RequestMapping("/api/catalogue")
@RequiredArgsConstructor
@SaCheckLogin
public class CatalogueController {

private final CatalogueService catalogueService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -58,6 +59,7 @@
@Api(tags = "Cluster Config Controller")
@RequestMapping("/api/clusterConfiguration")
@RequiredArgsConstructor
@SaCheckLogin
public class ClusterConfigurationController {

private final ClusterConfigurationService clusterConfigurationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -56,6 +57,7 @@
@Api(tags = "ClusterInstance Instance Controller")
@RequestMapping("/api/cluster")
@RequiredArgsConstructor
@SaCheckLogin
public class ClusterInstanceController {

private final ClusterInstanceService clusterInstanceService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -68,6 +69,7 @@
@Api(tags = "DataSource Controller")
@RequestMapping("/api/database")
@RequiredArgsConstructor
@SaCheckLogin
public class DataSourceController {

private final DataBaseService databaseService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -55,6 +56,7 @@
@Api(tags = "Document Controller")
@RequestMapping("/api/document")
@RequiredArgsConstructor
@SaCheckLogin
public class DocumentController {

private final DocumentService documentService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
Expand All @@ -41,6 +42,7 @@
@Slf4j
@Api(tags = "Flink Conf Controller", hidden = true)
@RequestMapping("/api/flinkConf")
@SaCheckLogin
@RequiredArgsConstructor
public class FlinkController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpRequest;
Expand All @@ -42,6 +43,7 @@
@Controller
@Api(tags = "Flink Proxy Controller", hidden = true, description = "Flink Proxy API")
@RequestMapping(FlinkProxyController.API)
@SaCheckLogin
public class FlinkProxyController {
public static final String API = "/api/flink/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.annotations.Api;
Expand All @@ -53,6 +54,7 @@
@Api(tags = "Fragment Controller")
@RequestMapping("/api/fragment")
@RequiredArgsConstructor
@SaCheckLogin
public class FragmentController {

private final FragmentVariableService fragmentVariableService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.bean.BeanUtil;
Expand All @@ -71,6 +72,7 @@
@Api(tags = "Git Project Controller")
@RequestMapping("/api/git")
@AllArgsConstructor
@SaCheckLogin
public class GitController {
final GitProjectService gitProjectService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import com.fasterxml.jackson.databind.JsonNode;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
Expand All @@ -49,6 +50,7 @@
@RestController
@RequestMapping("/api/history")
@RequiredArgsConstructor
@SaCheckLogin
public class HistoryController {

private final HistoryService historyService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
Expand All @@ -43,6 +44,7 @@
@Api(tags = "Home Controller")
@RequestMapping("/api/home")
@RequiredArgsConstructor
@SaCheckLogin
public class HomeController {

private final HomeService homeService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand All @@ -52,6 +53,7 @@
@Api(tags = "Jar Controller")
@RequestMapping("/api/jar")
@RequiredArgsConstructor
@SaCheckLogin
public class JarController {

private final TaskService taskService;
Expand Down
Loading

0 comments on commit c8e9d65

Please sign in to comment.