Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Sessionauthenticator removes added Values from Play Session #292

Merged
merged 1 commit into from
Mar 3, 2015
Merged

Sessionauthenticator removes added Values from Play Session #292

merged 1 commit into from
Mar 3, 2015

Conversation

akkie
Copy link
Contributor

@akkie akkie commented Mar 3, 2015

Hi,
We currently have the problem that if we use the SessionAuthenticator as authenticator we cannot add additional values in the Session anymore. These values will be removed during the update/touch process of the sessionauthenticator.

package com.springer.nemo.identity.controllers

import com.mohiva.play.silhouette.api
import com.mohiva.play.silhouette.api.{ LoginInfo, Silhouette }
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import com.mohiva.play.silhouette.test.{ FakeEnvironment, FakeRequestWithAuthenticator }
import org.scalatest.{ Matchers, FlatSpec }
import org.scalatest.concurrent.{ AsyncAssertions, ScalaFutures }
import play.api.Play
import play.api.test.{ FakeApplication, FakeRequest }
import play.api.test.Helpers._

case class User(loginInfo: LoginInfo) extends api.Identity

class SilhouetteController extends Silhouette[User, SessionAuthenticator] {
  val loginInfo = new LoginInfo("foo", "bar")
  val identity = new User(loginInfo)

  val env = FakeEnvironment[User, SessionAuthenticator](Seq(loginInfo -> identity))

  val request = FakeRequest().withAuthenticator(loginInfo)(env)

  def testAttachToSession = UserAwareAction { implicit request =>
    Ok.withSession(("key" -> "valueX"))
  }
}

class SilhouetteSpec extends FlatSpec with AsyncAssertions with ScalaFutures with Matchers {

  "UserAwareAction" should "allow custom attributes in session" in {
    Play.start(FakeApplication())
    val controller = new SilhouetteController
    val request = controller.request
    whenReady(controller.testAttachToSession(request)) { result =>
      result.header.status should be(OK)
      result.session(request).get("key") should be(defined)
      result.session(request).get("key").get should be("valueX")

    }
    Play.stop()
  }
}

This feature would be really nice.

P.s.
Really nice project. Helped us a lot. Thanks for all your work.

@akkie akkie added the bug label Feb 25, 2015
@akkie akkie added this to the 2.0 milestone Feb 25, 2015
@akkie akkie self-assigned this Feb 25, 2015
@akkie
Copy link
Contributor

akkie commented Feb 25, 2015

Yes, definitely a bug. Thanks for reporting this.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 98.86% when pulling fed1046 on akkie:session-authenticator-bug292 into 2e4ca8b on mohiva:master.

akkie added a commit that referenced this pull request Mar 3, 2015
Sessionauthenticator removes added Values from Play Session
@akkie akkie merged commit 277a400 into mohiva:master Mar 3, 2015
@akkie
Copy link
Contributor

akkie commented Mar 3, 2015

Note that you must write addingToSession instead of withSession, because the later one creates a new session and the former one adds a new value to an existing session.

@akkie akkie deleted the session-authenticator-bug292 branch March 3, 2015 19:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants