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 @@ -37,8 +37,6 @@ public void createNotice(NoticeCreateRequest request, UserJpaEntity user) {
attachmentService.createAttachment(request.attachments(), noticeEntity);
}

@Cacheable(cacheNames = "notice",
key = "'page=' + #page + ',size=' + #size")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<NoticeResponse> getNotices(int page, int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by("id"));
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/life/mosu/mosuserver/global/filter/Whitelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -51,10 +52,31 @@ public enum Whitelist {
USER_FIND_PASSWORD("/api/v1/user/me/find-password", WhitelistMethod.POST),

APPLICATION_GUEST("/api/v1/applications/guest", WhitelistMethod.ALL);

private static final List<ExceptionRule> AUTH_REQUIRED_EXCEPTIONS = List.of(
new ExceptionRule("/api/v1/exam-application", WhitelistMethod.GET)
);

private final String path;
private final WhitelistMethod method;

public static boolean isAuthException(final HttpServletRequest request) {
String uri = request.getRequestURI();
String method = request.getMethod();
for (ExceptionRule rule : AUTH_REQUIRED_EXCEPTIONS) {
if (matchesPath(uri, rule.path())
&& (rule.method() == WhitelistMethod.ALL
|| rule.method().name().equalsIgnoreCase(method))) {
return true;
}
}
return false;
}

public static boolean isWhitelisted(final HttpServletRequest request) {
if (isAuthException(request)) {
return false;
}
return findMatch(request).isPresent();
}

Expand All @@ -68,4 +90,16 @@ private static Optional<Whitelist> findMatch(final HttpServletRequest request) {
.equalsIgnoreCase(requestMethod))
.findFirst();
}

private static boolean matchesPath(String requestUri, String base) {
if (requestUri == null || base == null) {
return false;
}
String normalizedBase = base.endsWith("/") ? base : base + "/";
return requestUri.equals(base) || requestUri.startsWith(normalizedBase);
}

private record ExceptionRule(String path, WhitelistMethod method) {

}
}