-
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.
* refactor: #107 refreshTokenRepository 인터페이스화해 의존성 제거 * feat: JpaRefreshtoken entity, repository를 infra-security에 추가, rdbRefreshToken 구현 rdbRefreshTokenRepository는 만료시간에 대해 추가적인 구현 필요 * feat: #107 jpaRefreshToken에 생성일 추가 * feat: jpaRefreshToken 시간 체크 기능 추가 * fix: 어노테이션 수정
- Loading branch information
Showing
9 changed files
with
129 additions
and
18 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
11 changes: 11 additions & 0 deletions
11
infra/infra-security/src/main/kotlin/com/kw/infrasecurity/config/JpaConfig.kt
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.kw.infrasecurity.config | ||
|
||
import org.springframework.boot.autoconfigure.domain.EntityScan | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories | ||
|
||
@Configuration | ||
@EntityScan("com.kw.infrasecurity.refreshToken") | ||
@EnableJpaRepositories(basePackages = ["com.kw.infrasecurity.refreshToken"]) | ||
class JpaConfig { | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...nfra-security/src/main/kotlin/com/kw/infrasecurity/refreshToken/entity/JpaRefreshToken.kt
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,24 @@ | ||
package com.kw.infrasecurity.refreshToken.entity | ||
|
||
import jakarta.persistence.* | ||
import org.springframework.data.annotation.CreatedDate | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
@Table(name = "refresh_token") | ||
@EntityListeners(AuditingEntityListener::class) | ||
class JpaRefreshToken(@Column(name = "refresh_token", nullable = false, updatable = false) | ||
val refreshToken: String, | ||
@Column(name = "member_id", nullable = false, updatable = false) | ||
val memberId: Long) { | ||
@Id | ||
@Column(name = "id", nullable = false, updatable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long? = null | ||
|
||
@Column(name = "created_at", nullable = false, updatable = false) | ||
@CreatedDate | ||
var createdAt: LocalDateTime = LocalDateTime.now() | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
...src/main/kotlin/com/kw/infrasecurity/refreshToken/repository/JpaRefreshTokenRepository.kt
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.kw.infrasecurity.refreshToken.repository | ||
|
||
import com.kw.infrasecurity.refreshToken.entity.JpaRefreshToken | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface JpaRefreshTokenRepository: JpaRepository<JpaRefreshToken, Long> { | ||
fun deleteByRefreshToken(refreshToken: String) | ||
|
||
fun findByRefreshToken(refreshToken: String): JpaRefreshToken | ||
} |
46 changes: 46 additions & 0 deletions
46
...src/main/kotlin/com/kw/infrasecurity/refreshToken/repository/RdbRefreshTokenRepository.kt
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,46 @@ | ||
package com.kw.infrasecurity.refreshToken.repository | ||
|
||
import com.kw.infrasecurity.refreshToken.entity.JpaRefreshToken | ||
import org.springframework.context.annotation.Primary | ||
import org.springframework.stereotype.Repository | ||
import java.time.Duration | ||
import java.time.LocalDateTime | ||
|
||
@Primary | ||
@Repository | ||
class RdbRefreshTokenRepository(val jpaRefreshTokenRepository: JpaRefreshTokenRepository): RefreshTokenRepository { | ||
override fun save(refreshToken: String, memberId: Long) { | ||
val jpaRefreshToken = JpaRefreshToken( | ||
refreshToken = refreshToken, | ||
memberId = memberId) | ||
jpaRefreshTokenRepository.save(jpaRefreshToken) | ||
} | ||
|
||
override fun delete(refreshToken: String) { | ||
jpaRefreshTokenRepository.deleteByRefreshToken(refreshToken) | ||
} | ||
|
||
override fun findByRefreshToken(refreshToken: String): Long? { | ||
val jpaRefreshToken = jpaRefreshTokenRepository.findByRefreshToken(refreshToken) ?: return null | ||
|
||
if(isRefreshTokenExpired(jpaRefreshToken)) | ||
return null | ||
|
||
return jpaRefreshToken.memberId | ||
} | ||
// TODO 테스트 해보기 | ||
|
||
private fun isRefreshTokenExpired(refreshToken: JpaRefreshToken): Boolean { | ||
val timeDifference = Duration.between(LocalDateTime.now(), refreshToken.createdAt) | ||
if(timeDifference.toSeconds() < REFRESH_TOKEN_EXPIRE_LONG) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// TODO 만료된 refresh token 처리 구현하기 | ||
companion object { | ||
private const val REFRESH_TOKEN_EXPIRE_LONG = 259200L | ||
} | ||
// TODO 만료기간 yml에서 가져오게 수정하기 | ||
} |
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: 9 additions & 0 deletions
9
...ty/src/main/kotlin/com/kw/infrasecurity/refreshToken/repository/RefreshTokenRepository.kt
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,9 @@ | ||
package com.kw.infrasecurity.refreshToken.repository | ||
|
||
interface RefreshTokenRepository { | ||
fun save(refreshToken: String, memberId: Long) | ||
|
||
fun delete(refreshToken: String) | ||
|
||
fun findByRefreshToken(refreshToken: String): Long? | ||
} |
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