0

I am trying to use a doFilter and my web.xml page to force users to login to access any "secured" page.

I found an example here and I have implemented it. I am having a small issue though. When I put the filter definition into web.xml the entire website fails to load. I do believe this is because I do not have the proper class path to the java file which contains the filter. I am showing you my web.xml page next to my project explorer. Auth Filter I am hoping you can help me with the class path needed for the <filter-class> </filter-class>

I am also showing my doFilter method

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    UserBean userBean = (UserBean)((HttpServletRequest)request).getSession().getAttribute("userBean");

    if(userBean == null || !userBean.isSuccessfullLogin()){
        String contextPath = ((HttpServletRequest)request).getContextPath();
        ((HttpServletResponse)response).sendRedirect(contextPath + "/index.xhtml");
    }
    chain.doFilter(request, response);
}

So far the rest of my server works, the website runs but I can not get the filter. Any suggestions are accepted!

Thank you!

Michael Miner
  • 964
  • 2
  • 17
  • 39
  • Your filter is in a `Filter` folder (read `Filter` java package), your `filter-class` definition must be the fully qualified class name (FQN): `Filter.AuthenticationFilter`. Screen-shots of files are a lot less easier to read than the actual files. You should post the content of the file here next time – kolossus Nov 05 '14 at 16:11
  • That is exactly what my FQN in the web.xml is set to. The filter though is never called. – Michael Miner Nov 07 '14 at 21:06

2 Answers2

0

I have not written any filters by now, but usually if you have to define a class in web.xml, it is named as

package.Class

So if your AuthenticationFilter class is in the package "my.filter.package" like so:

package my.filter.package;
public class AuthenticationFilter {...}

the filter class declaration should be

<filter-class>my.filter.package.AuthenticationFilter</filter-class>
ChristophS
  • 598
  • 4
  • 23
0

I did get it to work last night. Filters.AuthenticationFilter works. It was my url pattern that was wrong.

Instead of having my url pattern as /secured/* I needed it to be /faces/secured/*

Michael Miner
  • 964
  • 2
  • 17
  • 39