-
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
[Feat] 기념일 API 구현 및 AuthenticationEntryPoint 오류 수정 확인
- Loading branch information
Showing
4 changed files
with
54 additions
and
19 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
26 changes: 9 additions & 17 deletions
26
favor/src/main/java/com/favor/favor/exception/CustomAuthenticationEntryPoint.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,39 +1,31 @@ | ||
package com.favor.favor.exception; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import static com.favor.favor.exception.ExceptionCode.UNAUTHORIZED_USER; | ||
|
||
@Component("customAuthenticationEntryPoint") | ||
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
|
||
private static CustomException errorResponse = | ||
new CustomException(new RuntimeException(), UNAUTHORIZED_USER); | ||
|
||
@Override | ||
public void commence(HttpServletRequest request, | ||
HttpServletResponse response, | ||
AuthenticationException ex) throws IOException, ServletException { | ||
AuthenticationException ex) throws IOException { | ||
|
||
// [commence] 인증 실패로 response.sendError 발생 | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
response.setStatus(401); | ||
response.setContentType("application/json"); | ||
response.setCharacterEncoding("utf-8"); | ||
try (OutputStream os = response.getOutputStream()) { | ||
objectMapper.writeValue(os, errorResponse); | ||
os.flush(); | ||
} | ||
response.setStatus(401); | ||
|
||
JSONObject responseJson = new JSONObject(); | ||
responseJson.put("ResponseCode", "AUTHENTICATION_FAILED"); | ||
responseJson.put("ResponseMessage", "인증에 실패하였습니다."); | ||
|
||
response.getWriter().print(responseJson); | ||
} | ||
} |
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