ip频繁访问限制

This commit is contained in:
mythxb 2023-11-22 17:17:29 +08:00
parent a0bda3d08e
commit 744fb80719
2 changed files with 13 additions and 2 deletions

View File

@ -63,10 +63,10 @@ public class LogAspect {
//限制时长 //限制时长
private static final Long REJECT_TIME = 10 * 60 * 1000L; private static final Long REJECT_TIME = 10 * 60 * 1000L;
//redis公共方法
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
private ApplicationContext context;
/** /**
* 拦截位置 * 拦截位置

View File

@ -10,6 +10,7 @@ import com.common.utils.model.*;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.rzyc.advice.LoginAuth; import com.rzyc.advice.LoginAuth;
import com.rzyc.advice.exception.AccessException;
import com.rzyc.bean.PageDto; import com.rzyc.bean.PageDto;
import com.rzyc.bean.UserDepart; import com.rzyc.bean.UserDepart;
import com.rzyc.bean.check.CheckList; import com.rzyc.bean.check.CheckList;
@ -26,6 +27,7 @@ import com.rzyc.bean.user.task.TaskDetailDto;
import com.rzyc.bean.user.task.TaskPageDto; import com.rzyc.bean.user.task.TaskPageDto;
import com.rzyc.bean.user.dto.*; import com.rzyc.bean.user.dto.*;
import com.rzyc.config.MethodAnnotation; import com.rzyc.config.MethodAnnotation;
import com.rzyc.config.RedisUtil;
import com.rzyc.enums.*; import com.rzyc.enums.*;
import com.rzyc.model.*; import com.rzyc.model.*;
import com.rzyc.model.ent.SysEnterprise; import com.rzyc.model.ent.SysEnterprise;
@ -33,11 +35,13 @@ import com.rzyc.model.log.SysLogs;
import com.rzyc.model.oth.OtheWareHouse; import com.rzyc.model.oth.OtheWareHouse;
import com.rzyc.model.personal.SysResource; import com.rzyc.model.personal.SysResource;
import com.rzyc.model.user.*; import com.rzyc.model.user.*;
import com.rzyc.utils.IpUtil;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.apache.catalina.User; import org.apache.catalina.User;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter; import org.apache.commons.beanutils.converters.DateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -48,6 +52,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* PC个人中心 * PC个人中心
@ -71,17 +76,22 @@ public class PcPersonalController extends com.rzyc.controller.BaseController {
/*@PreAuthorize("hasAnyAuthority('pclogin','pclogin:update')") /*@PreAuthorize("hasAnyAuthority('pclogin','pclogin:update')")
@MethodAnnotation(authorizations = {"pclogin","pclogin:update"},name = "PC政府用户登录")*/ @MethodAnnotation(authorizations = {"pclogin","pclogin:update"},name = "PC政府用户登录")*/
@ResponseBody @ResponseBody
public SingleResult<SysUser> pclogin(@Valid LoginDto loginDto)throws Exception{ public SingleResult<SysUser> pclogin(@Valid LoginDto loginDto,HttpServletRequest request)throws Exception{
SingleResult<SysUser> result = new SingleResult<>(); SingleResult<SysUser> result = new SingleResult<>();
System.out.println("loginDto -> "+JSONArray.toJSONString(loginDto)); System.out.println("loginDto -> "+JSONArray.toJSONString(loginDto));
String sysusername = loginDto.getSysusername(); String sysusername = loginDto.getSysusername();
String syspassword = loginDto.getSyspassword(); String syspassword = loginDto.getSyspassword();
String ip = IpUtil.getIpAddr(request);
ip = ip+sysusername;
//获取验证码 //获取验证码
String generateCode = request.getSession().getAttribute(constantsConfigure.getGenerateCodeKey())+""; String generateCode = request.getSession().getAttribute(constantsConfigure.getGenerateCodeKey())+"";
//验证码只能使用一次 //验证码只能使用一次
request.getSession().removeAttribute(constantsConfigure.getGenerateCodeKey()); request.getSession().removeAttribute(constantsConfigure.getGenerateCodeKey());
if(loginDto.getGenerateCode().equals(generateCode)){ if(loginDto.getGenerateCode().equals(generateCode)){
SysUser sysUser = sysUserMapper.findBySysUserName(sysusername); SysUser sysUser = sysUserMapper.findBySysUserName(sysusername);
@ -124,6 +134,7 @@ public class PcPersonalController extends com.rzyc.controller.BaseController {
return result; return result;
} }
/** /**
* @Description: PC管理员登录 * @Description: PC管理员登录
* @Author ZQW * @Author ZQW