Unverified Commit 2fd0baa9 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Optimization] Optimize login detection (#3405)

parent 0f5acd0d
......@@ -77,6 +77,7 @@ public class WebExceptionHandler {
@ExceptionHandler
@ResponseBody
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public Result<Void> notLoginException(NotLoginException notLoginException) {
ServletRequestAttributes servletRequestAttributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
......@@ -91,7 +92,7 @@ public class WebExceptionHandler {
}
/**
* 参数异常处理程序 设置状态码为 400
* Parameter exception handler sets status code to 400
*
* @param e e
* @return {@link Result}<{@link String}>
......@@ -101,11 +102,12 @@ public class WebExceptionHandler {
@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(
......
......@@ -47,6 +47,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -62,6 +63,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "OpenAPI & Task API Controller")
@RequestMapping("/openapi")
@RequiredArgsConstructor
@SaCheckLogin
public class APIController {
private final TaskService taskService;
......@@ -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")
......@@ -200,6 +202,6 @@ public class APIController {
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);
}
}
......@@ -27,6 +27,7 @@ import org.dinky.data.model.rbac.Tenant;
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;
......@@ -35,7 +36,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -92,8 +95,13 @@ public class AdminController {
*/
@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);
}
/**
......@@ -105,6 +113,7 @@ public class AdminController {
@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);
}
......@@ -116,12 +125,14 @@ public class AdminController {
*/
@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());
}
......
......@@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -51,6 +52,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Alert Group Controller")
@RequestMapping("/api/alertGroup")
@RequiredArgsConstructor
@SaCheckLogin
public class AlertGroupController {
private final AlertGroupService alertGroupService;
......
......@@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -50,6 +51,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Alert History Controller")
@RequestMapping("/api/alertHistory")
@RequiredArgsConstructor
@SaCheckLogin
public class AlertHistoryController {
private final AlertHistoryService alertHistoryService;
......
......@@ -44,6 +44,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -60,6 +61,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Alert Instance Controller")
@RequestMapping("/api/alertInstance")
@RequiredArgsConstructor
@SaCheckLogin
public class AlertInstanceController {
private final AlertInstanceService alertInstanceService;
......
......@@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -53,6 +54,7 @@ import lombok.RequiredArgsConstructor;
@RestController
@RequestMapping("/api/alertRule")
@Api(tags = "Alert Rule Controller")
@SaCheckLogin
public class AlertRuleController {
private final AlertRuleService alertRuleService;
......
......@@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -48,6 +49,7 @@ import lombok.RequiredArgsConstructor;
@RestController
@RequestMapping("/api/alertTemplate")
@Api(tags = "Alert Template Controller")
@SaCheckLogin
public class AlertTemplateController {
private final AlertTemplateService alertTemplateService;
......
......@@ -41,6 +41,7 @@ import org.springframework.web.bind.annotation.RequestParam;
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;
......@@ -60,6 +61,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Catalogue Controller")
@RequestMapping("/api/catalogue")
@RequiredArgsConstructor
@SaCheckLogin
public class CatalogueController {
private final CatalogueService catalogueService;
......
......@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -58,6 +59,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Cluster Config Controller")
@RequestMapping("/api/clusterConfiguration")
@RequiredArgsConstructor
@SaCheckLogin
public class ClusterConfigurationController {
private final ClusterConfigurationService clusterConfigurationService;
......
......@@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -56,6 +57,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "ClusterInstance Instance Controller")
@RequestMapping("/api/cluster")
@RequiredArgsConstructor
@SaCheckLogin
public class ClusterInstanceController {
private final ClusterInstanceService clusterInstanceService;
......
......@@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -68,6 +69,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "DataSource Controller")
@RequestMapping("/api/database")
@RequiredArgsConstructor
@SaCheckLogin
public class DataSourceController {
private final DataBaseService databaseService;
......
......@@ -41,6 +41,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -55,6 +56,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Document Controller")
@RequestMapping("/api/document")
@RequiredArgsConstructor
@SaCheckLogin
public class DocumentController {
private final DocumentService documentService;
......
......@@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.GetMapping;
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;
......@@ -41,6 +42,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@Api(tags = "Flink Conf Controller", hidden = true)
@RequestMapping("/api/flinkConf")
@SaCheckLogin
@RequiredArgsConstructor
public class FlinkController {
......
......@@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletResponse;
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;
......@@ -42,6 +43,7 @@ import lombok.SneakyThrows;
@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/";
......
......@@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -53,6 +54,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Fragment Controller")
@RequestMapping("/api/fragment")
@RequiredArgsConstructor
@SaCheckLogin
public class FragmentController {
private final FragmentVariableService fragmentVariableService;
......
......@@ -53,6 +53,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
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;
......@@ -71,6 +72,7 @@ import lombok.AllArgsConstructor;
@Api(tags = "Git Project Controller")
@RequestMapping("/api/git")
@AllArgsConstructor
@SaCheckLogin
public class GitController {
final GitProjectService gitProjectService;
......
......@@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -49,6 +50,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@RequestMapping("/api/history")
@RequiredArgsConstructor
@SaCheckLogin
public class HistoryController {
private final HistoryService historyService;
......
......@@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.GetMapping;
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;
......@@ -43,6 +44,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Home Controller")
@RequestMapping("/api/home")
@RequiredArgsConstructor
@SaCheckLogin
public class HomeController {
private final HomeService homeService;
......
......@@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.PostMapping;
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;
......@@ -52,6 +53,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Jar Controller")
@RequestMapping("/api/jar")
@RequiredArgsConstructor
@SaCheckLogin
public class JarController {
private final TaskService taskService;
......
......@@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.JsonNode;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.Dict;
import io.swagger.annotations.Api;
......@@ -68,6 +69,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Job Instance Controller")
@RequestMapping("/api/jobInstance")
@RequiredArgsConstructor
@SaCheckLogin
public class JobInstanceController {
private final JobInstanceService jobInstanceService;
......
......@@ -42,6 +42,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -71,6 +72,7 @@ public class LdapController {
@GetMapping("/testConnection")
@ApiOperation("Test connection to LDAP server")
@SaCheckLogin
@Log(title = "Test connection to LDAP server", businessType = BusinessType.TEST)
public Result<Integer> testConnection() {
List<User> users = ldapService.listUsers();
......@@ -83,6 +85,7 @@ public class LdapController {
@GetMapping("/listUser")
@ApiOperation("List user from LDAP server")
@SaCheckLogin
public Result<List<User>> listUser() {
List<User> users = ldapService.listUsers();
List<User> localUsers = userService.list();
......@@ -98,6 +101,7 @@ public class LdapController {
@PostMapping("/importUsers")
@ApiOperation("Import users from LDAP server")
@SaCheckLogin
@Log(title = "Import users from LDAP server", businessType = BusinessType.IMPORT)
@ApiImplicitParam(name = "users", value = "User list", required = true, dataType = "List<User>")
public Result<Void> importUsers(@RequestBody List<User> users) {
......@@ -115,6 +119,7 @@ public class LdapController {
* @return {@link Result}{@link UserDTO} obtain the user's UserDTO
*/
@PostMapping("/testLogin")
@SaCheckLogin
@ApiOperation("Test login to LDAP server")
@Log(title = "Test login to LDAP server", businessType = BusinessType.TEST)
@ApiImplicitParam(name = "loginDTO", value = "Login information", required = true, dataType = "LoginDTO")
......
......@@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RestController;
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.ApiImplicitParams;
......@@ -48,6 +49,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Log Controller")
@RequestMapping("/api/log")
@SaCheckLogin
@RequiredArgsConstructor
public class LogController {
......
......@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -53,6 +54,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Menu Controller")
@RequestMapping("/api/menu")
@RequiredArgsConstructor
@SaCheckLogin
public class MenuController {
private final MenuService menuService;
......
......@@ -44,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Opt;
......@@ -59,6 +60,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Monitor Controller")
@RequestMapping("/api/monitor")
@RequiredArgsConstructor
@SaCheckLogin
public class MonitorController {
private final MonitorService monitorService;
......
......@@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestBody;
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.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
......@@ -41,6 +42,7 @@ import lombok.AllArgsConstructor;
@Api(tags = "Print Table Controller")
@AllArgsConstructor
@RequestMapping("/api/printTable")
@SaCheckLogin
public class PrintTableController {
private final PrintTableService printTableService;
......
......@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -44,6 +45,7 @@ import lombok.RequiredArgsConstructor;
@RestController
@Api(tags = "Process Controller")
@RequestMapping("/api/process")
@SaCheckLogin
@RequiredArgsConstructor
public class ProcessController {
......
......@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -53,6 +54,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Resource Controller")
@RequestMapping("/api/resource")
@RequiredArgsConstructor
@SaCheckLogin
public class ResourceController {
private final ResourcesService resourcesService;
......
......@@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
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.lang.Dict;
......@@ -58,6 +59,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Role Controller")
@RequestMapping("/api/role")
@SaCheckLogin
@RequiredArgsConstructor
public class RoleController {
......
......@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -42,6 +43,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Role Menu Controller")
@RequestMapping("/api/roleMenu")
@SaCheckLogin
@RequiredArgsConstructor
public class RoleMenuController {
......
......@@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -50,6 +51,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "RowPermissions Controller")
@RestController
@RequestMapping("/api/rowPermissions")
@SaCheckLogin
public class RowPermissionsController {
@Autowired
......
......@@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
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;
......@@ -50,6 +51,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "SavePoints Controller")
@RequestMapping("/api/savepoints")
@SaCheckLogin
@RequiredArgsConstructor
public class SavePointsController {
......
......@@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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;
......@@ -44,6 +45,7 @@ import lombok.RequiredArgsConstructor;
@RestController
@RequestMapping("/api/scheduler")
@Api(tags = "DolphinScheduler Controller")
@SaCheckLogin
@RequiredArgsConstructor
public class SchedulerController {
......
......@@ -46,6 +46,7 @@ import org.springframework.web.bind.annotation.RestController;
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.ApiImplicitParams;
......@@ -62,6 +63,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Data Studio Controller")
@RequestMapping("/api/studio")
@SaCheckLogin
@RequiredArgsConstructor
public class StudioController {
......
......@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestBody;
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.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
......@@ -41,6 +42,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Suggestion Controller")
@RequestMapping("/api/suggestion")
@SaCheckLogin
@RequiredArgsConstructor
public class SuggestionController {
......
......@@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
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.hutool.core.lang.Dict;
import cn.hutool.core.map.MapUtil;
......@@ -54,6 +55,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@Api(tags = "System Config Controller")
@SaCheckLogin
@RequestMapping("/api/sysConfig")
@RequiredArgsConstructor
public class SysConfigController {
......
......@@ -44,6 +44,7 @@ import lombok.RequiredArgsConstructor;
@RestController
@Api(tags = "System Controller")
@RequestMapping("/api/system")
@SaCheckLogin
@RequiredArgsConstructor
public class SystemController {
......
......@@ -55,6 +55,7 @@ import org.springframework.web.multipart.MultipartFile;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.lang.tree.Tree;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -66,6 +67,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Task Controller")
@RequestMapping("/api/task")
@SaCheckLogin
@RequiredArgsConstructor
public class TaskController {
......
......@@ -36,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
......@@ -52,6 +53,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Task Version Controller")
@RequestMapping("/api/task/version")
@SaCheckLogin
@RequiredArgsConstructor
public class TaskVersionController {
......
......@@ -43,6 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
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.lang.Dict;
......@@ -57,6 +58,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Tenant Controller")
@RequestMapping("/api/tenant")
@SaCheckLogin
@RequiredArgsConstructor
public class TenantController {
......
......@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RestController;
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.dev33.satoken.stp.StpLogic;
......@@ -56,6 +57,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "Token Controller")
@RestController
@RequestMapping("/api/token")
@SaCheckLogin
@RequiredArgsConstructor
public class TokenController {
......
......@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestBody;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -37,6 +38,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "Tools Controller")
@RequestMapping("/api/tools")
@SaCheckLogin
@RequiredArgsConstructor
public class ToolsController {
@PostMapping("/jsonToFlinkSql")
......
......@@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestBody;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -45,6 +46,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "UDF Controller")
@RestController
@RequestMapping("/api/udf")
@SaCheckLogin
@RequiredArgsConstructor
public class UDFController {
private final UDFService udfService;
......
......@@ -46,6 +46,7 @@ import org.springframework.web.bind.annotation.RestController;
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.collection.CollUtil;
......@@ -62,6 +63,7 @@ import lombok.extern.slf4j.Slf4j;
@Api(tags = "UDF Controller")
@RestController
@RequestMapping("/api/udf/template")
@SaCheckLogin
@RequiredArgsConstructor
public class UDFTemplateController {
......
......@@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.RestController;
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.lang.Dict;
......@@ -64,6 +65,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@Api(tags = "User Controller")
@RequestMapping("/api/user")
@SaCheckLogin
@RequiredArgsConstructor
public class UserController {
......
......@@ -109,7 +109,7 @@ public interface UserService extends ISuperService<User> {
*
* @return {@link Result}{@link UserDTO} obtain the current user's UserDTO
*/
Result<UserDTO> queryCurrentUserInfo();
Result<UserDTO> queryCurrentUserInfo(Integer tenantId);
/**
* user enable or disable
......
......@@ -363,13 +363,18 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
}
@Override
public Result<UserDTO> queryCurrentUserInfo() {
public Result<UserDTO> queryCurrentUserInfo(Integer tenantId) {
UserDTO userInfo = UserInfoContextHolder.get(StpUtil.getLoginIdAsInt());
chooseTenant(tenantId);
if (Asserts.isNotNull(userInfo)) {
UserDTO userInfoDto = buildUserInfo(userInfo.getUser().getId());
if (userInfoDto != null) {
userInfoDto.setCurrentTenant(userInfo.getCurrentTenant());
Tenant currentTenant = userInfo.getCurrentTenant();
if (Asserts.isNull(currentTenant)) {
currentTenant = tenantService.getById(tenantId);
}
userInfoDto.setCurrentTenant(currentTenant);
}
UserInfoContextHolder.refresh(StpUtil.getLoginIdAsInt(), userInfoDto);
return Result.succeed(userInfoDto);
......
......@@ -299,6 +299,8 @@ export default {
'login.result': '{msg}\t\t{time}',
'login.username.placeholder': 'Username',
'login.username.required': 'Please input your username!',
'login.token.error':
'Unable to get token information/session has expired, will jump to the login page, please re-login...',
/**
*
* menu
......
......@@ -287,6 +287,7 @@ export default {
'login.result': '{msg}\t\t{time}',
'login.username.placeholder': '用户名',
'login.username.required': '用户名是必填项!',
'login.token.error': '无法获取token信息/会话已过期,即将跳转到登录页,请重新登录...',
/**
*
* menu
......
......@@ -23,9 +23,11 @@ import {
setKeyToLocalStorage,
setLocalThemeToStorage
} from '@/utils/function';
import { l } from '@/utils/intl';
import { WarningMessageAsync } from '@/utils/messages';
import { history } from '@@/core/history';
/** 此方法会跳转到 redirect 参数所在的位置 */
/** This method will redirect to the location of the redirect parameter */
export const gotoRedirectUrl = () => {
if (!history) return;
setTimeout(() => {
......@@ -34,15 +36,16 @@ export const gotoRedirectUrl = () => {
}, 10);
};
export const redirectToLogin = () => {
//TODO: 弹出确认框
export const redirectToLogin = async () => {
//todo: 使用模态框提示, 但是目前会重复弹出,原因是接口每次都会调用,所以会出现重复弹出
await WarningMessageAsync(l('login.token.error'));
window.location.href = '/#/user/login';
};
export const initSomeThing = () => {
// 初始化设置主题
// initialize setting theme
setLocalThemeToStorage();
// 取出本地存储是否有启用消息提示的 key , 没有的话设置一下
// Retrieve the key for enabling message prompts from the local storage, and if not, set it accordingly
if (hasKeyofLocalStorage(ENABLE_MODEL_TIP)) {
setKeyToLocalStorage(ENABLE_MODEL_TIP, 'false');
}
......
......@@ -137,7 +137,6 @@ const Login: React.FC = () => {
if (result.code === 0) {
// if login success then get token info and set it to local storage
await queryDataByParams<SaTokenInfo>(API_CONSTANTS.TOKEN_INFO).then((res) => {
console.log(res);
if (res) {
setLocalStorageOfToken(JSON.stringify(res));
} else {
......
......@@ -17,7 +17,7 @@
*
*/
import Pop from '@/components/Animation/Pop';
import FadeIn from '@/components/Animation/FadeIn';
import { LogSvg } from '@/components/Icons/CodeLanguageIcon';
import { loginOut } from '@/components/RightContent/AvatarDropdown';
import PasswordForm from '@/pages/AuthCenter/User/components/PasswordModal/PasswordForm';
......@@ -169,7 +169,7 @@ const PersonCenter = () => {
* render
*/
return (
<Pop>
<FadeIn>
<PageContainer title={false}>
<ProCard ghost gutter={[16, 16]} hoverable loading={!loading && currentUser}>
<ProCard
......@@ -208,7 +208,7 @@ const PersonCenter = () => {
/>
</ProCard>
</PageContainer>
</Pop>
</FadeIn>
);
};
......
......@@ -17,16 +17,15 @@
*
*/
import { redirectToLogin } from '@/pages/Other/Login/function';
import { ENABLE_MODEL_TIP } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { getValueFromLocalStorage } from '@/utils/function';
import { l } from '@/utils/intl';
import { ErrorNotification, WarningNotification } from '@/utils/messages';
import { history } from '@@/core/history';
import type { RequestOptions } from '@@/plugin-request/request';
import type { RequestConfig } from '@umijs/max';
// 错误处理方案: 错误类型
// Error handling scheme: Error type
enum ErrorCode {
SUCCESS = 0,
ERROR = 1,
......@@ -35,7 +34,7 @@ enum ErrorCode {
AUTHORIZE_ERROR = 7
}
// 与后端约定的响应数据格式
// Response data format agreed upon with the backend
interface ResponseStructure {
success: boolean;
data?: any;
......@@ -74,61 +73,61 @@ const handleBizError = (result: ResponseStructure) => {
* @doc https://umijs.org/docs/max/request#配置
*/
export const errorConfig: RequestConfig = {
// 错误处理: umi@3 的错误处理方案。
// Error handling: umi@3 Error handling plan for.
errorConfig: {
// 错误抛出
// Error thrown
errorThrower: (res: ResponseStructure) => {
const { success, data, msg, code } = res as ResponseStructure;
if (!success) {
const error: any = new Error(msg);
error.name = 'BizError';
error.info = { msg, code, data };
throw error; // 抛出自制的错误
throw error; // Throwing self-made errors
}
},
// 错误接收及处理
// Error reception and handling
errorHandler: (error: any, opts: any) => {
if (opts?.skipErrorHandler) throw error;
// 我们的 errorThrower 抛出的错误。
//The error thrown by our errorThrower.
if (error.name === 'BizError') {
const errorInfo: ResponseStructure = error.info;
if (errorInfo) {
handleBizError(errorInfo);
}
} else if (error.response) {
// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
//认证错误,跳转登录页面
//The request was successfully sent and the server also responded with a status code, but the status code exceeded the range of 2xx
//Authentication error, redirect to login page
if (error.response.status === 401) {
history.push(API_CONSTANTS.LOGIN_PATH);
redirectToLogin();
} else {
if (getValueFromLocalStorage(ENABLE_MODEL_TIP) == 'true') {
ErrorNotification(error.message, error.code);
}
}
} else if (error.request) {
// 请求已经成功发起,但没有收到响应
//The request has been successfully initiated, but no response has been received
ErrorNotification(error.toString(), l('app.response.noresponse'));
} else {
// 发送请求时出了点问题
// There was a problem sending the request
ErrorNotification(error.toString(), l('app.request.failed'));
}
}
},
// 请求拦截器
// request interceptor
requestInterceptors: [
(config: RequestOptions) => {
// 拦截请求配置,进行个性化处理。
// Intercept request configuration for personalized processing.
const url = config?.url;
return { ...config, url };
}
],
// 响应拦截器
// Response interceptor
responseInterceptors: [
(response) => {
// 拦截响应数据,进行个性化处理
// 不再需要异步处理读取返回体内容,可直接在data中读出,部分字段可在 config 中找到
//Intercept response data for personalized processing
//No longer requires asynchronous processing to read the content of the return body, it can be directly read from data, and some fields can be found in config
const { data = {} as any, config } = response;
return response;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment