This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Filter to check if user is logged in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Filter to check if user is logged in" Watch "Filter to check if user is logged in" New topic
Author

Filter to check if user is logged in

Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
hi,

I wrote a simple request filter to check if the user is logged in before he can access any JSP page. I mapped the filter to the action servlet. Now the problem is that the filter works even when the login action is called. So it keeps directing the user to the login page. How do I prevent the filter from acting when the action is a login action ?

My filter code is as follows.

Claude Forkner
Greenhorn

Joined: Feb 19, 2006
Posts: 24
Hey dude. The problem is that your mapping for your filter is probably not optimally setup. Right now it sounds like you have the mapping set to run the filter on every page/action. For something like a login action, you probably want to make that a "public" action which can be run without the filter being run.

Make sense?

Post your mapping for the filter.
Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
That makes sense, but how do you map the actions selectively ?
I'm mapping to the action servlet itself.
My filter mapping is as follows.

<filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>

Thanks
Devi
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You have access to the request object in your filter code. Use the getRequestURL method to see if the URL in the request ends with "login.do". If it does, allow the request to pass without a valid login.


Merrill
Consultant, Sima Solutions
Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
Thanks for that tip. It worked fine.

-Devi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Filter to check if user is logged in
 
Similar Threads
JSF Filter prevent direct access certain page
if a user enter a website without entering the authentication page how can i redirect
Filter Problem
How to know login & logout status of user
Problem with session timeout