mirror of https://gitee.com/y_project/RuoYi.git
Merge branch 'feature/xxzy-schedule_whiteList' into hotfix/fix-scheduleUtils_NPE
* feature/xxzy-schedule_whiteList: feat: 定时任务添加扩展的白名单配置(降低对若依框架代码的修改)pull/451/head
commit
6cda0a3425
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -37,6 +38,9 @@ import com.ruoyi.quartz.util.ScheduleUtils;
|
|||
public class SysJobController extends BaseController
|
||||
{
|
||||
private String prefix = "monitor/job";
|
||||
|
||||
@Value("${job.whiteList:}")
|
||||
private List<String> whiteList;
|
||||
|
||||
@Autowired
|
||||
private ISysJobService jobService;
|
||||
|
@ -153,7 +157,7 @@ public class SysJobController extends BaseController
|
|||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
||||
}
|
||||
else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
||||
else if (!ScheduleUtils.whiteList(job.getInvokeTarget(), whiteList.toArray(new String[whiteList.size()])))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
||||
}
|
||||
|
@ -201,7 +205,7 @@ public class SysJobController extends BaseController
|
|||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
||||
}
|
||||
else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
||||
else if (!ScheduleUtils.whiteList(job.getInvokeTarget(), whiteList.toArray(new String[whiteList.size()])))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.quartz.util;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.quartz.CronScheduleBuilder;
|
||||
import org.quartz.CronTrigger;
|
||||
import org.quartz.Job;
|
||||
|
@ -123,19 +124,22 @@ public class ScheduleUtils
|
|||
* 检查包名是否为白名单配置
|
||||
*
|
||||
* @param invokeTarget 目标字符串
|
||||
* @param extendedWhiteList 扩展的名单单
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean whiteList(String invokeTarget)
|
||||
{
|
||||
public static boolean whiteList(String invokeTarget, String... extendedWhiteList)
|
||||
{
|
||||
String[] whiteList = StringUtils.isEmpty(extendedWhiteList) ? Constants.JOB_WHITELIST_STR
|
||||
: ArrayUtils.addAll(extendedWhiteList, Constants.JOB_WHITELIST_STR);
|
||||
String packageName = StringUtils.substringBefore(invokeTarget, "(");
|
||||
int count = StringUtils.countMatches(packageName, ".");
|
||||
if (count > 1)
|
||||
{
|
||||
return StringUtils.containsAnyIgnoreCase(invokeTarget, Constants.JOB_WHITELIST_STR);
|
||||
return StringUtils.containsAnyIgnoreCase(invokeTarget, whiteList);
|
||||
}
|
||||
Object obj = SpringUtils.getBean(StringUtils.split(invokeTarget, ".")[0]);
|
||||
String beanPackageName = obj.getClass().getPackage().getName();
|
||||
return StringUtils.containsAnyIgnoreCase(beanPackageName, Constants.JOB_WHITELIST_STR)
|
||||
return StringUtils.containsAnyIgnoreCase(beanPackageName, whiteList)
|
||||
&& !StringUtils.containsAnyIgnoreCase(beanPackageName, Constants.JOB_ERROR_STR);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue