Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a Filter for an IceFaces based web application?
    primarykey
    data
    text
    <p>I am using IceFaces 1.8.2. I want to create a <code>Filter</code> so that people cannot access unauthorized URLs of my application. </p> <p>I attempted to created a <code>Filter</code> like this:</p> <pre><code>public class AuthenticationFilter implements Filter { private FilterConfig config; public void init(FilterConfig filterConfig) throws ServletException { this.config=filterConfig; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req=(HttpServletRequest)request; HttpServletResponse resp=(HttpServletResponse)response; //HttpSession session=req.getSession(true); String pageRequested=req.getRequestURL().toString(); System.out.println("Page Requested="+pageRequested); HttpSession session = req.getSession(false); if (!session.isNew()) { if(ManageCustomerMbeans.AUTH_KEY!=null){ System.out.println(":::::::::::::::::::::::::Login Authenticate"); chain.doFilter(req, resp); } } else { System.out.println("::::::::::::::::::::::::::Not Authenticate"); //Session has expired - redirect to login.jsp } } public void destroy() { } } </code></pre> <p>But the result is that the restricted page still shows if I type in its URL. If I block the other page like this:</p> <pre><code>if (!(pageRequested.contains("Login.jsp")&amp;&amp;session.getAttribute(ManageCustomerMbeans.AUTH_KEY)==null)) { System.out.println("Filter Error!!!"); resp.sendRedirect("./error"); } else { chain.doFilter(request, response); } </code></pre> <p>nothing happend too.</p> <p>How do I properly create a <code>Filter</code> for an IceFaces based web application?</p> <p><em><strong></em>**<em>*</em>**<em>*</em>**<em>*</em>***</strong><em>UPDATE</em><strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>****</strong></p> <p>After correction from Mr. BalusC, i do many correction in my <code>Filter</code> class plus a little tweak because iam using icefaces 1.8.2..this is my correction and it works:</p> <pre><code>public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req=(HttpServletRequest)request; HttpServletResponse resp=(HttpServletResponse)response; HttpSession session = req.getSession(false); String pageRequested=req.getRequestURL().toString(); String resources="resources/"; String xmlhttp="xmlhttp/"; String kaptcha="kaptcha.jpg"; String block="block/"; if(pageRequested.contains("login")||pageRequested.contains(resources) ||pageRequested.contains(block)||pageRequested.contains(xmlhttp) ||pageRequested.contains(kaptcha)||pageRequested.contains("error") ||pageRequested.contains("logout")||pageRequested.contains("lsuccess")){ chain.doFilter(req, resp); }else{ if (session != null &amp;&amp; session.getAttribute(ManageUsersMBeans.AUTH_KEY) != null) { chain.doFilter(req, resp); } else { resp.sendRedirect(req.getContextPath() + "/error"); } } } </code></pre> <p>and in web.xml:</p> <pre><code> &lt;filter&gt; &lt;filter-name&gt;AuthenticationFilter&lt;/filter-name&gt; &lt;filter-class&gt;com.do.tools.util.AuthenticationFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;AuthenticationFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload