作者 RuoYi

定时任务屏蔽http(s)远程调用

@@ -325,6 +325,29 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils @@ -325,6 +325,29 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
325 } 325 }
326 326
327 /** 327 /**
  328 + * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
  329 + *
  330 + * @param cs 指定字符串
  331 + * @param searchCharSequences 需要检查的字符串数组
  332 + * @return 是否包含任意一个字符串
  333 + */
  334 + public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences)
  335 + {
  336 + if (isEmpty(cs) || isEmpty(searchCharSequences))
  337 + {
  338 + return false;
  339 + }
  340 + for (CharSequence testStr : searchCharSequences)
  341 + {
  342 + if (containsIgnoreCase(cs, testStr))
  343 + {
  344 + return true;
  345 + }
  346 + }
  347 + return false;
  348 + }
  349 +
  350 + /**
328 * 驼峰转下划线命名 351 * 驼峰转下划线命名
329 */ 352 */
330 public static String toUnderScoreCase(String str) 353 public static String toUnderScoreCase(String str)
@@ -79,18 +79,22 @@ public class SysJobController extends BaseController @@ -79,18 +79,22 @@ public class SysJobController extends BaseController
79 @PreAuthorize("@ss.hasPermi('monitor:job:add')") 79 @PreAuthorize("@ss.hasPermi('monitor:job:add')")
80 @Log(title = "定时任务", businessType = BusinessType.INSERT) 80 @Log(title = "定时任务", businessType = BusinessType.INSERT)
81 @PostMapping 81 @PostMapping
82 - public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException 82 + public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
83 { 83 {
84 - if (!CronUtils.isValid(sysJob.getCronExpression())) 84 + if (!CronUtils.isValid(job.getCronExpression()))
85 { 85 {
86 - return AjaxResult.error("新增任务'" + sysJob.getJobName() + "'失败,Cron表达式不正确"); 86 + return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
87 } 87 }
88 - else if (StringUtils.containsIgnoreCase(sysJob.getInvokeTarget(), Constants.LOOKUP_RMI)) 88 + else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
89 { 89 {
90 - return AjaxResult.error("新增任务'" + sysJob.getJobName() + "'失败,目标字符串不允许'rmi://'调用"); 90 + return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
91 } 91 }
92 - sysJob.setCreateBy(SecurityUtils.getUsername());  
93 - return toAjax(jobService.insertJob(sysJob)); 92 + else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
  93 + {
  94 + return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
  95 + }
  96 + job.setCreateBy(SecurityUtils.getUsername());
  97 + return toAjax(jobService.insertJob(job));
94 } 98 }
95 99
96 /** 100 /**
@@ -99,18 +103,22 @@ public class SysJobController extends BaseController @@ -99,18 +103,22 @@ public class SysJobController extends BaseController
99 @PreAuthorize("@ss.hasPermi('monitor:job:edit')") 103 @PreAuthorize("@ss.hasPermi('monitor:job:edit')")
100 @Log(title = "定时任务", businessType = BusinessType.UPDATE) 104 @Log(title = "定时任务", businessType = BusinessType.UPDATE)
101 @PutMapping 105 @PutMapping
102 - public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException 106 + public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException
103 { 107 {
104 - if (!CronUtils.isValid(sysJob.getCronExpression())) 108 + if (!CronUtils.isValid(job.getCronExpression()))
  109 + {
  110 + return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
  111 + }
  112 + else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
105 { 113 {
106 - return AjaxResult.error("修改任务'" + sysJob.getJobName() + "'失败,Cron表达式不正确"); 114 + return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
107 } 115 }
108 - else if (StringUtils.containsIgnoreCase(sysJob.getInvokeTarget(), Constants.LOOKUP_RMI)) 116 + else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
109 { 117 {
110 - return AjaxResult.error("修改任务'" + sysJob.getJobName() + "'失败,目标字符串不允许'rmi://'调用"); 118 + return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
111 } 119 }
112 - sysJob.setUpdateBy(SecurityUtils.getUsername());  
113 - return toAjax(jobService.updateJob(sysJob)); 120 + job.setUpdateBy(SecurityUtils.getUsername());
  121 + return toAjax(jobService.updateJob(job));
114 } 122 }
115 123
116 /** 124 /**