-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π ν ν° μ¬λ°κΈ #8
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ad41802
add :: RefreshToken
ta2ye0n 8642630
add :: RefreshToken save
ta2ye0n 401d4b5
add :: ExpiredTokenException
ta2ye0n 1f57ac7
add :: RefreshTokenRepository
ta2ye0n 933cc9c
feat :: ReissueTokenService
ta2ye0n 8a4f585
add :: endpoint μ€μ
ta2ye0n ebbcf15
refactor :: Long -> String
ta2ye0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/com/gcms/v3/domain/auth/domain/entity/RefreshToken.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,20 @@ | ||
package com.gcms.v3.domain.auth.domain.entity; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.index.Indexed; | ||
|
||
@Getter | ||
@Builder | ||
@RedisHash(value = "refreshToken", timeToLive = 60L * 60 * 24 * 7) | ||
public class RefreshToken { | ||
|
||
@Indexed | ||
private String email; | ||
|
||
@Id | ||
@Indexed | ||
private String token; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/gcms/v3/domain/auth/domain/repository/RefreshTokenRepository.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,12 @@ | ||
package com.gcms.v3.domain.auth.domain.repository; | ||
|
||
import com.gcms.v3.domain.auth.domain.entity.RefreshToken; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface RefreshTokenRepository extends CrudRepository<RefreshToken, Long> { | ||
Optional<RefreshToken> findByToken(String token); | ||
|
||
RefreshToken findByEmail(String email); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gcms/v3/domain/auth/exception/ExpiredTokenException.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.gcms.v3.domain.auth.exception; | ||
|
||
import com.gcms.v3.global.error.BasicException; | ||
import com.gcms.v3.global.error.ErrorCode; | ||
|
||
public class ExpiredTokenException extends BasicException { | ||
public ExpiredTokenException() { | ||
super(ErrorCode.EXPIRED_TOKEN); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/gcms/v3/domain/auth/service/ReissueTokenService.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,7 @@ | ||
package com.gcms.v3.domain.auth.service; | ||
|
||
import com.gcms.v3.domain.auth.presentation.data.response.TokenInfoResponseDto; | ||
|
||
public interface ReissueTokenService { | ||
TokenInfoResponseDto execute(String refreshToken); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/gcms/v3/domain/auth/service/impl/ReissueTokenServiceImpl.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,49 @@ | ||
package com.gcms.v3.domain.auth.service.impl; | ||
|
||
import com.gcms.v3.domain.auth.domain.entity.RefreshToken; | ||
import com.gcms.v3.domain.auth.domain.repository.RefreshTokenRepository; | ||
import com.gcms.v3.domain.auth.exception.UserNotFoundException; | ||
import com.gcms.v3.domain.auth.presentation.data.response.TokenInfoResponseDto; | ||
import com.gcms.v3.domain.auth.service.ReissueTokenService; | ||
import com.gcms.v3.domain.user.domain.entity.User; | ||
import com.gcms.v3.domain.user.domain.repository.UserRepository; | ||
import com.gcms.v3.global.security.exception.ExpiredTokenException; | ||
import com.gcms.v3.global.security.jwt.JwtTokenProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class ReissueTokenServiceImpl implements ReissueTokenService { | ||
|
||
private final JwtTokenProvider jwtTokenProvider; | ||
private final UserRepository userRepository; | ||
private final RefreshTokenRepository refreshTokenRepository; | ||
|
||
public TokenInfoResponseDto execute(String refreshToken) { | ||
String refresh = jwtTokenProvider.parseToken(refreshToken); | ||
|
||
String email = jwtTokenProvider.exactEmailFromRefreshToken(refresh); | ||
|
||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(UserNotFoundException::new); | ||
|
||
RefreshToken existingRefreshToken = refreshTokenRepository.findByToken(refresh) | ||
.orElseThrow(ExpiredTokenException::new); | ||
|
||
TokenInfoResponseDto responseDto = jwtTokenProvider.generateToken(user.getEmail()); | ||
|
||
saveRefreshToken(existingRefreshToken.getEmail(), responseDto.refreshToken()); | ||
|
||
return responseDto; | ||
} | ||
|
||
private void saveRefreshToken(String email, String refreshToken) { | ||
RefreshToken token = RefreshToken.builder() | ||
.email(email) | ||
.token(refreshToken) | ||
.build(); | ||
|
||
refreshTokenRepository.save(token); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RefreshTokenμ Id νμ μ StringμΈλ° μ¬κΈ°μ LongμΌλ‘ λμ΄μλ€μ
StringμΌλ‘ λ³κ²½ν΄ μ£ΌμΈμ!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ebbcf15
μμ νμ΅λλ€!