-
Notifications
You must be signed in to change notification settings - Fork 7
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
로그인 처리 공통화를 위한 ArgumentResolver 및 Interceptor 구현 #156
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d6817b
feat: LoginMember, LoginMemberArgumentResolver 구현
ksk0605 e61e35c
feat: LoginMemberArgumentResolver 등록 및 웹MVC 설정 구현
ksk0605 d11e946
refactor: 코드 리포맷팅
ksk0605 1b33085
feat: 로그인 여부 체크를 위한 인터셉터 구현 및 등록
ksk0605 03139a9
test: 데이터베이스 클리터 추가
ksk0605 d50dee1
refactor: 코드 리포맷팅
ksk0605 68bc14d
feat: 설정 클래스 등록
ksk0605 5a41bda
test: 엑세스 토큰 픽스쳐 구현
ksk0605 4081652
refactor: 상수 접근제어자 수정
ksk0605 de0bcdd
refactor: 메소드 분리
ksk0605 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/mouda/backend/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package mouda.backend.config; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.config.argumentresolver.LoginMemberArgumentResolver; | ||
import mouda.backend.config.interceptor.AuthenticationCheckInterceptor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
private final LoginMemberArgumentResolver loginMemberArgumentResolver; | ||
|
||
private final AuthenticationCheckInterceptor authenticationCheckInterceptor; | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(authenticationCheckInterceptor) | ||
.addPathPatterns("/v1/**") | ||
.excludePathPatterns("/v1/auth/login"); | ||
} | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(loginMemberArgumentResolver); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/mouda/backend/config/argumentresolver/LoginMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package mouda.backend.config.argumentresolver; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface LoginMember { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/mouda/backend/config/argumentresolver/LoginMemberArgumentResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package mouda.backend.config.argumentresolver; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.auth.service.AuthService; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class LoginMemberArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
private final AuthService authService; | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Object resolveArgument( | ||
MethodParameter parameter, ModelAndViewContainer mavContainer, | ||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory | ||
) throws Exception { | ||
String authorizationHeader = webRequest.getHeader("Authorization"); | ||
|
||
String token = extractToken(authorizationHeader); | ||
return authService.findMember(token); | ||
} | ||
|
||
private String extractToken(String authorizationHeader) { | ||
return authorizationHeader.substring(7); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/mouda/backend/config/interceptor/AuthenticationCheckInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mouda.backend.config.interceptor; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import mouda.backend.auth.service.AuthService; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AuthenticationCheckInterceptor implements HandlerInterceptor { | ||
|
||
private static final String AUTHORIZATION_PREFIX = "Bearer "; | ||
|
||
private final AuthService authService; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { | ||
String authorizationHeader = request.getHeader("Authorization"); | ||
|
||
if (authorizationHeader == null || !authorizationHeader.startsWith(AUTHORIZATION_PREFIX)) { | ||
throw new IllegalArgumentException("Authorization header is missing or invalid"); | ||
} | ||
|
||
String token = extractToken(authorizationHeader); | ||
authService.checkAuthentication(token); | ||
|
||
return true; | ||
} | ||
|
||
private String extractToken(String authorizationHeader) { | ||
return authorizationHeader.substring(7); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
피드백 반영 감사요