-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/socialLogin' into develop
- Loading branch information
Showing
36 changed files
with
205 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mpnp.baechelin.exception; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ErrorCode { | ||
|
||
SUCCESS_MESSAGE(200, "S-SUC200","SUCCESS"), | ||
// NOT_FOUND_MESSAGE(500, "BE001", "NOT FOUND"), | ||
FAILED_MESSAGE(500, "E-FAI500","서버에서 오류가 발생하였습니다."), | ||
INVALID_ACCESS_TOKEN(401, "E-IAT401","유효하지 않은 Access Token입니다."), | ||
INVALID_REFRESH_TOKEN(401, "E-IRT401", "유효하지 않은 Refresh Token입니다."), | ||
NOT_EXPIRED_TOKEN_YET(401, "E-NET401", "만료되지 않은 JWT 토큰입니다."), | ||
EXPIRED_TOKEN(401, "E-EXT401", "만료된 JWT 토큰입니다."), | ||
WRONG_TYPE_TOKEN(401, "E-WTT401","잘못된 JWT 토큰입니다."), | ||
WRONG_TYPE_SIGNATURE(401, "E-WTS401", "잘못된 JWT 서명입니다."), | ||
ACCESS_DENIED(401, "E-ACD401","접근이 거부되었습니다."), | ||
TOKEN_NOT_EXIST(401, "E-TNE401", "토큰이 존재하지 않습니다."), | ||
ALREADY_LOGIN_ACCOUNT(400, "E-ALA400","다른 계정으로 로그인 되었습니다."); | ||
|
||
private final int status; | ||
private final String code; | ||
private final String message; | ||
} |
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
4 changes: 2 additions & 2 deletions
4
.../baechelin/config/security/JwtConfig.java → ...baechelin/login/jwt/config/JwtConfig.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
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
2 changes: 1 addition & 1 deletion
2
...echelin/user/domain/UserRefreshToken.java → ...in/login/jwt/entity/UserRefreshToken.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
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
2 changes: 1 addition & 1 deletion
2
.../exception/TokenValidFailedException.java → .../exception/TokenValidFailedException.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
70 changes: 70 additions & 0 deletions
70
src/main/java/com/mpnp/baechelin/login/jwt/filter/TokenAuthenticationFilter.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,70 @@ | ||
package com.mpnp.baechelin.login.jwt.filter; | ||
|
||
import com.mpnp.baechelin.exception.ErrorCode; | ||
import com.mpnp.baechelin.login.jwt.AuthToken; | ||
import com.mpnp.baechelin.login.jwt.AuthTokenProvider; | ||
import com.mpnp.baechelin.util.HeaderUtil; | ||
import io.jsonwebtoken.ExpiredJwtException; | ||
import io.jsonwebtoken.MalformedJwtException; | ||
import io.jsonwebtoken.UnsupportedJwtException; | ||
import io.jsonwebtoken.security.SignatureException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/* 토큰을 파싱하여 유저 정보를 가지고 오고, 토큰이 유효할 경우 그 유저에게 권한을 부여하는 클래스 | ||
* usernamepasswordAuthenticationFilter 보다 먼저 토큰을 바탕으로 유저를 등록시키는 클래스 | ||
* OncePerRequestFilter는 요청 당 한번 만 일어나도록 하는 추상클래스이다. | ||
*/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class TokenAuthenticationFilter extends OncePerRequestFilter { | ||
|
||
private final AuthTokenProvider tokenProvider; | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
FilterChain filterChain) throws ServletException, IOException { | ||
|
||
// 요청값의 header에서 토큰을 뽑아온다. | ||
String tokenStr = HeaderUtil.getAccessToken(request); | ||
// String으로 된 token을 AuthToken객체로 변환해준다. | ||
AuthToken token = tokenProvider.convertAuthToken(tokenStr); | ||
|
||
try { | ||
if (token != null && token.tokenValidate()) { | ||
Authentication authentication = tokenProvider.getAuthentication(token); | ||
// SecurityContextHolder 에 인증 객체를 넣는다. | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
} | ||
// 에러가 발생했을 때, request에 attribute를 세팅하고 RestAuthenticationEntryPoint로 request를 넘겨준다. | ||
} catch (SignatureException e) { | ||
log.info("잘못된 JWT 서명입니다."); | ||
request.setAttribute("exception", ErrorCode.WRONG_TYPE_SIGNATURE.getCode()); | ||
} catch (MalformedJwtException e) { | ||
log.info("유효하지 않은 구성의 JWT 토큰입니다."); | ||
request.setAttribute("exception", ErrorCode.WRONG_TYPE_TOKEN.getCode()); | ||
} catch (ExpiredJwtException e) { | ||
log.info("만료된 JWT 토큰입니다."); | ||
request.setAttribute("exception", ErrorCode.EXPIRED_TOKEN.getCode()); | ||
} catch (UnsupportedJwtException e) { | ||
log.info("지원되지 않는 형식이나 구성의 JWT 토큰입니다."); | ||
request.setAttribute("exception", ErrorCode.WRONG_TYPE_TOKEN.getCode()); | ||
} catch (IllegalArgumentException e) { | ||
log.info(e.toString().split(":")[1].trim()); | ||
request.setAttribute("exception", ErrorCode.TOKEN_NOT_EXIST.getCode()); | ||
} | ||
|
||
filterChain.doFilter(request, response); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...uth/handler/TokenAccessDeniedHandler.java → ...jwt/handler/TokenAccessDeniedHandler.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
4 changes: 2 additions & 2 deletions
4
...epository/UserRefreshTokenRepository.java → ...epository/UserRefreshTokenRepository.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
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
2 changes: 1 addition & 1 deletion
2
.../baechelin/oauth/entity/ProviderType.java → ...elin/login/oauth/entity/ProviderType.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,4 +1,4 @@ | ||
package com.mpnp.baechelin.oauth.entity; | ||
package com.mpnp.baechelin.login.oauth.entity; | ||
|
||
import lombok.Getter; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...mpnp/baechelin/oauth/entity/RoleType.java → ...aechelin/login/oauth/entity/RoleType.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
2 changes: 1 addition & 1 deletion
2
...baechelin/oauth/entity/UserPrincipal.java → ...lin/login/oauth/entity/UserPrincipal.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
2 changes: 1 addition & 1 deletion
2
...tion/OAuthProviderMissMatchException.java → ...tion/OAuthProviderMissMatchException.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
Oops, something went wrong.