mirror of https://gitee.com/maxjhandsome/pig
包名错误修复,验证码过滤器逻辑修改
This commit is contained in:
parent
5a8c62c843
commit
c6f4770d9a
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.config;
|
||||
package com.github.pig.gateway.component.config;
|
||||
|
||||
import com.github.pig.common.constant.ServiceNameConstant;
|
||||
import org.apache.commons.lang.StringUtils;
|
|
@ -1,8 +1,8 @@
|
|||
package com.github.pig.gateway.componet.config;
|
||||
package com.github.pig.gateway.component.config;
|
||||
|
||||
import com.github.pig.common.bean.config.FilterUrlsPropertiesConfig;
|
||||
import com.github.pig.gateway.componet.filter.ValidateCodeFilter;
|
||||
import com.github.pig.gateway.componet.handler.PigAccessDeniedHandler;
|
||||
import com.github.pig.gateway.component.filter.ValidateCodeFilter;
|
||||
import com.github.pig.gateway.component.handler.PigAccessDeniedHandler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.fallback;
|
||||
package com.github.pig.gateway.component.fallback;
|
||||
|
||||
import com.github.pig.common.constant.ServiceNameConstant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.fallback;
|
||||
package com.github.pig.gateway.component.fallback;
|
||||
|
||||
import com.github.pig.common.constant.ServiceNameConstant;
|
||||
import lombok.extern.slf4j.Slf4j;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.filter;
|
||||
package com.github.pig.gateway.component.filter;
|
||||
|
||||
import com.github.pig.common.constant.SecurityConstants;
|
||||
import com.netflix.zuul.ZuulFilter;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.filter;
|
||||
package com.github.pig.gateway.component.filter;
|
||||
|
||||
import com.github.pig.gateway.service.LogSendService;
|
||||
import com.netflix.zuul.ZuulFilter;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.filter;
|
||||
package com.github.pig.gateway.component.filter;
|
||||
|
||||
import com.github.pig.gateway.service.LogSendService;
|
||||
import com.netflix.zuul.ZuulFilter;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.filter;
|
||||
package com.github.pig.gateway.component.filter;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pig.common.constant.CommonConstant;
|
||||
|
@ -31,6 +31,9 @@ import java.io.PrintWriter;
|
|||
@Component("validateCodeFilter")
|
||||
public class ValidateCodeFilter extends OncePerRequestFilter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ValidateCodeFilter.class);
|
||||
|
||||
private static final String EXPIRED_CAPTCHA_ERROR = "验证码已过期,请重新获取验证码";
|
||||
|
||||
@Value("${security.validate.code:true}")
|
||||
private boolean isValidate;
|
||||
@Autowired
|
||||
|
@ -64,35 +67,38 @@ public class ValidateCodeFilter extends OncePerRequestFilter {
|
|||
|
||||
private void checkCode(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
String code = httpServletRequest.getParameter("code");
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new ValidateCodeException("请输入验证码");
|
||||
}
|
||||
|
||||
String randomStr = httpServletRequest.getParameter("randomStr");
|
||||
if (StringUtils.isBlank(randomStr)) {
|
||||
randomStr = httpServletRequest.getParameter("mobile");
|
||||
}
|
||||
Object codeObj = redisTemplate.opsForValue().get(SecurityConstants.DEFAULT_CODE_KEY + randomStr);
|
||||
|
||||
String key = SecurityConstants.DEFAULT_CODE_KEY + randomStr;
|
||||
if (!redisTemplate.hasKey(key)) {
|
||||
throw new ValidateCodeException(EXPIRED_CAPTCHA_ERROR);
|
||||
}
|
||||
|
||||
Object codeObj = redisTemplate.opsForValue().get(key);
|
||||
|
||||
if (codeObj == null) {
|
||||
throw new ValidateCodeException("验证码为空或已过期");
|
||||
throw new ValidateCodeException(EXPIRED_CAPTCHA_ERROR);
|
||||
}
|
||||
|
||||
String saveCode = codeObj.toString();
|
||||
|
||||
if (StringUtils.isBlank(code)) {
|
||||
redisTemplate.delete(SecurityConstants.DEFAULT_CODE_KEY + randomStr);
|
||||
throw new ValidateCodeException("验证码的值不能为空");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(saveCode)) {
|
||||
redisTemplate.delete(SecurityConstants.DEFAULT_CODE_KEY + randomStr);
|
||||
throw new ValidateCodeException("验证码已过期或已过期");
|
||||
if (StringUtils.isBlank(saveCode)) {
|
||||
redisTemplate.delete(key);
|
||||
throw new ValidateCodeException(EXPIRED_CAPTCHA_ERROR);
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(saveCode, code)) {
|
||||
redisTemplate.delete(SecurityConstants.DEFAULT_CODE_KEY + randomStr);
|
||||
throw new ValidateCodeException("验证码不匹配");
|
||||
redisTemplate.delete(key);
|
||||
throw new ValidateCodeException("验证码错误,请重新输入");
|
||||
}
|
||||
|
||||
if (StringUtils.equals(code, saveCode)) {
|
||||
redisTemplate.delete(SecurityConstants.DEFAULT_CODE_KEY + randomStr);
|
||||
filterChain.doFilter(httpServletRequest, httpServletResponse);
|
||||
}
|
||||
redisTemplate.delete(key);
|
||||
filterChain.doFilter(httpServletRequest, httpServletResponse);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,11 @@
|
|||
package com.github.pig.gateway.componet.handler;
|
||||
package com.github.pig.gateway.component.handler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pig.common.constant.CommonConstant;
|
||||
import com.github.pig.common.util.R;
|
||||
import com.github.pig.common.util.exception.PigDeniedException;
|
||||
import com.xiaoleilu.hutool.http.HttpUtil;
|
||||
import com.xiaoleilu.hutool.util.URLUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
|
|
@ -1,4 +1,4 @@
|
|||
package com.github.pig.gateway.componet.handler;
|
||||
package com.github.pig.gateway.component.handler;
|
||||
|
||||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.DefaultRateLimiterErrorHandler;
|
||||
import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.RateLimiterErrorHandler;
|
Loading…
Reference in New Issue