Added a simple sysout statement in the doFilter method.
However for some reason I do not see the Filter being invoked.
Any idea what am I missing here? Is there any more configuration that need to be specified?
Can you please share the code and some information about your application?
Is it a plain Java application or are you using perhaps Spring Boot with Spring Security?
There might be another filter that runs before yours and blocks the request (e.g. a security filter)
Looking at the linked docs, my understanding is that you are defining a Filter mapped to /connect URL, and then you are doing a post to /connect/login to authenticate the user.
But you also said I just want to add login before the user is able to access any page, so I suppose you are also doing a redirect to the login page for unauthenticated users.
Can you please share your code, so we can get a better understanding of the actual solution and try to provide some help?
BTW, it seems to me that the WebFilter URL pattern might be incorrect in the docs; I expect it to be /connect/* to be able to cover also /connect/login
@Override
public void init(FilterConfig filterConfig) throws ServletException { }
@Override
public void destroy() { }
}
I have defined the filter using the mapping based on the link.
Eventually yes, I do want the user to be redirected to the login page for unauthenticated users.
I am not trying access the Filter directly. Currently, I am only looking to check if the Filter is invoked when I make a request or not. This I verify if the “In CustomWebFilter” is printed. But I do not see it.
Correct. Though I am not making a call to connect. I am making a call to one of the Views / Pages. eg. http://localhost:port/award-details. And the filter is not invoked
This probably explains because the filter is not invoked.
Your filter is mapped to be executed only on the /connect path.
If you want to execute if for every request, you should set the URL mapping to /*,
e.g. @WebFilter("/*")
Ok, one difference is that I have been running the project as a Spring Boot Application. i.e. Running Application.java and Not deployed on a web server.
Could that be an issue?
Will share the code shortly.