|
@ -1,6 +1,7 @@ |
|
|
package com.epmet.openapi.scan.interceptor; |
|
|
package com.epmet.openapi.scan.interceptor; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.utils.IpUtils; |
|
|
import com.epmet.commons.tools.utils.IpUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
@ -32,7 +33,9 @@ public class ScanApiAuthInterceptor implements HandlerInterceptor { |
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|
|
String ip = IpUtils.getIpAddr(request); |
|
|
String ip = IpUtils.getIpAddr(request); |
|
|
SetOperations setOperations = redisTemplate.opsForSet(); |
|
|
SetOperations setOperations = redisTemplate.opsForSet(); |
|
|
if (!setOperations.isMember(RedisKeys.getWhiteList(), ip)) { |
|
|
if (setOperations.isMember(RedisKeys.getWhiteList(), StrConstant.STAR)){ |
|
|
|
|
|
return true; |
|
|
|
|
|
}else if (!setOperations.isMember(RedisKeys.getWhiteList(), ip)) { |
|
|
log.error("preHandle ip:{} 不在白名单内", ip); |
|
|
log.error("preHandle ip:{} 不在白名单内", ip); |
|
|
String result = JSON.toJSONString(new Result<>().error(EpmetErrorCode.ERR401.getCode(), EpmetErrorCode.ERR401.getMsg())); |
|
|
String result = JSON.toJSONString(new Result<>().error(EpmetErrorCode.ERR401.getCode(), EpmetErrorCode.ERR401.getMsg())); |
|
|
responseJson(response, result); |
|
|
responseJson(response, result); |
|
|