GeeCON Prague 2014*
The moose likes Servlets and the fly likes common URL Mapping for filter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "common URL Mapping for filter" Watch "common URL Mapping for filter" New topic
Author

common URL Mapping for filter

Ramkumar Subburaj
Ranch Hand

Joined: Sep 07, 2007
Posts: 83
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.


SCJP 1.5, SCWCD 1.4.
Hanging between Web Services and EJB
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
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.

Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Kuldeep Tewari
Ranch Hand

Joined: May 22, 2006
Posts: 35
try this : <url-pattern>/webadmin/*</url-pattern>
 
GeeCON Prague 2014
 
subject: common URL Mapping for filter