-
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
refreshToken도입 + 로그아웃 기능 구현
- Loading branch information
Showing
8 changed files
with
277 additions
and
32 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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/api/trip/common/exception/custom_exception/BadRequestException.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,10 @@ | ||
package com.api.trip.common.exception.custom_exception; | ||
|
||
import com.api.trip.common.exception.CustomException; | ||
import com.api.trip.common.exception.ErrorCode; | ||
|
||
public class BadRequestException extends CustomException { | ||
public BadRequestException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/api/trip/common/exception/custom_exception/InvalidException.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,10 @@ | ||
package com.api.trip.common.exception.custom_exception; | ||
|
||
import com.api.trip.common.exception.CustomException; | ||
import com.api.trip.common.exception.ErrorCode; | ||
|
||
public class InvalidException extends CustomException { | ||
public InvalidException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/api/trip/common/security/util/JwtTokenUtils.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,53 @@ | ||
package com.api.trip.common.security.util; | ||
|
||
|
||
|
||
import com.api.trip.common.exception.ErrorCode; | ||
import com.api.trip.common.exception.custom_exception.BadRequestException; | ||
import com.api.trip.common.redis.RedisService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class JwtTokenUtils { | ||
|
||
private final RedisService redisService; | ||
|
||
@Value("${custom.jwt.token.refresh-expiration-time}") | ||
private long refreshExpirationTime; | ||
/** | ||
* @Description | ||
* Bearer토큰의 여부에 대해 검증한 뒤 토큰을 반환합니다. | ||
*/ | ||
public static String extractBearerToken(String token) { | ||
if(token != null){ | ||
if(!token.startsWith("Bearer")) | ||
throw new BadRequestException(ErrorCode.INVALID_TYPE_TOKEN); | ||
return token.split(" ")[1].trim(); | ||
} | ||
return null; | ||
} | ||
|
||
public boolean isLogin(String email){ | ||
return redisService.getData("Login_" + email) != null; | ||
} | ||
public void setRefreshToken(String username, String refreshToken){ | ||
redisService.setData("Login_" + username, refreshToken, refreshExpirationTime, TimeUnit.SECONDS); | ||
} | ||
public void updateRefreshToken(String name, String refreshToken) { | ||
setRefreshToken(name, refreshToken); | ||
} | ||
|
||
public void deleteRefreshToken(String name) { | ||
redisService.deleteData("Login_" + name); | ||
} | ||
|
||
public String getRefreshToken(String name) { | ||
return redisService.getData("Login_" + name).toString(); | ||
} | ||
|
||
} |
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.