定时任务屏蔽http(s)远程调用
parent
66e0f9a53d
commit
8057dcc4fc
|
@ -17,6 +17,11 @@ public class Constants
|
||||||
*/
|
*/
|
||||||
public static final String GBK = "GBK";
|
public static final String GBK = "GBK";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RMI 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_RMI = "rmi://";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求
|
* http请求
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,8 +13,10 @@ import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
import com.ruoyi.common.core.exception.job.TaskException;
|
import com.ruoyi.common.core.exception.job.TaskException;
|
||||||
import com.ruoyi.common.core.utils.SecurityUtils;
|
import com.ruoyi.common.core.utils.SecurityUtils;
|
||||||
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||||
import com.ruoyi.common.core.web.controller.BaseController;
|
import com.ruoyi.common.core.web.controller.BaseController;
|
||||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||||
|
@ -79,14 +81,22 @@ public class SysJobController extends BaseController
|
||||||
@PreAuthorize(hasPermi = "monitor:job:add")
|
@PreAuthorize(hasPermi = "monitor:job:add")
|
||||||
@Log(title = "定时任务", businessType = BusinessType.INSERT)
|
@Log(title = "定时任务", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
|
public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
|
||||||
{
|
{
|
||||||
if (!CronUtils.isValid(sysJob.getCronExpression()))
|
if (!CronUtils.isValid(job.getCronExpression()))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("cron表达式不正确");
|
return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
||||||
}
|
}
|
||||||
sysJob.setCreateBy(SecurityUtils.getUsername());
|
else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
||||||
return toAjax(jobService.insertJob(sysJob));
|
{
|
||||||
|
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
|
||||||
|
}
|
||||||
|
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
||||||
|
{
|
||||||
|
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
|
||||||
|
}
|
||||||
|
job.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
return toAjax(jobService.insertJob(job));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,14 +105,22 @@ public class SysJobController extends BaseController
|
||||||
@PreAuthorize(hasPermi = "monitor:job:edit")
|
@PreAuthorize(hasPermi = "monitor:job:edit")
|
||||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException
|
public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException
|
||||||
{
|
{
|
||||||
if (!CronUtils.isValid(sysJob.getCronExpression()))
|
if (!CronUtils.isValid(job.getCronExpression()))
|
||||||
{
|
{
|
||||||
return AjaxResult.error("cron表达式不正确");
|
return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
||||||
}
|
}
|
||||||
sysJob.setUpdateBy(SecurityUtils.getUsername());
|
else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
||||||
return toAjax(jobService.updateJob(sysJob));
|
{
|
||||||
|
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用");
|
||||||
|
}
|
||||||
|
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
||||||
|
{
|
||||||
|
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用");
|
||||||
|
}
|
||||||
|
job.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
return toAjax(jobService.updateJob(job));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue