
org.scalatra.auth.ScentryAuthStore.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalatra-auth_2.9.2 Show documentation
Show all versions of scalatra-auth_2.9.2 Show documentation
Scalatra authentication module
The newest version!
package org.scalatra
package auth
import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpSession}
import servlet.ServletApiImplicits._
import util.RicherString._
import java.text.SimpleDateFormat
import java.util.{Date, TimeZone}
object ScentryAuthStore {
trait ScentryAuthStore {
def get(implicit request: HttpServletRequest, response: HttpServletResponse): String
def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse)
def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse)
}
class CookieAuthStore(app: ScalatraContext)(implicit cookieOptions: CookieOptions = CookieOptions(path = "/")) extends ScentryAuthStore {
def get(implicit request: HttpServletRequest, response: HttpServletResponse) = app.cookies.get(Scentry.scentryAuthKey) getOrElse ""
def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse) {
app.cookies.update(Scentry.scentryAuthKey, value)(cookieOptions)
}
def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse) {
app.cookies.delete(Scentry.scentryAuthKey)(cookieOptions)
}
}
class SessionAuthStore(app: ScalatraContext) extends ScentryAuthStore {
def get(implicit request: HttpServletRequest, response: HttpServletResponse): String = {
app.session.get(Scentry.scentryAuthKey).map(_.asInstanceOf[String]).orNull
}
def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse) {
app.session(Scentry.scentryAuthKey) = value
}
def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse) {
app.session.invalidate()
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy