Skip to content

Commit

Permalink
refactor : rate limit whitelist ( next js init 대응 ) (#539)
Browse files Browse the repository at this point in the history
* refactor : RedissonLockAop IllegalMonitorStateException 관련 수정

* feat : acl white list 추가
  • Loading branch information
ImNM authored Mar 8, 2023
1 parent e123c74 commit ebff708
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.bucket4j.Bucket;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
Expand All @@ -26,17 +28,28 @@ public class ThrottlingInterceptor implements HandlerInterceptor {
private final IPRateLimiter ipRateLimiter;
private final ObjectMapper objectMapper;

@Value("${acl.whiteList}")
private List<String> aclWhiteList;

private final SlackThrottleErrorSender slackThrottleErrorSender;

@Override
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler)
throws IOException {
Long userId = SecurityUtils.getCurrentUserId();
String remoteAddr = request.getRemoteAddr();
log.info("remoteAddr : " + remoteAddr);

// next js ssr 대응
if (aclWhiteList.contains(remoteAddr)) {
log.info("white List pass" + remoteAddr);
return true;
}

Bucket bucket;
if (userId == 0L) {
// 익명 유저 ip 기반처리
String remoteAddr = request.getRemoteAddr();
bucket = ipRateLimiter.resolveBucket(remoteAddr);
} else {
// 비 익명 유저 유저 아이디 기반 처리
Expand Down
2 changes: 2 additions & 0 deletions DuDoong-Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ swagger:
throttle:
overdraft: ${RATE_LIMIT_OVERDRAFT:60}
greedyRefill: ${RATE_LIMIT_REFILL:60}

acl.whiteList : ${ACL_WHITELIST:127.0.0.1,127.0.0.2}
---
spring:
config:
Expand Down
1 change: 0 additions & 1 deletion DuDoong-Batch/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ spring:
- common
batch.job.names: ${job.name:NONE}


---
spring:
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public Object lock(final ProceedingJoinPoint joinPoint) throws Throwable {
try {
rLock.unlock();
} catch (IllegalMonitorStateException e) {
rLock.forceUnlock();
log.error(e + baseKey + dynamicKey);
throw e;
}
}
}
Expand Down

0 comments on commit ebff708

Please sign in to comment.