大佬教程收集整理的这篇文章主要介绍了通过cookie实现更安全的Play Scala框架会话的更好方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我添加了时间戳,在1小时后每隔5分钟使会话失效,如果用户仍在使用该站点,则更新时间戳,以便cookie签名滚动并过期.
我对scala和play框架都很陌生,所以任何建议或更好的方法来实现同样的东西将非常感激.
Trait Secured { def withAuth(f: => String => request[AnyContent] => Result) = { Security.Authenticated(username,onUnauthorized) { user => Action(request => { val sessionRolloverPeriod = 300 val sessionExpiryTime = 3600 val sessionCreationTime: Int = request.session("ts").toInt val currentTime = System.currentTimeMillis() / 1000L if(currentTime <= (sessionCreationTime + sessionExpiryTimE)) { if(currentTime >= (sessionCreationTime + sessionRolloverPeriod)) { f(user)(request).withSession(request.session + ("ts" -> (System.currentTimeMillis() / 1000L).toString)) } else { f(user)(request) } } else { Results.Redirect(routes.Auth.login()).withNewSession } } ) } } }
每5分钟生产一次饼干:
The cookies produced every 5min: Cookie:PS="a6bdf9df798c24a8836c2b2222ec1ea4a4251f301-username=admin&ts=1381180064" Cookie:PS="D7edg7df709b54B1537c2b9862dc2eaff40001c90-username=admin&ts=1381180380"
以上是大佬教程为你收集整理的通过cookie实现更安全的Play Scala框架会话的更好方法全部内容,希望文章能够帮你解决通过cookie实现更安全的Play Scala框架会话的更好方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。