-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FIX] 토큰 재발급 API 에러 수정
- Loading branch information
Showing
5 changed files
with
87 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
.../main/java/com/example/growthookserver/common/config/jwt/JwtAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
package com.example.growthookserver.common.config.jwt; | ||
|
||
import com.example.growthookserver.common.response.ApiResponse; | ||
import com.example.growthookserver.common.response.ErrorStatus; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, | ||
AuthenticationException authException) throws IOException { | ||
setResponse(response); | ||
setResponse(response, HttpStatus.UNAUTHORIZED, ErrorStatus.UNAUTHORIZED_TOKEN); | ||
} | ||
|
||
|
||
public void setResponse(HttpServletResponse response) throws IOException { | ||
public void setResponse(HttpServletResponse response, HttpStatus statusCode, ErrorStatus status) throws IOException { | ||
response.setContentType("application/json;charset=UTF-8"); | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
|
||
ApiResponse apiResponse = ApiResponse.fail(statusCode.value(), status.getMessage()); | ||
response.getWriter().println(mapper.writeValueAsString(apiResponse)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters