-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: kakao accessToken으로 로그인, Server jwt 발급 (#51)
- Loading branch information
Showing
19 changed files
with
141 additions
and
319 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
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
66 changes: 0 additions & 66 deletions
66
src/main/java/com/api/ttoklip/global/security/auth/UserPrincipal.java
This file was deleted.
Oops, something went wrong.
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
9 changes: 1 addition & 8 deletions
9
src/main/java/com/api/ttoklip/global/security/auth/dto/LoginResponse.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,14 +1,7 @@ | ||
package com.api.ttoklip.global.security.auth.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class LoginResponse { | ||
private String jwtToken; | ||
private boolean ifFirstLogin; | ||
public record LoginResponse(String jwtToken, boolean ifFirstLogin) { | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/api/ttoklip/global/security/auth/handler/AuthFailureHandler.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.api.ttoklip.global.security.auth.handler; | ||
|
||
import com.api.ttoklip.global.exception.ApiException; | ||
import com.api.ttoklip.global.exception.ErrorType; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.authentication.AuthenticationFailureHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AuthFailureHandler implements AuthenticationFailureHandler { | ||
|
||
@Override | ||
public void onAuthenticationFailure(final HttpServletRequest request, final HttpServletResponse response, | ||
final AuthenticationException authException) throws IOException { | ||
ApiException apiException = (ApiException) authException.getCause(); | ||
ErrorType errorType = apiException.getErrorType(); | ||
setResponse(response, errorType); | ||
} | ||
|
||
private void setResponse(HttpServletResponse response, ErrorType errorType) throws IOException { | ||
|
||
response.setContentType("application/json;charset=UTF-8"); | ||
|
||
int status = Integer.parseInt(String.valueOf(errorType.getStatus()).substring(0,3)); | ||
response.setStatus(status); | ||
|
||
response.getWriter().println( | ||
"{\"status\" : \"" + status + "\"," + | ||
"\"errorCode\" : \"" + errorType.getErrorCode() + "\"," + | ||
" \"message\" : \"" + errorType.getMessage() + | ||
"\"}"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/api/ttoklip/global/security/auth/handler/TokenErrorHandler.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.api.ttoklip.global.security.auth.handler; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.web.access.AccessDeniedHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class TokenErrorHandler implements AccessDeniedHandler { | ||
// 권한 부족시 호출되는 핸들러 | ||
@Override | ||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException { | ||
response.sendError(HttpServletResponse.SC_FORBIDDEN); | ||
} | ||
} |
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
Oops, something went wrong.