This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JSF and the fly likes Return to Login Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Return to Login Page" Watch "Return to Login Page" New topic

Return to Login Page

Rich Smith

Joined: Jun 13, 2008
Posts: 2
Hello all, my first post here so hope it's not a simple-obvious one

I'm currently working on a JSF web-application and we want better handle an enforced logout of the user, either by session timeout, or back-end event requiring this.

I have spent today looking at using a Servlet Filter to intercept the request and decide if the user is currently logged on, if not the forward them back to the login page. Unfortunaly I had problems with this, the forward did not seem to be working, the Filter was called, but the next JSF page was displayed! It was as if the Faces Sevlet was being called with the original request, regardless of the forward which I expected call the login page (which might be due to my lack of understanding!)

Anyhow, I had a bit more of a look (including the thread on pre-page initialisation) and wondered if I was approaching this problem in the wrong way. Should I be using a Servlet as a Filter to take the appropriate action on session timeout or if the user is not logged in, or is there a more 'JSF' way to accomplish this such as using a PhaseListener or NavigationHandler?

Any advice would be very much appreciated.

Venkat Sadasivam
Ranch Hand

Joined: May 10, 2008
Posts: 139
To me servlet filter is good approach. I using servlet filter to perform authorization it is working quite well. Please post your servlet filter code.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand. ”<br>
-Martin Fowler
Venkat Sadasivam
Ranch Hand

Joined: May 10, 2008
Posts: 139
My servlet filter code is:

Rich Smith

Joined: Jun 13, 2008
Posts: 2

Thank you for your reply.

My servlet codce looks much like yours, although I was getting RequestDispater from filterConfig.getServletContext().getRequestDispatcher() however if just tried getting it from the request it's still not worked for me.

My Filter is configured by the web.xml file entries, these are placed at the end of web.xml file.

Also, somthing which may or maynot be a factor is that I am using JDeveloper and ADF, and have a file called adf-faces-config.xml which only has a <skin-family> definition.

When I run my application in debug mode I can follow it through until is gets to the forward command so it should be happening, I did wonder if I was specifying the wrong page to forward to, but if I change that to anything else (e.g. "/Login.jsp") but that results in a 500 internal servlet error so I think i have it correct already?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17166

I admit I'm rather prejudiced in the matter, but what about simply using the built-in J2EE standard security system (Container-based Authentication and Authorization)?

Sun designed all that stuff to work together and to minimize the amount of security-related code that the application programmer has to create and debug. And modify when the security system changes.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Return to Login Page
It's not a secret anymore!