| | |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.properties.SystemProperties; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.SpringContextUtil; |
| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import org.web3j.crypto.Hash; |
| | |
| | | private final DappMemberDao dappMemberDao = SpringContextUtil.getBean(DappMemberDao.class); |
| | | private final RedisUtils redisUtils = SpringContextUtil.getBean(RedisUtils.class); |
| | | |
| | | private SystemProperties systemProperties = SpringContextUtil.getBean(SystemProperties.class); |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | if ("OPTIONS".equals(request.getMethod().toUpperCase())) { |
| | |
| | | String headAddress = request.getHeader("address"); |
| | | String key = request.getHeader("key"); |
| | | String path = request.getServletPath().replace("/dapi", ""); |
| | | log.info("进入拦截:{}, {}, {}", headAddress, path, key); |
| | | |
| | | String chain = request.getHeader("chain"); |
| | | if (StrUtil.isBlank(headAddress) || StrUtil.isBlank(key)) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | Map<Object, Object> signKey = redisUtils.hmget(AppContants.REDIS_KEY_SIGN); |
| | | Object signObj = signKey.get(headAddress); |
| | | if (!systemProperties.isDebug()) { |
| | | Map<Object, Object> signKey = redisUtils.hmget(AppContants.REDIS_KEY_SIGN); |
| | | Object signObj = signKey.get(headAddress); |
| | | |
| | | if (signObj == null) { |
| | | responseUnAuth(response); |
| | | return false; |
| | | } |
| | | String sign = (String) signObj; |
| | | if (signObj == null) { |
| | | responseUnAuth(response); |
| | | return false; |
| | | } |
| | | String sign = (String) signObj; |
| | | |
| | | String calKey = LoginUserUtil.sha3(sign + path + headAddress).replace("0x", ""); |
| | | if (!calKey.equals(key)) { |
| | | responseUnAuth(response); |
| | | return false; |
| | | String calKey = LoginUserUtil.sha3(sign + path + headAddress).replace("0x", ""); |
| | | if (!calKey.equals(key)) { |
| | | responseUnAuth(response); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | DappMemberEntity memberEntity = dappMemberDao.selectByAddress(headAddress, null); |