• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Filter URL mappings

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My application is running on weblogic server 1 0.3.4 and iam using jsf 2.0.

I have a requirement where in I have to implement a technique to validate the user before he starts accessing the application. Also, I need to check if a valid user has logged in whenever he accesses any page in the application. If the user has not logged in, then I should redirect the user to the login screen.

So I am using a Login Authentication filter to do this. I have placed the login related xhtml files in a folder /login/. Once the user is authenticated, then he is directed to application pages which are placed under /pages/... folder.

My filter mapping is given below:

<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.validate.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>faces/pages/*</url-pattern>
</filter-mapping>

Scenario 1:
When the user access the login page directly from the browser, the login.xhtml page loads correctly. On click of login button in login.xhtml, the user is authenticated and transfered to application specific pages under /pages/welcomeuser.xhmtl. The filter is not invoked on click of login button in login.xhtml at this point in time, because the mapped url for filter is faces/pages/*. This scenario works fine.

Scenario 2:
Let's assume the user directly types the URL http://localhost:8020/pages/welcomeuser.xhtml. the expected behaviour should that the user should redirected to /login.login.xhtml page as the user is not validated yet.

In this case, the doFilter () method in LoginFilter is invoked. Inside this method, I am checking if the user object exists or not. If not exists, then I am redirecting the user to /login/login.xhtml. What happens now is, since I am doing a redirect to a page whose URL pattern matches with URL pattern of filter, it calls the doFilter() again and again and this goes into a indefinite loop.

Please let me know how to overcome this.

The do filter method is given below:

<code>
public void doFilter(ServletRequest request, ServletResponse response,FilterChain filterChain) throws IOException,ServletException {

HttpServletResponse httpServeltResponse = (HttpServletResponse) response;

String email = session.setAttribute("loginuseremail");
if(email == null)
{
httpServeltResponse.sendRedirect(policyURL);
}
else
{
try {
chain.doFilter(request, response);
} catch (Throwable t) {

t.printStackTrace();
}
}
}
</code>

Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"forum groupuser" please check your private messages for an important administrative matter. Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic