Skip to content

Commit

Permalink
[feat] SessionArgumentResolver 컴포넌트 등록 및 WebConfiguration 설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
june-777 committed Aug 13, 2024
1 parent c64baf9 commit 6e088ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/main/java/camp/woowak/lab/web/config/WebConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package camp.woowak.lab.web.config;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import camp.woowak.lab.web.resolver.session.SessionCustomerArgumentResolver;
import camp.woowak.lab.web.resolver.session.SessionVendorArgumentResolver;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class WebConfiguration implements WebMvcConfigurer {

private final SessionVendorArgumentResolver sessionVendorArgumentResolver;
private final SessionCustomerArgumentResolver sessionCustomerArgumentResolver;

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(sessionVendorArgumentResolver);
resolvers.add(sessionCustomerArgumentResolver);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package camp.woowak.lab.web.resolver.session;

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.ModelAndViewContainer;
Expand All @@ -12,6 +13,7 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

@Component
public class SessionCustomerArgumentResolver extends LoginMemberArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
Expand All @@ -21,7 +23,7 @@ public boolean supportsParameter(MethodParameter parameter) {

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
AuthenticationPrincipal parameterAnnotation = parameter.getParameterAnnotation(AuthenticationPrincipal.class);
if (parameterAnnotation == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package camp.woowak.lab.web.resolver.session;

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.ModelAndViewContainer;
Expand All @@ -12,6 +13,7 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

@Component
public class SessionVendorArgumentResolver extends LoginMemberArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
Expand All @@ -21,7 +23,7 @@ public boolean supportsParameter(MethodParameter parameter) {

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
AuthenticationPrincipal parameterAnnotation = parameter.getParameterAnnotation(AuthenticationPrincipal.class);
if (parameterAnnotation == null) {
return null;
Expand Down

0 comments on commit 6e088ca

Please sign in to comment.