I have configured my application to use OmniFaces's Extensionless URLs feature, but now that I enabled security in my web.xml, the extensionless requests do not get caught by the <security-constraint>.
web.xml
<!-- JSF configuration -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<!-- OmniFaces configuration -->
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/*.xhtml</param-value>
</context-param>
<!-- Servlets and filters. -->
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- Welcome files, error pages and mime types. -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- Security constraints -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Allowed resources</web-resource-name>
<url-pattern>/javax.faces.resource/*</url-pattern>
</web-resource-collection>
</security-constraint>
<security-constraint>
<display-name>SSL transport</display-name>
<web-resource-collection>
<web-resource-name>Secure Area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ADMINISTRATOR</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- Security roles -->
<security-role>
<role-name>ADMINISTRATOR</role-name>
</security-role>
<!-- Login config -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>myRealm</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login.xhtml</form-error-page>
</form-login-config>
</login-config>
login.xhtml
<h:form>
<h:panelGrid columns="1">
<h:outputText value="Username:" />
<h:inputText id="username" required="true"
value="#{appSession.loginUsername}"
requiredMessage="Username is required" />
<h:message for="username" />
<hr />
<h:outputText value="Password:" />
<h:inputSecret id="password" required="true"
value="#{appSession.loginPassword}"
requiredMessage="Password is required" />
<h:message for="password" />
<h:commandButton value="Login" action="#{appSession.login}" />
</h:panelGrid>
<h:messages globalOnly="true" showDetail="false" />
</h:form>
AppSession.java
@SessionScoped
@ManagedBean
public class AppSession {
private String loginUsername;
private String loginPassword;
public AppSession() { }
public String login() {
try {
Faces.login(loginUsername, loginPassword);
return "index.xhtml?faces-redirect=true";
} catch (ServletException e) {
e.printStackTrace();
return "login.xhtml";
}
}
public void logout() throws IOException {
Faces.invalidateSession();
Faces.redirect("index.xhtml");
}
//Getters and setters
}
So, if I browse to index.xhtml, it gets redirected correctly to login. However if I browse to index, there is no redirect and the browser is allowed to download the content from index. I know that this is exactly what is specified in web.xml by <url-pattern>*.xhtml</url-pattern>, but how can I configure the application, so that extensionless URLs get also restricted by login?
If I try this with <url-pattern>/*</url-pattern> under <security-constraint>, it gets redirected successfully, however my login form does not work in this case. I have to do programmatic login with JSF, since I want to reuse the credentials for webservices. Any ideas so I get a valid configuration?
I am using OmniFaces 2.0, Mojarra 2.2.7 on GlassFish 4.1.