|
|
@@ -1,21 +1,24 @@
|
|
|
package com.xxl.job.admin.controller.biz;
|
|
|
|
|
|
-import com.xxl.job.admin.web.xxlsso.PermissionInterceptor;
|
|
|
-import com.xxl.job.admin.scheduler.exception.XxlJobException;
|
|
|
+import com.xxl.job.admin.constant.Consts;
|
|
|
+import com.xxl.job.admin.mapper.XxlJobGroupMapper;
|
|
|
import com.xxl.job.admin.model.XxlJobGroup;
|
|
|
import com.xxl.job.admin.model.XxlJobInfo;
|
|
|
-import com.xxl.job.admin.model.XxlJobUser;
|
|
|
+import com.xxl.job.admin.scheduler.exception.XxlJobException;
|
|
|
import com.xxl.job.admin.scheduler.route.ExecutorRouteStrategyEnum;
|
|
|
import com.xxl.job.admin.scheduler.scheduler.MisfireStrategyEnum;
|
|
|
import com.xxl.job.admin.scheduler.scheduler.ScheduleTypeEnum;
|
|
|
import com.xxl.job.admin.scheduler.thread.JobScheduleHelper;
|
|
|
-import com.xxl.job.admin.util.I18nUtil;
|
|
|
-import com.xxl.job.admin.mapper.XxlJobGroupMapper;
|
|
|
import com.xxl.job.admin.service.XxlJobService;
|
|
|
+import com.xxl.job.admin.util.I18nUtil;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
|
|
import com.xxl.job.core.glue.GlueTypeEnum;
|
|
|
import com.xxl.job.core.util.DateUtil;
|
|
|
+import com.xxl.sso.core.helper.XxlSsoHelper;
|
|
|
+import com.xxl.sso.core.model.LoginInfo;
|
|
|
+import com.xxl.tool.core.StringTool;
|
|
|
+import com.xxl.tool.response.Response;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -26,7 +29,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* index controller
|
|
|
@@ -53,11 +59,11 @@ public class JobInfoController {
|
|
|
model.addAttribute("MisfireStrategyEnum", MisfireStrategyEnum.values()); // 调度过期策略
|
|
|
|
|
|
// 执行器列表
|
|
|
- List<XxlJobGroup> jobGroupList_all = xxlJobGroupMapper.findAll();
|
|
|
+ List<XxlJobGroup> jobGroupListTotal = xxlJobGroupMapper.findAll();
|
|
|
|
|
|
// filter group
|
|
|
- List<XxlJobGroup> jobGroupList = PermissionInterceptor.filterJobGroupByRole(request, jobGroupList_all);
|
|
|
- if (jobGroupList==null || jobGroupList.size()==0) {
|
|
|
+ List<XxlJobGroup> jobGroupList = filterJobGroupByPermission(request, jobGroupListTotal);
|
|
|
+ if (jobGroupList==null || jobGroupList.isEmpty()) {
|
|
|
throw new XxlJobException(I18nUtil.getString("jobgroup_empty"));
|
|
|
}
|
|
|
|
|
|
@@ -84,22 +90,20 @@ public class JobInfoController {
|
|
|
@ResponseBody
|
|
|
public ReturnT<String> add(HttpServletRequest request, XxlJobInfo jobInfo) {
|
|
|
// valid permission
|
|
|
- PermissionInterceptor.validJobGroupPermission(request, jobInfo.getJobGroup());
|
|
|
+ LoginInfo loginInfo = validJobGroupPermission(request, jobInfo.getJobGroup());
|
|
|
|
|
|
// opt
|
|
|
- XxlJobUser loginUser = PermissionInterceptor.getLoginUser(request);
|
|
|
- return xxlJobService.add(jobInfo, loginUser);
|
|
|
+ return xxlJobService.add(jobInfo, loginInfo);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@RequestMapping("/update")
|
|
|
@ResponseBody
|
|
|
public ReturnT<String> update(HttpServletRequest request, XxlJobInfo jobInfo) {
|
|
|
// valid permission
|
|
|
- PermissionInterceptor.validJobGroupPermission(request, jobInfo.getJobGroup());
|
|
|
+ LoginInfo loginInfo = validJobGroupPermission(request, jobInfo.getJobGroup());
|
|
|
|
|
|
// opt
|
|
|
- XxlJobUser loginUser = PermissionInterceptor.getLoginUser(request);
|
|
|
- return xxlJobService.update(jobInfo, loginUser);
|
|
|
+ return xxlJobService.update(jobInfo, loginInfo);
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/remove")
|
|
|
@@ -128,9 +132,10 @@ public class JobInfoController {
|
|
|
@RequestParam("addressList") String addressList) {
|
|
|
|
|
|
// login user
|
|
|
- XxlJobUser loginUser = PermissionInterceptor.getLoginUser(request);
|
|
|
+ Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
|
|
|
+
|
|
|
// trigger
|
|
|
- return xxlJobService.trigger(loginUser, id, executorParam, addressList);
|
|
|
+ return xxlJobService.trigger(loginInfoResponse.getData(), id, executorParam, addressList);
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/nextTriggerTime")
|
|
|
@@ -160,5 +165,51 @@ public class JobInfoController {
|
|
|
return ReturnT.ofSuccess(result);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // -------------------- tool --------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * check if has jobgroup permission
|
|
|
+ */
|
|
|
+ public static boolean hasJobGroupPermission(LoginInfo loginInfo, int jobGroup){
|
|
|
+ if (XxlSsoHelper.hasRole(loginInfo, Consts.ADMIN_ROLE).isSuccess()) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ List<String> jobGroups = (loginInfo.getExtraInfo()!=null && loginInfo.getExtraInfo().containsKey("jobGroups"))
|
|
|
+ ? List.of(StringTool.tokenizeToArray(loginInfo.getExtraInfo().get("jobGroups"), ",")) :new ArrayList<>();
|
|
|
+ return jobGroups.contains(String.valueOf(jobGroup));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * valid jobGroup permission
|
|
|
+ */
|
|
|
+ public static LoginInfo validJobGroupPermission(HttpServletRequest request, int jobGroup) {
|
|
|
+ Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
|
|
|
+ if (!(loginInfoResponse.isSuccess() && hasJobGroupPermission(loginInfoResponse.getData(), jobGroup))) {
|
|
|
+ throw new RuntimeException(I18nUtil.getString("system_permission_limit") + "[username="+ loginInfoResponse.getData().getUserName() +"]");
|
|
|
+ }
|
|
|
+ return loginInfoResponse.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * filter jobGroupList by permission
|
|
|
+ */
|
|
|
+ public static List<XxlJobGroup> filterJobGroupByPermission(HttpServletRequest request, List<XxlJobGroup> jobGroupListTotal){
|
|
|
+ Response<LoginInfo> loginInfoResponse = XxlSsoHelper.loginCheckWithAttr(request);
|
|
|
+
|
|
|
+ if (XxlSsoHelper.hasRole(loginInfoResponse.getData(), Consts.ADMIN_ROLE).isSuccess()) {
|
|
|
+ return jobGroupListTotal;
|
|
|
+ } else {
|
|
|
+ List<String> jobGroups = (loginInfoResponse.getData().getExtraInfo()!=null && loginInfoResponse.getData().getExtraInfo().containsKey("jobGroups"))
|
|
|
+ ? List.of(StringTool.tokenizeToArray(loginInfoResponse.getData().getExtraInfo().get("jobGroups"), ",")) :new ArrayList<>();
|
|
|
+
|
|
|
+ return jobGroupListTotal
|
|
|
+ .stream()
|
|
|
+ .filter(jobGroup -> jobGroups.contains(String.valueOf(jobGroup.getId())))
|
|
|
+ .toList();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|