Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServle
if (redisService.isAdminLoginAllowed("LOGIN_ADMIN", username)) {
int count = redisService.getRequestCount("LOGIN_ADMIN", username);
sendErrorResponse(response, HttpStatus.UNAUTHORIZED,
"아이디 또는 비밀번호를 확인해주세요(%s/10)".formatted(String.valueOf(10 - count)));
"아이디 또는 비밀번호를 확인해주세요. (%s/10)".formatted(String.valueOf(count)));
return;
}
int count = redisService.getRequestCount("LOGIN_ADMIN", username);
if (count >= 10) {
eventPublisher.publishEvent(new AdminBanEvent(username, ClientUtils.getRemoteIP(request)));
}
sendErrorResponse(response, HttpStatus.UNAUTHORIZED, "해당 아이디 로그인 시도가 10번 불일치하여" +
sendErrorResponse(response, HttpStatus.UNAUTHORIZED, "해당 아이디 로그인 시도가 10번 불일치하여\n" +
"계정이 잠금되었습니다.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class RedisService { // TODO: RedisReportService 로 변경.

private final RedisTemplate<String, String> redisTemplate;

private static final String ADMIN_ALARM_KEY="ADMIN_ALARM";
private static final int ADMIN_LOGIN_MAX_REQUESTS=10;
private static final int MAX_REQUESTS = 3; // 제한 횟수 (기본값: 5분 동안 3회)
private static final long EXPIRED_TIME = 5L; // 만료 시간 (5분)
Expand Down Expand Up @@ -63,8 +63,8 @@ public boolean isAdminLoginAllowed(String category,String identifier){
String redisKey = getRateLimitKey(category, identifier);
String requestCountStr = redisTemplate.opsForValue().get(redisKey);
int requestCount = requestCountStr == null ? 0 : Integer.parseInt(requestCountStr);

if (requestCount >= ADMIN_LOGIN_MAX_REQUESTS) {
requestCount+=1;
if (0>=(ADMIN_LOGIN_MAX_REQUESTS-requestCount)) {
log.warn("🚫 [RateLimit] 관리자 요청 차단 - Key: {}, 요청 횟수: {}", redisKey, requestCount);
return false;
}
Expand All @@ -75,7 +75,6 @@ public boolean isAdminLoginAllowed(String category,String identifier){
return true;

}

public boolean AdminReadCheck(String category, String adminIdentifier, StaticDataType staticDataType, Long contentId){

String redisKey=getRateLimitKey(category,adminIdentifier+staticDataType.name()+String.valueOf(contentId));
Expand All @@ -96,8 +95,24 @@ public void adminReadCheckUpdate(String category, String adminIdentifier, Static
redisTemplate.expire(redisKey, Duration.ofMinutes(ADMIN_ALARM_READ_EXPIRE_TIME));
}
}


/*public boolean AdminReadCheck(String adminIdentifier, StaticDataType staticDataType, Long contentId){
String redisKey=ADMIN_ALARM_KEY+adminIdentifier+staticDataType.name()+String.valueOf(contentId);
String requestCountStr=redisTemplate.opsForValue().get(redisKey);
int requestCount = requestCountStr == null ? 0 : Integer.parseInt(requestCountStr);
if(requestCount==0){
return false;
}
return true;
}
public void adminReadCheckUpdate(String adminIdentifier, StaticDataType staticDataType, Long contentId){
String redisKey=ADMIN_ALARM_KEY+adminIdentifier+staticDataType.name()+String.valueOf(contentId);
String requestCountStr=redisTemplate.opsForValue().get(redisKey);
int requestCount = requestCountStr == null ? 0 : Integer.parseInt(requestCountStr);
if(requestCount==0) {
redisTemplate.opsForValue().increment(redisKey);
redisTemplate.expire(redisKey, Duration.ofDays(30L));
}
}*/
/**
* 요청 제한을 적용할 Redis Key 생성
*
Expand Down
Loading