-
Notifications
You must be signed in to change notification settings - Fork 0
[Step4] 데이터 전송 방식을 일부 변경한다. #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
2abbfa0
afb76b7
98e6bc9
fecc578
18841b9
3afbe3a
fb5b15b
be7ed0a
c0c7c64
2956fb8
023b4b5
424e277
fcef502
49547fa
4350b67
045c610
53aa75f
947a8c7
eb19568
9959627
8b65cdb
fec3b99
4313365
c38b3d4
a00907a
1fccab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,5 +92,5 @@ task downloadYml { | |
} | ||
|
||
tasks.named("downloadYml") { | ||
dependsOn downloadYml | ||
dependsOn compileJava | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package project.server.app.common.configuration; | ||
|
||
import project.server.app.common.configuration.interceptor.SessionCheckHandlerInterceptor; | ||
import project.server.app.core.web.user.application.UserLoginUseCase; | ||
import project.server.app.core.web.user.presentation.validator.UserValidator; | ||
import project.server.mvc.springframework.annotation.Component; | ||
import static project.server.mvc.springframework.context.ApplicationContext.getBean; | ||
import static project.server.mvc.springframework.context.ApplicationContext.register; | ||
import project.server.mvc.springframework.web.InterceptorRegistry; | ||
import project.server.mvc.springframework.web.WebMvcConfigurer; | ||
|
||
@Component | ||
public class WebConfiguration implements WebMvcConfigurer { | ||
|
||
private final UserValidator validator; | ||
private final UserLoginUseCase loginUseCase; | ||
|
||
public WebConfiguration( | ||
UserValidator validator, | ||
UserLoginUseCase loginUseCase | ||
) { | ||
this.validator = validator; | ||
this.loginUseCase = loginUseCase; | ||
register(new InterceptorRegistry()); | ||
addInterceptors(getBean(InterceptorRegistry.class)); | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인터셉터를 직접 구현하셨군요! 인터셉터를 구현하신 이유가 있나요? 인터셉터의 역할은 무엇인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 각 컨트롤러에서 권한 체크를 하니, 로직의 중복이 발생했는데요, 이를 제거하기 위해 인터셉터를 만들었습니다. 즉, 권한 체크가 인터셉터의 역할입니다. |
||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(new SessionCheckHandlerInterceptor(validator, loginUseCase)) | ||
.addPathPatterns("/my-info.html", "/my-info", "/api/users"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package project.server.app.common.configuration.interceptor; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import project.server.app.common.login.LoginUser; | ||
import project.server.app.common.login.Session; | ||
import static project.server.app.common.utils.HeaderUtils.getSessionId; | ||
import project.server.app.core.web.user.application.UserLoginUseCase; | ||
import project.server.app.core.web.user.presentation.validator.UserValidator; | ||
import project.server.mvc.servlet.HttpServletRequest; | ||
import project.server.mvc.servlet.HttpServletResponse; | ||
import project.server.mvc.springframework.handler.HandlerInterceptor; | ||
import project.server.mvc.springframework.web.servlet.ModelAndView; | ||
|
||
@Slf4j | ||
public class SessionCheckHandlerInterceptor implements HandlerInterceptor { | ||
|
||
private final UserValidator validator; | ||
private final UserLoginUseCase loginUseCase; | ||
|
||
public SessionCheckHandlerInterceptor( | ||
UserValidator validator, | ||
UserLoginUseCase loginUseCase | ||
) { | ||
this.validator = validator; | ||
this.loginUseCase = loginUseCase; | ||
} | ||
|
||
@Override | ||
public boolean preHandle( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
Object handler | ||
) { | ||
Long sessionId = getSessionId(request.getCookies()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getSessionId를 HeaderUtils에 선언하셨던데 HeaderUtils에 선언하기로 결정한 이유에 대해서 들을 수 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header에서 여러 유형의 값들을 파싱할 수 있다고 판단해서 별도의 파싱 클래스를 생성했습니다. Session 이외에도 여러 값들을 파싱할 수 있기 때문입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그럼 그건 HttpHeaders가 가질 수 있는 책임 아니였을까요?? HttpHeaders 클래스에 존재하는
위 메서드는 headers중에 contentLength를 찾아서 반환하는데 이것이 session과 관련된 메서드를 찾아서 가져오는 것과 어떤 차이가 있나요? 비슷한 성질의 역할을 하는 메서드인데 contentLength를 찾아오는 메서드는 HttpHeaders에 존재하고 sessionId를 찾아오는 메서드는 HeadersUtils에 존재하는 것이 납득되지 않습니다. 또한 common 패키지 밑에 HeadersUtils가 들어가는 것도 이해가 잘 안됩니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sessionId로 UUID가 아니라 Long을 사용하신 이유가 궁금합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 userId 같은데 제 실수 같네요. 수정하겠습니다! |
||
validator.validateSessionId(sessionId, response); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맞습니다. 위에 변수명 실수 같아요. |
||
|
||
Session findSession = loginUseCase.findSessionById(sessionId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. findSession에서 find의 수동태는 found라 foundSession이 맞지않나요? 저는 그냥 session이라 선언해도 의미 전달에 전혀 문제가 없다 느껴져요. 굳이 변수명이 길어지는 것 보다는 session으로 두는 것이 더 낫다고 생각하는데 어떻게 생각하시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그것도 괜찮죠. 다만 찾아온 값들의 접두사로 find{$NAME} 형태로 사용하다보니 전체를 이렇게 통일했습니다. |
||
log.info("Session:{}", findSession); | ||
validator.validateSession(findSession, response); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 쿠키 만료 시간을 0으로 해야 브라우저에 저장된 값을 삭제할 수 있기 때문입니다. |
||
|
||
LoginUser loginUser = new LoginUser(findSession); | ||
request.setAttribute("loginUser", loginUser); | ||
return false; | ||
} | ||
|
||
@Override | ||
public void postHandle( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
Object handler, | ||
ModelAndView modelAndView | ||
) { | ||
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); | ||
} | ||
|
||
@Override | ||
public void afterCompletion( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
Object handler | ||
) { | ||
HandlerInterceptor.super.afterCompletion(request, response, handler); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package project.server.app.core.web.user.application; | ||
|
||
import project.server.app.common.login.LoginUser; | ||
|
||
public interface UserUpdateUseCase { | ||
void update(LoginUser loginUser, String password); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependsOn downloadYml이라고 검색해보도 잘 안나와서 그런데,
어떤 작업을 하신건지 설명해주실 수 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
외부 저장소에 저장된 yml 값을 받아오는 역할을 합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전 글 한 번 참조해보면 좋을 것 같습니다.