Increases max session life time.

This commit is contained in:
Stefan Schallerl 2025-02-10 12:43:41 +01:00
parent 77424c4842
commit d6efa4d1a4

View file

@ -9,15 +9,18 @@ import org.eclipse.jetty.server.session.DefaultSessionCache
import org.eclipse.jetty.server.session.FileSessionDataStore
import org.eclipse.jetty.server.session.SessionHandler
import java.io.File
import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
fun main() {
val dtf = DateTimeFormatter.ISO_DATE_TIME
val db = System.getenv("dbpath")
val db = System.getenv("db_path")
?: throw IllegalArgumentException("Please define an env dbpath, e.g. /data/filemure.db")
val sessionExpiry = System.getenv("session_expiry_sec")?.toInt() ?: (Duration.ofMinutes(30).toSeconds().toInt())
val app = FilemureApp(SqliteRepository("jdbc:sqlite:$db"))
Javalin
@ -35,7 +38,7 @@ fun main() {
config.useVirtualThreads = true
config.jetty.modifyServletContextHandler {
it.sessionHandler = fileSessionHandler()
it.sessionHandler = fileSessionHandler(sessionExpiry)
}
}
.also {
@ -44,14 +47,14 @@ fun main() {
.start(7070)
}
fun fileSessionHandler() = SessionHandler().apply {
fun fileSessionHandler(expirySec: Int) = SessionHandler().apply {
sessionCache = DefaultSessionCache(this).apply {
sessionDataStore = FileSessionDataStore().apply {
val baseDir = File(System.getProperty("java.io.tmpdir"))
this.storeDir = File(baseDir, "javalin-session").apply { mkdirs() }
}
}
maxInactiveInterval = 30 * 60
maxInactiveInterval = expirySec
httpOnly = true
isSecureRequestOnly = true
sameSite = HttpCookie.SameSite.STRICT