-
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.
Merge pull request #28 from Team-J9/feature/token
토큰 로직 수정
- Loading branch information
Showing
10 changed files
with
119 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.j9.bestmoments.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${redis.host}") | ||
private String host; | ||
|
||
@Value("${redis.port}") | ||
private int port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/j9/bestmoments/constants/TokenExpiration.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,11 @@ | ||
package com.j9.bestmoments.constants; | ||
|
||
public final class TokenExpiration { | ||
|
||
// 10분 | ||
public static final int ACCESS_TOKEN = 60 * 10; | ||
|
||
// 60분 | ||
public static final int REFRESH_TOKEN = 60 * 60; | ||
|
||
} |
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,40 +1,35 @@ | ||
package com.j9.bestmoments.domain; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.Id; | ||
import java.util.UUID; | ||
import lombok.Getter; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
public class Token { | ||
@RedisHash(value = "Token") | ||
public | ||
class Token { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
private String token; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "member_id", referencedColumnName = "id") | ||
private Member member; | ||
private TokenType tokenType; | ||
|
||
private String refreshToken; | ||
private String accessToken; | ||
@TimeToLive | ||
private Long expiration; | ||
|
||
@Builder | ||
public Token(Member member, String refreshToken, String accessToken) { | ||
this.member = member; | ||
this.refreshToken = refreshToken; | ||
this.accessToken = accessToken; | ||
} | ||
private UUID memberId; | ||
|
||
public void setAccessToken(String accessToken) { | ||
this.accessToken = accessToken; | ||
@Builder | ||
public Token(Member member, TokenType tokenType, String token) { | ||
this.memberId = member.getId(); | ||
this.token = token; | ||
this.tokenType = tokenType; | ||
this.expiration = tokenType.getExpiration(); | ||
} | ||
|
||
} |
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,18 @@ | ||
package com.j9.bestmoments.domain; | ||
|
||
import com.j9.bestmoments.constants.TokenExpiration; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum TokenType { | ||
|
||
ACCESS_TOKEN("accessToken", TokenExpiration.ACCESS_TOKEN), | ||
REFRESH_TOKEN("refreshToken", TokenExpiration.REFRESH_TOKEN), | ||
; | ||
|
||
private final String name; | ||
private final long expiration; | ||
|
||
} |
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
10 changes: 4 additions & 6 deletions
10
src/main/java/com/j9/bestmoments/repository/TokenRepository.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,12 +1,10 @@ | ||
package com.j9.bestmoments.repository; | ||
|
||
import com.j9.bestmoments.domain.Token; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
public interface TokenRepository extends JpaRepository<Token, Long> { | ||
|
||
Optional<Token> findByAccessToken(String accessToken); | ||
Optional<Token> findByRefreshToken(String refreshToken); | ||
@Repository | ||
public interface TokenRepository extends CrudRepository<Token, String> { | ||
|
||
} |
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