Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to invalidate existing session and create new session in jsf?

 
saivenkat venkatesan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am creating a session Map in PageCodeBase.java class like this

sessionScope = (Map) facesContext.getApplication().createValueBinding("#{sessionScope}").getValue(facesContext);

I have Logon.java which extends the PageCodeBase class

for security reason,whenever the user logon to the application i want to invalidate the existing session and create a new session in my managed bean class Logon.java.

how can i do this ? please help me.
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it's not you who is creating that code.
I believe that code is being created by IBM's RAD.

The simplistic way of acheiving this is to wrap a Filter around the Faces servlet. Check for the URL, and if it's login page, then invalidate the existing session and create a new session.
 
Chris Schalk
author
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a generic sense here is how to invalidate a session from Faces:

ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
HttpSession session = (HttpSession)ectx.getSession(false);
session.invalidate();
 
saivenkat venkatesan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks chris,

I invalidated my session like this in Logon.java

session = (HttpSession)facesContext.getExternalContext().getSession(false);
session.invalidate();

but how can i create a new session.i put the follwing line after invalidating but it is failing,


sessionScope = (Map) facesContext.getApplication().createValueBinding("#{sessionScope}").getValue(facesContext);

can you help me.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by saivenkat venkatesan:
but how can i create a new session.i put the follwing line after invalidating but it is failing,


Well, how do we create a new session in JSP or Servlet?
[ September 13, 2006: Message edited by: Adeel Ansari ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic