Skip to content

Commit

Permalink
refactor: (#284) guest에 대한 요청을 판단하는 filter에 http method에 대한 검증 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jeomxon committed Aug 8, 2023
1 parent 265963c commit f9f9cf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ResponseEntity<PostDetailResponse> getPost(
return ResponseEntity.ok(response);
}

@Operation(summary = "게시글 상세 조회(비회원)", description = "비회원이 한 게시글의 상세를 조회한다.")
@Operation(summary = "게시글 상세 조회(비회원)", description = "비회원으로 게시글을 상세조회 한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "게시글 조회 성공"),
@ApiResponse(responseCode = "404", description = "존재하지 않는 게시글")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

Expand Down Expand Up @@ -57,7 +59,7 @@ protected void doFilterInternal(
@Override
protected boolean shouldNotFilter(final HttpServletRequest request) {
return containsAllowedUris(request) || startsWithAllowedStartUris(request)
|| endsWithAllowedEndUris(request) || matchesUriPattern(request);
|| matchesGuestRequest(request) || matchesUriPattern(request);
}

private boolean containsAllowedUris(final HttpServletRequest request) {
Expand All @@ -70,8 +72,10 @@ private boolean startsWithAllowedStartUris(final HttpServletRequest request) {
.anyMatch(url -> request.getRequestURI().startsWith(url));
}

private boolean endsWithAllowedEndUris(final HttpServletRequest request) {
return ALLOWED_END_URIS.stream().anyMatch(url -> request.getRequestURI().endsWith(url));
private boolean matchesGuestRequest(final HttpServletRequest request) {
return ALLOWED_END_URIS.stream()
.anyMatch(url -> request.getRequestURI().endsWith(url) &&
Objects.equals(request.getMethod(), HttpMethod.GET.name()));
}

private boolean matchesUriPattern(final HttpServletRequest request) {
Expand Down

0 comments on commit f9f9cf7

Please sign in to comment.