Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:42:00+00:00 2026-06-13T09:42:00+00:00

I have read numerous examples though I seem to have an ‘exact’ copy of

  • 0

I have read numerous examples though I seem to have an ‘exact’ copy of them, so I cannot figure out why my filter will execute when I navigate to /login instead of /restricted/*.
I have tried both annotations (as in the example below) and XML to define the WebFilter.

The Webfilter

@WebFilter(filterName = "AuthenticationFilter", servletNames = { "Faces Servlet" }, urlPatterns = { "/restricted/*" } )
public class AuthenticationFilter implements Filter {
    @Inject
    private SessionManager sessionManager;

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
        System.out.println("Active AuthenticationFilter");
        if (sessionManager.getUser() == null) {
            ((HttpServletResponse) response).sendRedirect("/login");
        }
        else {
            chain.doFilter(request, response);
        }
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void destroy() {
    }
}

web.xml

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>   
<filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
    <async-supported>true</async-supported>
</filter>
<filter-mapping> 
    <filter-name>Pretty Filter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher>
    <dispatcher>ASYNC</dispatcher>
</filter-mapping>
<filter>
    <filter-name>NoCacheFilter</filter-name>
    <filter-class>filter.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>NoCacheFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
    <filter-name>AuthenticationFilter</filter-name>
    <filter-class>filter.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>AuthenticationFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/restricted/*</url-pattern>
</filter-mapping>

Note

Even though the filter is defined in both files, I can assure I am not using both notations at the same time. For the sake of testing and reviewing I however did post them both.

I am new to the use of webfilters, and could not find much about using multiple filters. But what I did read, you can use multiple and they will execute in the order you defined them in web.xml.

Question

Does anyone have a clue as to why my filter will execute on pages as /login too?
The app is running on Glassfish 3.1.2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:42:01+00:00Added an answer on June 13, 2026 at 9:42 am

    The <filter-mapping> matching conditions are not inclusive, they are exclusive.

    With the following mapping

    <filter-mapping>
        <filter-name>AuthenticationFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/restricted/*</url-pattern>
    </filter-mapping>
    

    you’re basically instructing that the filter should be invoked whenever the FacesServlet is to be invoked or whenever the URL pattern matches /restricted/*.

    This is not an “and” condition as you seemed to expect. Just remove the <servlet-name> entry.

    The proper @WebFilter declaration would then be

    @WebFilter("/restricted/*")
    

    assuming that you don’t need a <filter-mapping> (if the order is irrelevant, for example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read various posts in stackoverflow and I am trying to figure out
I have read numerous people with this question and have tried numerous strategies. However,
I have read numerous times that enforcing const-correctness in your C or C++ code
I have tried to do this without bothering the experts and have read numerous
I have read numerous posts, spent hours going over the documents at cakephp.org and
There are numerous discussions here that have addressed issues that seem related to this
I have read numerous time that learning a language such as Haskell, Lisp or
I have read I should encode my ampersands as &amp; in HTML. However numerous
I have read the README on the RGraphviz page and have looked at numerous
I have read numerous posts and articles about the element in client endpoints on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.