
我添加了时间戳,在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"解决方法 对我来说似乎很合理,我可能会把它放在服务器端,给客户端一个“session-ID”并在用户注销时删除会话.在客户端执行此 *** 作意味着如果会话被盗,除非等待超时,否则无法使会话无效. 总结
以上是内存溢出为你收集整理的通过cookie实现更安全的Play Scala框架会话的更好方法全部内容,希望文章能够帮你解决通过cookie实现更安全的Play Scala框架会话的更好方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)