From ee931cf377b9c637c80c702d2db9341e49922085 Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 1 Jul 2024 20:53:04 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20TokenResponse=20DTO=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/controller/TokenController.java | 4 ++-- .../dto/{ReissueTokenResponse.java => TokenResponse.java} | 3 ++- .../sanbosillokserver/api/auth/service/TokenService.java | 6 +++--- .../sanbosillokserver/config/jwt/LoginFilter.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) rename src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/{ReissueTokenResponse.java => TokenResponse.java} (75%) diff --git a/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/controller/TokenController.java b/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/controller/TokenController.java index 0ec2e34..e3576ad 100644 --- a/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/controller/TokenController.java +++ b/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/controller/TokenController.java @@ -1,7 +1,7 @@ package com.sanbosillok.sanbosillokserver.api.auth.controller; import com.sanbosillok.sanbosillokserver.api.auth.dto.RefreshTokenRequest; -import com.sanbosillok.sanbosillokserver.api.auth.dto.ReissueTokenResponse; +import com.sanbosillok.sanbosillokserver.api.auth.dto.TokenResponse; import com.sanbosillok.sanbosillokserver.api.auth.service.TokenService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -14,7 +14,7 @@ public class TokenController { private final TokenService tokenService; @PostMapping("/refresh") - public ReissueTokenResponse getNewToken(@RequestBody @Valid RefreshTokenRequest refreshTokenRequest) { + public TokenResponse getNewToken(@RequestBody @Valid RefreshTokenRequest refreshTokenRequest) { return tokenService.reIssueAccessToken(refreshTokenRequest.getRefreshToken()); } } diff --git a/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/ReissueTokenResponse.java b/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/TokenResponse.java similarity index 75% rename from src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/ReissueTokenResponse.java rename to src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/TokenResponse.java index d2eca80..754f23e 100644 --- a/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/ReissueTokenResponse.java +++ b/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/dto/TokenResponse.java @@ -5,7 +5,8 @@ @Data @AllArgsConstructor -public class ReissueTokenResponse { +public class TokenResponse { private String accessToken; private String refreshToken; + private String role; } diff --git a/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/service/TokenService.java b/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/service/TokenService.java index f26004d..5132f41 100644 --- a/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/service/TokenService.java +++ b/src/main/java/com/sanbosillok/sanbosillokserver/api/auth/service/TokenService.java @@ -1,6 +1,6 @@ package com.sanbosillok.sanbosillokserver.api.auth.service; -import com.sanbosillok.sanbosillokserver.api.auth.dto.ReissueTokenResponse; +import com.sanbosillok.sanbosillokserver.api.auth.dto.TokenResponse; import com.sanbosillok.sanbosillokserver.api.member.domain.Member; import com.sanbosillok.sanbosillokserver.api.member.repository.MemberRepository; import com.sanbosillok.sanbosillokserver.config.jwt.JwtTokenProvider; @@ -13,7 +13,7 @@ public class TokenService { private final JwtTokenProvider jwtTokenProvider; private final MemberRepository memberRepository; - public ReissueTokenResponse reIssueAccessToken(String refreshToken) { + public TokenResponse reIssueAccessToken(String refreshToken) { if (refreshToken == null) { throw new IllegalArgumentException("토큰이 비어있습니다."); @@ -30,6 +30,6 @@ public ReissueTokenResponse reIssueAccessToken(String refreshToken) { String role = "ROLE_" + member.getRole().toString(); Long id = member.getId(); - return new ReissueTokenResponse(jwtTokenProvider.createAccessToken(username, role), jwtTokenProvider.createRefreshToken(id)); + return new TokenResponse(jwtTokenProvider.createAccessToken(username, role), jwtTokenProvider.createRefreshToken(id), role); } } diff --git a/src/main/java/com/sanbosillok/sanbosillokserver/config/jwt/LoginFilter.java b/src/main/java/com/sanbosillok/sanbosillokserver/config/jwt/LoginFilter.java index 715be65..6e49b3e 100644 --- a/src/main/java/com/sanbosillok/sanbosillokserver/config/jwt/LoginFilter.java +++ b/src/main/java/com/sanbosillok/sanbosillokserver/config/jwt/LoginFilter.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.sanbosillok.sanbosillokserver.api.auth.dto.CustomUserDetails; -import com.sanbosillok.sanbosillokserver.api.auth.dto.LoginResponse; +import com.sanbosillok.sanbosillokserver.api.auth.dto.TokenResponse; import jakarta.servlet.FilterChain; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -59,7 +59,7 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR String accessToken = jwtTokenProvider.createAccessToken(username, role); response.setContentType("application/json"); - response.getWriter().print(objectMapper.writeValueAsString(new LoginResponse(refreshToken, accessToken, role))); + response.getWriter().print(objectMapper.writeValueAsString(new TokenResponse(refreshToken, accessToken, role))); } @Override