QnaList > Groups > Play-Framework > Oct 2012
faq

[Java] [2.0.4] Session()

Hello,
I have a strange behaviours with session
In a class� i put a username in session
public static class UserAction extends Action {
.....
��� ctx.session().put("uid", username);���� 
��� ctx.session().put("type", "etudiants");�� ��� � � ��� 
...
}
I use it to know who is connect the right� ... and show different part of� regarding the type
In admin part i have a button to login like an other people a button send data to this methode
public static Result loginAs() {
��� ��� Logger logger = LoggerFactory.getLogger(MaPage.class);��� ��� 
��� ��� Map mapRequest = request().queryString();��� ��� 
��� ��� String loggin=mapRequest.get("loginAs")[0];
��� ��� 
��� ��� logger.debug("
***********************");
��� ��� logger.debug(session().get("uid")); // here oldname
��� ��� session().clear();
��� ��� session().put("uid", loggin);
��� ��� logger.debug(session().get("uid")); //newname
��� ��� session().put("type", "etudiants");
��� ��� session().put("privilege", "none");� ��� 
��� ��� return redirect(routes.Application.index());
��� }
inside the methode all is ok i read the new name
put after redirect� on .Application.index()
my main scala have yhis
uid:@session.get("uid") user:@session.get("user") type:@session.get("type") privilege:@session.get("privilege")
and is showing the oldname 
i don't understand why the change of the cession context is not persistante ???
thanks in advance
lionel

asked Oct 18 2012 at 00:49

Gadille Lionel's gravatar image



4 Replies for : [Java] [2.0.4] Session()
Salut,
I do very similar things (modify then redirect) without any problems, except that I don't call clear.
Here is what I suggest :
1) Remove the call to session.clear() and see if it has any impact 
2) Use firebug or a similar tool and check the content of the session cookie (mine is named play_session or something like that).
A plus
Le jeudi 18 octobre 2012 09:42:43 UTC+2, Gadille Lionel a �crit�:
- show quoted text -

answered Oct 18 2012 at 08:42

Stephane C's gravatar image


Hello
je suis francais aussi de grenoble on continue en anglais si on trouve un truc ... sa peux aider les non francophone 
�
I try without clear� but withou success
More strange with fire bug i see the good thinks in R�ponsse
other point if at the place of redirect i put somethings like
return ok(views.html.VMaPage.index.render(form(FichePresenceByEtudiant.class),form(FichePresenceByGroup.class)));
I see the good uid / type� on the page
but when i got to another page of the site i switch back on my own admin account (session uid switch back to gadillel and session type to admin)
to use basic auth do you set somme data to session with � ctx.session().put("uid", username);� ?
i'am wodering if usin ctx.cession in context of �� extend Action� is the same things than� cession in controller
Thanks,
R�ponse voir le code source
Content-Length	0
Location	/
Set-Cookie	play2_zenith2=4bce55965401ab8ea7ae1629f0618c7c668f67f2-uid%3Aabboudc%00privilege%3Anone%00tata%3Atoto%00type%3Aetudiants;Path=/;HTTPOnly
Requ�te voir le code source
Accept	text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding	gzip, deflate
Accept-Language	en-US,en;q=0.5
Authorization	Basic Z2FkaWxsZWw6bWVsMjFsaW8=
Connection	keep-alive
Cookie	user=a; type=a; uid=a; org.cups.sid=dcc3bcd02688dee26b696f73c6657255; play2_zenith2=9b3c9371e53c8665c8d34ed726af50f991b88fab-uid%3Agadillel%00privilege%3Aadmin%00tata%3Atoto%00type%3Apersadmin; PLAY_SESSION=7b9a961b269f8b52f57e323e704a9a2c2f07094c-%00username%3Agadillel%5B1%2C2012%5D%3B%00%00___AT%3A0a89d60e11de17bff763cf9a470e96f149d6c03d%00
Host	localhost:9000
Referer	http://localhost:9000/MaPage/
User-Agent	Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0

answered Oct 18 2012 at 09:25

Gadille Lionel's gravatar image


Hello, 
I don't think so....
I wrote such code for testing in a pre-action :
public class AuthenticationCheck extends Action.Simple {
��� @Override
��� public Result call(Context ctx) throws Throwable {
������� SessionAdapter sessionAdapter =� new SessionAdapter(ctx.session());
������� sessionAdapter.setLoggedUserEmail( "[email protected]" );
To write a value in session, I don't have any issue reading the value in the controller using� 
new SessionAdapter( ctx().session()).getLoggedUserEmail(...)
(SessionAdapter class is just a wrapper on the session map for providing typed access to values.)
Honestly, I can't really help you, moreover the values in the cookie seem correct which is a sign that session is properly updated and serialized.... I'd suggest you start a new project with just one controller and try to reproduce the issue with minimal code.
Best
Le jeudi 18 octobre 2012 18:18:43 UTC+2, Gadille Lionel a �crit�:
- show quoted text -

answered Oct 19 2012 at 01:01

Stephane C's gravatar image


excuse me formy post i finally found my stupid error
the page i navigate after setting the usupated user (abboudc) is secured alsos i go to the secured action and is set the uid regarding the username set by the http basic hautentification�� (the old one)
i fixt my erro with 
if (ctx.session().get("uid")==null){��� 
}

answered Oct 19 2012 at 02:05

Gadille Lionel's gravatar image


Related discussions

Tagged

Group Play-framework

asked Oct 18 2012 at 00:49

active Oct 19 2012 at 02:05

posts:5

users:2

Play-framework

©2013 QnaList.com