From a0ffeb236e43d03afe6f98b7cfa03c52c264e45e Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Thu, 28 Aug 2025 16:00:54 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=9A=8C=EC=9B=90=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=9D=91=EB=8B=B5=20=EA=B0=9C=EC=84=A0]=20LoginRes?= =?UTF-8?q?ponseDto=EC=97=90=20name=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20MemberMapper=EC=97=90=20toLoginResponse?= =?UTF-8?q?Dto=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80.=20JwtTo?= =?UTF-8?q?kenIssuanceFilter=EC=97=90=EC=84=9C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=84=B1=EA=B3=B5=20=EC=8B=9C=20LoginResponseDto?= =?UTF-8?q?=20=EB=B3=80=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/base/member/dto/LoginResponseDto.java | 1 + .../domain/base/member/mapper/MemberMapper.java | 7 ++++++- .../bio_backend/global/filter/JwtTokenIssuanceFilter.java | 8 ++++---- .../com/bio/bio_backend/global/security/WebSecurity.java | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java b/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java index 22d4068..0bfb95e 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/dto/LoginResponseDto.java @@ -14,5 +14,6 @@ import java.time.LocalDateTime; public class LoginResponseDto { private String userId; + private String name; private LocalDateTime lastLoginAt; } diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java index 779c323..886ec32 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/mapper/MemberMapper.java @@ -2,13 +2,13 @@ package com.bio.bio_backend.domain.base.member.mapper; import com.bio.bio_backend.domain.base.member.dto.CreateMemberRequestDto; import com.bio.bio_backend.domain.base.member.dto.CreateMemberResponseDto; +import com.bio.bio_backend.domain.base.member.dto.LoginResponseDto; import com.bio.bio_backend.domain.base.member.dto.MemberDto; import com.bio.bio_backend.domain.base.member.entity.Member; import com.bio.bio_backend.global.annotation.IgnoreBaseEntityMapping; import com.bio.bio_backend.global.config.GlobalMapperConfig; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.factory.Mappers; import java.util.List; @Mapper(config = GlobalMapperConfig.class) @@ -52,4 +52,9 @@ public interface MemberMapper { */ @IgnoreBaseEntityMapping void updateMemberFromDto(MemberDto memberDto, @org.mapstruct.MappingTarget Member member); + + /** + * MemberDto를 LoginResponseDto로 변환 + */ + LoginResponseDto toLoginResponseDto(MemberDto memberDto); } diff --git a/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java b/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java index 7c5d12d..1b0efd8 100644 --- a/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java +++ b/src/main/java/com/bio/bio_backend/global/filter/JwtTokenIssuanceFilter.java @@ -9,6 +9,7 @@ import com.bio.bio_backend.global.dto.ApiResponseDto; import com.bio.bio_backend.domain.base.member.dto.LoginRequestDto; import com.bio.bio_backend.domain.base.member.dto.LoginResponseDto; import com.bio.bio_backend.domain.base.member.dto.MemberDto; +import com.bio.bio_backend.domain.base.member.mapper.MemberMapper; import com.bio.bio_backend.domain.base.member.service.MemberService; import com.bio.bio_backend.global.constants.ApiResponseCode; import com.bio.bio_backend.global.utils.JwtUtils; @@ -40,6 +41,7 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter private final ObjectMapper objectMapper; private final MemberService memberService; private final HttpUtils httpUtils; + private final MemberMapper memberMapper; // 사용자 login 인증 처리 @Override @@ -83,16 +85,14 @@ public class JwtTokenIssuanceFilter extends UsernamePasswordAuthenticationFilter context.setAuthentication(authResult); contextHolder.setContext(context); - LoginResponseDto memberData = new LoginResponseDto(); - memberData.setUserId(member.getUserId()); - memberData.setLastLoginAt(member.getLastLoginAt()); + LoginResponseDto loginResponseDto = memberMapper.toLoginResponseDto(member); // login 성공 메시지 전송 response.setStatus(HttpStatus.OK.value()); response.setContentType(MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8"); objectMapper.writeValue( response.getWriter(), - ApiResponseDto.success(ApiResponseCode.LOGIN_SUCCESSFUL, memberData) + ApiResponseDto.success(ApiResponseCode.LOGIN_SUCCESSFUL, loginResponseDto) ); } } diff --git a/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java b/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java index 88094bc..b209f47 100644 --- a/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java +++ b/src/main/java/com/bio/bio_backend/global/security/WebSecurity.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.bio.bio_backend.domain.base.member.service.MemberService; +import com.bio.bio_backend.domain.base.member.mapper.MemberMapper; import com.bio.bio_backend.global.exception.CustomAuthenticationFailureHandler; import com.bio.bio_backend.global.utils.JwtUtils; import com.bio.bio_backend.global.utils.HttpUtils; @@ -37,9 +38,10 @@ public class WebSecurity { private final Environment env; private final SecurityPathConfig securityPathConfig; private final HttpUtils httpUtils; + private final MemberMapper memberMapper; private JwtTokenIssuanceFilter getJwtTokenIssuanceFilter(AuthenticationManager authenticationManager) throws Exception { - JwtTokenIssuanceFilter filter = new JwtTokenIssuanceFilter(authenticationManager, jwtUtils, objectMapper, memberService, httpUtils); + JwtTokenIssuanceFilter filter = new JwtTokenIssuanceFilter(authenticationManager, jwtUtils, objectMapper, memberService, httpUtils, memberMapper); filter.setFilterProcessesUrl("/login"); filter.setAuthenticationFailureHandler(new CustomAuthenticationFailureHandler(objectMapper)); return filter;