| | |
| | | |
| | | 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())) { |
| | |
| | | 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); |
| | |
| | | response.setContentType("application/json; charset=utf-8"); |
| | | |
| | | FebsResponse code = new FebsResponse().code(HttpStatus.UNAUTHORIZED); |
| | | String encryptBase64 = SecureUtil.rsa(AppContants.RESP_PRIVATE_KEY, AppContants.RESP_PUBLIC_KEY).encryptBase64(JSONObject.toJSONString(code).getBytes(), KeyType.PublicKey); |
| | | response.getWriter().write(new ObjectMapper().writeValueAsString(encryptBase64)); |
| | | // String encryptBase64 = SecureUtil.rsa(AppContants.RESP_PRIVATE_KEY, AppContants.RESP_PUBLIC_KEY).encryptBase64(JSONObject.toJSONString(code).getBytes(), KeyType.PublicKey); |
| | | response.getWriter().write(new ObjectMapper().writeValueAsString(code)); |
| | | } |
| | | |
| | | public static void main(String[] args) { |