I am using a Servlet Filter in my JSF application. I have three groups of Web pages in my application, and I want to check Authentication for these pages in my Servlet Filter:
my Folders
/Admin/ *.xhtml
/Supervisor/*.xhtml
/Employee/*.xhtml
and I am writing web.xml
like
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.ems.admin.servlet.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/Employee/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/Admin/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/Supervisor/*</url-pattern>
</filter-mapping>
but requests like
http://localhost:8080/EMS2/faces/Html/Admin/Upload.xhtml
are not entering into Filter.
I have to provide security to these 3 folders.
How to solve this problem ?
This question is related to
servlets
servlet-filters
url-pattern
In case you are using the annotation method for filter definition (as opposed to defining them in the web.xml
), you can do so by just putting an array of mappings in the @WebFilter
annotation:
/**
* Filter implementation class LoginFilter
*/
@WebFilter(urlPatterns = { "/faces/Html/Employee","/faces/Html/Admin", "/faces/Html/Supervisor"})
public class LoginFilter implements Filter {
...
And just as an FYI, this same thing works for servlets using the servlet annotation too:
/**
* Servlet implementation class LoginServlet
*/
@WebServlet({"/faces/Html/Employee", "/faces/Html/Admin", "/faces/Html/Supervisor"})
public class LoginServlet extends HttpServlet {
...
Source: Stackoverflow.com