Skip to content

Commit

Permalink
[#38] refactor: 쿠키 리퀘스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hsik0225 committed Jun 5, 2020
1 parent 5d72bb7 commit 243969b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,11 @@ public boolean preHandle(HttpServletRequest request,
return false;
}

validateCookies(cookies);
validateCookies(cookies, "jwt");
return true;
}

private void validateCookies(Cookie[] cookies) {
String[] cookieKeys = {"jwt", "userId", "userImage"};

if(Arrays.stream(cookieKeys)
.anyMatch(key -> isIllegalCookie(cookies, key))) {
throw new IllegalArgumentException("쿠키가 없거나 같은 키의 쿠키가 여러개 존재합니다");
}
}

private boolean isIllegalCookie(Cookie[] cookies, String key) {
private boolean validateCookies(Cookie[] cookies, String key) {
return Arrays.stream(cookies)
.filter(c -> c.getName().equals(key))
.count() != 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
Expand Down

0 comments on commit 243969b

Please sign in to comment.