If you deploy a JSF application in WildFly 8, you can omit to define the JSF serlvet mapping. In this case three default mappings will be active out of the box.
Tested on WildFly 8.0.0.CR1 and JBoss EAP 6.2.0.GA
This behavior is not mentioned in the JSF 2.1 spec. But it explicitly allows implementations to use proprietary means to invoke the JSF lifecycle.
In addition to FacesServlet, JSF implementations may support other ways to invoke the JavaServer Faces request processing lifecycle, but applications that rely on these mechanisms will not be portable.
This default mapping can be problematic as it provides several path to access resources within your web application. Especially if you use security constraints to protect parts of your application. For instance if you restrict access to <context-root>/secure/* using a security constraint in your web.xml, web resources can still be accessed via <context-root>/faces/.
To prevent this issue it is always recommendable to define a servlet mapping for your JSF based application. If you define a serlvet mapping for JSF, WildFly will stop serving data for the default mappings. Just pick your preferred mapping and define it in the web.xml file as shown below:
<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> </code>
WildFly will stop serving files via its defaults mappings. Of course if you specify more than one mapping, you will have to add security constraints accordingly.
This maven project provides a minimalistic application that demonstrates this issue. The index.xhtml file in the /src/main/webapp/ directory is a JSF file. We restrict access to this file with a security constraint section in the web.xml file without any explict servlet mapping of the Faces Servlet:
<security-constraint> <web-resource-collection> <web-resource-name>secured index</web-resource-name> <url-pattern>/index.jsf</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> </security-constraint> <security-role> <role-name>admin</role-name> </security-role>
If you try to access the file by using the three patterns of the default mapping, you get the following responses:
- GET (http://localhost:8080/secure-jsf/index.jsf) → HTTP 403 Forbidden
- GET (http://localhost:8080/secure-jsf/faces/index.xhtml) → HTTP 200 Ok
- GET (http://localhost:8080/secure-jsf/index.faces) → HTTP 200 Ok
In this case only the request http://localhost:8080/secure-jsf/index.jsf is restricted by the security constraint. All other default mappings are not secured. To prevent this security issue you have to configure additional security constraints for all default mappings or to configure an explicit mapping for the JSF servlet in order to disable the default mappings.