Skip to content

Commit

Permalink
refactor : jwt filter에서 필요없는 repository 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
chwangmin committed May 19, 2024
1 parent 0fb3915 commit ad66b87
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit ad66b87

Please sign in to comment.