<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <!-- Session Configuration -->
    <session-config>
        <session-timeout>120</session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>dashboard.jsf</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>serenity-green</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.FONT_AWESOME</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/primefaces-serenity.taglib.xml</param-value>
    </context-param>
    <!--
        Java Server Faces Application Listeners
    -->
     <listener>
        <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
    </listener>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <filter>
        <filter-name>Character Encoding Filter</filter-name>
        <filter-class>org.primefaces.serenity.filter.CharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Character Encoding Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <mime-mapping>
        <extension>ttf</extension>
        <mime-type>application/font-sfnt</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>woff</extension>
        <mime-type>application/font-woff</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>png</extension>
        <mime-type>image/png</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>woff2</extension>
        <mime-type>application/font-woff2</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>eot</extension>
        <mime-type>application/vnd.ms-fontobject</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>eot?#iefix</extension>
        <mime-type>application/vnd.ms-fontobject</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exosemibold</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exobolditalic</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exomedium</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exoregular</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#fontawesomeregular</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <!--
        Java Authentication and Authorization Services (JAAS)
    -->
    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.jsf</form-login-page>
            <form-error-page>/WEB-INF/error-pages/access.jsf</form-error-page>
        </form-login-config>
    </login-config>
    <!--
        Security Constraints
    -->
    <!-- Menus Dashboard and Top Bar (Profile, Privacy) -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a DASHBOARD grant</web-resource-name>
            <url-pattern>/dashboard.jsf</url-pattern>
        </web-resource-collection>
        <web-resource-collection>
            <web-resource-name>Views only available when user has a PROFILE/PRIVACY/SETTINGS grant</web-resource-name>
            <url-pattern>/app/topbar/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>public.access</role-name>
        </auth-constraint>
    </security-constraint>
    <!-- Menus System (Employee, User) -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a EMPLOYEE grant</web-resource-name>
            <url-pattern>/app/system/employee/main.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>system.employee</role-name>
        </auth-constraint>
    </security-constraint>
     <security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a USER CREATE grant</web-resource-name>
            <url-pattern>/app/system/user/add/main.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>system.user.create</role-name>
        </auth-constraint>
    </security-constraint>
     <security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a USER SETTINGS grant</web-resource-name>
            <url-pattern>/app/system/user/setting/main.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>system.user.admin</role-name>
        </auth-constraint>
    </security-constraint>
     <security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a USER ACCESS grant</web-resource-name>
            <url-pattern>/app/system/user/access/main.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>system.user.access</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a CHANGE LOANS BETWEEN USER grant</web-resource-name>
            <url-pattern>/app/admin/loan/changeOwner.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin.loan.change.owner</role-name>
        </auth-constraint>
    </security-constraint>
    <!-- TBD -->
     <!--security-constraint>
        <web-resource-collection>
            <web-resource-name>Views only available when logged has a logs grant</web-resource-name>
            <url-pattern>.jsf</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name></role-name>
        </auth-constraint>
    </security-constraint-->
    <!--
        Security Roles
    -->
    <!-- Menus Dashboard and Top Bar (Profile, Privacy) -->
    <security-role>
        <role-name>public.access</role-name>
    </security-role>
    <!-- Menus System (Employee, User) -->
    <security-role>
        <role-name>system.employee</role-name>
    </security-role>
     <security-role>
        <role-name>system.user.create</role-name>
    </security-role>
     <security-role>
        <role-name>system.user.admin</role-name>
    </security-role>
     <security-role>
        <role-name>system.user.access</role-name>
    </security-role>
    <security-role>
        <role-name>admin.loan.change.owner</role-name>
    </security-role>
    <!--
        Error Pages
        Code 403 access denied
        code 404 page not found
        code 500 internal server error
    -->
    <error-page>
        <error-code>403</error-code>
        <location>/WEB-INF/error-pages/access.jsf</location>
    </error-page>
    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/error-pages/notfound.jsf</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/error-pages/error.jsf</location>
    </error-page>
    <!--   
        Resource reference, is an object factory for resource JDBC DataSource,
    configured into Tomcat. 
    -->
    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/apcAuth</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>