Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter to check if user is logged in

 
Sreedevi Vinod
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sreedevi Vinod
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that tip. It worked fine.

-Devi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic