From ad66b87ab433963810ef48441aa52191053b19ae Mon Sep 17 00:00:00 2001 From: chwangmin Date: Sun, 19 May 2024 20:32:31 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20jwt=20filter=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20repository=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/global/auth/filter/JwtAuthenticationFilter.java | 9 ++------- .../global/config/security/WebSecurityConfiguration.java | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/ssafy/home/global/auth/filter/JwtAuthenticationFilter.java b/backend/src/main/java/com/ssafy/home/global/auth/filter/JwtAuthenticationFilter.java index cbeaf6c..bf8c445 100644 --- a/backend/src/main/java/com/ssafy/home/global/auth/filter/JwtAuthenticationFilter.java +++ b/backend/src/main/java/com/ssafy/home/global/auth/filter/JwtAuthenticationFilter.java @@ -1,6 +1,5 @@ package com.ssafy.home.global.auth.filter; -import com.ssafy.home.domain.member.repository.MemberRepository; import com.ssafy.home.domain.member.service.MemberService; import com.ssafy.home.entity.member.Member; import com.ssafy.home.global.auth.dto.MemberDto; @@ -20,17 +19,14 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.NoSuchElementException; @Slf4j public class JwtAuthenticationFilter extends OncePerRequestFilter { private final JwtTokenProvider jwtTokenProvider; - private final MemberRepository memberRepository; private final MemberService memberService; // Jwt Provier 주입 - public JwtAuthenticationFilter(MemberRepository memberRepository, JwtTokenProvider jwtTokenProvider, MemberService memberService) { - this.memberRepository = memberRepository; + public JwtAuthenticationFilter(JwtTokenProvider jwtTokenProvider, MemberService memberService) { this.jwtTokenProvider = jwtTokenProvider; this.memberService = memberService; } @@ -75,8 +71,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse Long userId = jwtTokenProvider.getInfoId(token); log.info("userId : {}", userId); - Member member = memberRepository.findById(userId) - .orElseThrow(() -> new NoSuchElementException("Error: No member found with id " + userId)); + Member member = memberService.getMemberById(userId); UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken( MemberDto.builder() diff --git a/backend/src/main/java/com/ssafy/home/global/config/security/WebSecurityConfiguration.java b/backend/src/main/java/com/ssafy/home/global/config/security/WebSecurityConfiguration.java index e4ada60..4d4784d 100644 --- a/backend/src/main/java/com/ssafy/home/global/config/security/WebSecurityConfiguration.java +++ b/backend/src/main/java/com/ssafy/home/global/config/security/WebSecurityConfiguration.java @@ -40,7 +40,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .httpBasic(AbstractHttpConfigurer::disable) .formLogin(AbstractHttpConfigurer::disable) .logout(AbstractHttpConfigurer::disable) - .addFilterBefore(new JwtAuthenticationFilter(memberRepository, jwtTokenProvider), BasicAuthenticationFilter.class); + .addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider, memberService), BasicAuthenticationFilter.class); return http.build(); }