mirror of
https://github.com/MewoLab/AquaDX.git
synced 2025-10-25 20:12:39 +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.AquaNetUserRepo
|
||||||
import icu.samnyan.aqua.net.db.SessionToken
|
import icu.samnyan.aqua.net.db.SessionToken
|
||||||
import icu.samnyan.aqua.net.db.SessionTokenRepo
|
import icu.samnyan.aqua.net.db.SessionTokenRepo
|
||||||
|
import icu.samnyan.aqua.net.db.getTokenExpiry
|
||||||
import io.jsonwebtoken.JwtParser
|
import io.jsonwebtoken.JwtParser
|
||||||
import io.jsonwebtoken.Jwts
|
import io.jsonwebtoken.Jwts
|
||||||
import io.jsonwebtoken.security.Keys
|
import io.jsonwebtoken.security.Keys
|
||||||
@ -63,7 +64,7 @@ class JWT(
|
|||||||
@Transactional
|
@Transactional
|
||||||
fun gen(user: AquaNetUser): Str {
|
fun gen(user: AquaNetUser): Str {
|
||||||
val activeTokens = sessionRepo.findByAquaNetUserAuId(user.auId)
|
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()) {
|
if (activeTokens.isNotEmpty()) {
|
||||||
sessionRepo.deleteAll(activeTokens)
|
sessionRepo.deleteAll(activeTokens)
|
||||||
}
|
}
|
||||||
@ -96,6 +97,10 @@ class JWT(
|
|||||||
sessionRepo.delete(token)
|
sessionRepo.delete(token)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionRepo.save(token.apply{
|
||||||
|
expiry = getTokenExpiry()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return token?.aquaNetUser
|
return token?.aquaNetUser
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import java.io.Serializable
|
|||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
|
fun getTokenExpiry() = Instant.now().plusSeconds(7 * 86400)
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "aqua_net_session")
|
@Table(name = "aqua_net_session")
|
||||||
class SessionToken(
|
class SessionToken(
|
||||||
@ -16,7 +18,7 @@ class SessionToken(
|
|||||||
|
|
||||||
// Token creation time
|
// Token creation time
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
var expiry: Instant = Instant.now().plusSeconds(14 * 86400),
|
var expiry: Instant = getTokenExpiry(),
|
||||||
|
|
||||||
// Linking to the AquaNetUser
|
// Linking to the AquaNetUser
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user