Filter JSF page to prevent direct access
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Hoe_Chin
Posted On:   Friday, July 3, 2009 06:36 AM

I created a filter to prevent the user by typing the url to access certain page. I have 3 page, the user supposed to access page2 or page3 only through page1. First page required the user enter username, den go to page2 and so on. I have a managed bean user scoped session.This is my filter method. The problem is that when i never enter the username this line (req.getAttribute("user") == null) wont give me null but something value like this bean.User@6ed322. Anyone can help correct me where goes wrong ? public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp    More>>

I created a filter to prevent the user by typing the url to access certain page. I have 3 page, the user supposed to access page2 or page3 only through page1. First page required the user enter username, den go to page2 and so on. I have a managed bean user scoped session.This is my filter method. The problem is that when i never enter the username this line (req.getAttribute("user") == null) wont give me null but something value like this bean.User@6ed322. Anyone can help correct me where goes wrong ?





			
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; HttpSession httpSession = req.getSession(false); String pageRequested = req.getRequestURI().toString(); if (httpSession == null) { resp.sendRedirect("Page1.faces"); } else if (httpSession.getAttribute("user") != null && ((User) httpSession.getAttribute("user")).getUsername() == null && !pageRequested.contains("Page1.faces")) { resp.sendRedirect("Page1.faces"); } else { chain.doFilter(request, response); }}
   <<Less
About | Sitemap | Contact