mirror of
https://github.com/MewoLab/AquaDX.git
synced 2025-10-25 12:02:40 +00:00
Session Token Revitalization (#167)
This commit is contained in:
parent
d0b67c37f6
commit
9dc7a790cc
@ -6,6 +6,7 @@ import icu.samnyan.aqua.net.db.AquaNetUser
|
||||
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
||||
import icu.samnyan.aqua.net.db.SessionToken
|
||||
import icu.samnyan.aqua.net.db.SessionTokenRepo
|
||||
import icu.samnyan.aqua.net.db.getTokenExpiry
|
||||
import io.jsonwebtoken.JwtParser
|
||||
import io.jsonwebtoken.Jwts
|
||||
import io.jsonwebtoken.security.Keys
|
||||
@ -63,7 +64,7 @@ class JWT(
|
||||
@Transactional
|
||||
fun gen(user: AquaNetUser): Str {
|
||||
val activeTokens = sessionRepo.findByAquaNetUserAuId(user.auId)
|
||||
.sortedByDescending { it.expiry }.drop(4) // the cap is 5, but we append a new token after the fact
|
||||
.sortedByDescending { it.expiry }.drop(9) // the cap is 10, but we append a new token after the fact
|
||||
if (activeTokens.isNotEmpty()) {
|
||||
sessionRepo.deleteAll(activeTokens)
|
||||
}
|
||||
@ -96,6 +97,10 @@ class JWT(
|
||||
sessionRepo.delete(token)
|
||||
return null
|
||||
}
|
||||
|
||||
sessionRepo.save(token.apply{
|
||||
expiry = getTokenExpiry()
|
||||
})
|
||||
}
|
||||
|
||||
return token?.aquaNetUser
|
||||
|
||||
@ -7,6 +7,8 @@ import java.io.Serializable
|
||||
import java.time.Instant
|
||||
import java.util.UUID
|
||||
|
||||
fun getTokenExpiry() = Instant.now().plusSeconds(7 * 86400)
|
||||
|
||||
@Entity
|
||||
@Table(name = "aqua_net_session")
|
||||
class SessionToken(
|
||||
@ -16,7 +18,7 @@ class SessionToken(
|
||||
|
||||
// Token creation time
|
||||
@Column(nullable = false)
|
||||
var expiry: Instant = Instant.now().plusSeconds(14 * 86400),
|
||||
var expiry: Instant = getTokenExpiry(),
|
||||
|
||||
// Linking to the AquaNetUser
|
||||
@ManyToOne
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user