0

I have implemented a JAAS form based security for my site, and it is suppose to protect all the .xhtml files inside a folder named "secured" but it does not until that page is refreshed.

On first visit the url does not name the file either and just shows"faces/catalog.xhtml" that was the previous unprotected page then if i hit refresh it works then.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/bookstore.taglib.xml</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>faces/catalog.xhtml</welcome-file>
</welcome-file-list>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>customer</web-resource-name>
        <description/>
        <url-pattern>/faces/secured/checkout.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>customer</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>myjdbc</realm-name>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/login_error.xhtml</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <role-name>customer</role-name>
</security-role>

oh also calling the secured page like this:

public String buy() {

    if (getNumberOfItems() < 1) {
        message(null, "CartEmpty");

        return (null);
    } else {
        return ("/secured/checkout");
    }
}

Trying to figure this out for some time now, thanks for the help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
foreverNewb
  • 31
  • 1
  • 4
  • Start by removing the `/faces/*` mapping and use `*.xhtml` instead. Refer to http://stackoverflow.com/q/3008395/1065197 – Luiggi Mendoza Oct 27 '13 at 17:59
  • 2
    possible duplicate of [Problem with JSF forwarding and security constraint](http://stackoverflow.com/questions/3421498/problem-with-jsf-forwarding-and-security-constraint) Explanation is simple: security constraints are only checked on URLs of incoming requests, not on paths of templates used for response content. In other words, don't navigate by POST, but by GET. – BalusC Oct 27 '13 at 18:39
  • @balusc thanks, its working now finally with h:link. – foreverNewb Oct 28 '13 at 02:53

0 Answers0