File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Simple login filter causing issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Simple login filter causing issues" Watch "Simple login filter causing issues" New topic

Simple login filter causing issues

Syed Mahdi
Ranch Hand

Joined: Aug 27, 2004
Posts: 45
Hi Guys,

I am working on a simple filter: To keep my webapp only accessible to logged in users. for that i designed a simple filter which is not working as it should. I need some ideas on how to refine it more so its more robust. And the reason why i designed it doesnt really gets acheieved some how:

Here is my code:

for struts config.xml:

my do filter method in my filter class:

What this does is It checks for a loginbean and if it exists that means the persons logged in. Now, when the user comes in the first time this filter also runs at that point he doesnt have any session nor the bean in the session. so i just route him to login.jsp, If there is a session means that he is probably trying to log in and will not hve a login bean. this is giving me problems. Is there a way that I can only run this filter after the user has logged in. Also, when i try to access a url from browser after logging out, it doesnot give me any issues, it loads up the page, In log out i have removed the login bean and invalidated the session. There is no way i can remove or destory the sesssion at logout. so when it comes to the filter the session is still there and calls the login action class where it is designed to throw the user with errors on the login page but it doesnt.

Can any one see what i am doing wrong or how to make it more robust to not let any user access any urls without logging in.

Thanks in advance..
David Newton

Joined: Sep 29, 2008
Posts: 12617

I think you mean web.xml.

I find the code completely illegible--could you format it properly please? Thanks.
I agree. Here's the link:
subject: Simple login filter causing issues
It's not a secret anymore!