Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

common URL Mapping for filter

 
Ramkumar Subburaj
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an admin module in my web application and all the admin related jsp pages are in folder "webadmin";

eg: www.test.com/webadmin/home.jsp.


I want to write an authentication filter for admin module and i want to route all request that comes to webadmin/*.jsp to the filter.

How to give the the url patter in the filter config.
doesnt work.

 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is what i am doing in one of my applications to intercept requests. Check this out.

Servlet code


A user token is placed in the session after successful authentication in the servlet. It is removed when the session expires or when the user logs out.
The login page should call the servlet for authetication with an identifiable query. In this example, the link in login.jsp's form would probably look like "http://domain/servlet/auth?cLogin". (see below).

We check for the token first and if it is valid, we don't care about the query string. This setup helps avoid circular calls (especially since we do a forward as opposed to a redirect).
Authentication is valid only when a user token exists in the session. But we let the request proceed if the user is logging in.
If authentication fails and we have a valid configuration, we simply forward the request to the login page again. Otherwise, we throw an exception (we should really never get here ...). The default error page for the application would likely pick that up.

Web.xml

Code snippet for Login Page

Code snippet for Servlet:
- Obviously would be called from a doPost() method that's already extracted the parameters from the request if one of the parameters is "cLogin".



That's it. After you deploy a web application with this filter, all requests will be intercepted and authentication checked.
 
Kuldeep Tewari
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this : <url-pattern>/webadmin/*</url-pattern>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic