<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
         version="2.5">

  <filter>
    <filter-name>request-capture</filter-name>
    <filter-class>org.uberfire.ext.security.server.SecurityIntegrationFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>request-capture</filter-name>
    <url-pattern>*</url-pattern>
  </filter-mapping>

  <filter>
    <filter-name>Avoid Host Page Cache</filter-name>
    <filter-class>org.uberfire.ext.security.server.CacheHeadersFilter</filter-class>
  </filter>
  
  <filter-mapping>
    <filter-name>Avoid Host Page Cache</filter-name>
    <url-pattern>/dashbuilder.html</url-pattern>
  </filter-mapping>

  <filter>
    <filter-name>Host Page Patch</filter-name>
    <filter-class>org.jboss.errai.security.server.servlet.UserHostPageFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>Host Page Patch</filter-name>
    <url-pattern>/dashbuilder.html</url-pattern>
  </filter-mapping>

  <filter>
    <filter-name>GWT Locale Filter</filter-name>
    <filter-class>org.uberfire.server.locale.GWTLocaleHeaderFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>GWT Locale Filter</filter-name>
    <url-pattern>/dashbuilder.html</url-pattern>
  </filter-mapping>
  
  <filter>
    <filter-name>UberFire Security Headers Filter</filter-name>
    <filter-class>org.uberfire.ext.security.server.SecureHeadersFilter</filter-class>
    <init-param>
      <param-name>x-frame-options</param-name>
      <param-value>SAMEORIGIN</param-value>
    </init-param>
    <init-param>
      <param-name>x-xss-protection-enable</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>x-xss-protection-block</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>UberFire Security Headers Filter</filter-name>
    <url-pattern>*</url-pattern>
  </filter-mapping>

  <servlet>
    <servlet-name>LoginRedirectServlet</servlet-name>
    <servlet-class>org.uberfire.ext.security.server.LoginRedirectServlet</servlet-class>
    <init-param>
      <param-name>display-after-login</param-name>
      <param-value>/dashbuilder.html</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>LoginRedirectServlet</servlet-name>
    <url-pattern>/login</url-pattern>
  </servlet-mapping>

  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/login.jsp?message=Login failed. Please try again.</form-error-page>
    </form-login-config>
  </login-config>
  
  <servlet>
    <servlet-name>ErraiServlet</servlet-name>
    <servlet-class>org.jboss.errai.bus.server.servlet.DefaultBlockingServlet</servlet-class>

    <init-param>
      <param-name>service-locator</param-name>
      <param-value>org.jboss.errai.cdi.server.CDIServiceLocator</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>ErraiServlet</servlet-name>
    <url-pattern>*.erraiBus</url-pattern>
  </servlet-mapping>

  <servlet>
    <servlet-name>UberfireFileUploadServlet</servlet-name>
    <servlet-class>org.uberfire.server.FileUploadServlet</servlet-class>
    <init-param>
      <param-name>includes-path</param-name>
      <param-value>git://**,default://**</param-value>
    </init-param>
    <init-param>
      <param-name>excludes-path</param-name>
      <param-value>file://**</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>UberfireFileUploadServlet</servlet-name>
    <url-pattern>/org.dashbuilder.DashbuilderShowcase/defaulteditor/upload/*</url-pattern>
  </servlet-mapping>

  <servlet>
    <servlet-name>UberfireFileDownloadServlet</servlet-name>
    <servlet-class>org.uberfire.server.FileDownloadServlet</servlet-class>
    <init-param>
      <param-name>includes-path</param-name>
      <param-value>git://**,default://**</param-value>
    </init-param>
    <init-param>
      <param-name>excludes-path</param-name>
      <param-value>file://**</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>UberfireFileDownloadServlet</servlet-name>
    <url-pattern>/org.dashbuilder.DashbuilderShowcase/defaulteditor/download/*</url-pattern>
  </servlet-mapping>

  <!-- Security roles -->

  <security-role>
    <description>Administrator - Manages application configuration and creates dashboards</description>
    <role-name>admin</role-name>
  </security-role>

  <security-role>
    <description>User - Consumes existing dashboards</description>
    <role-name>user</role-name>
  </security-role>

  <!-- Open resources for login page. -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>openResources</web-resource-name>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/patternfly/*</url-pattern>
    </web-resource-collection>
  </security-constraint>

  <!-- Default security constraints.-->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>default</web-resource-name>
      <url-pattern>/dashbuilder.html</url-pattern>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/*</url-pattern>
      <url-pattern>*.erraiBus</url-pattern>
      <url-pattern>/plugins/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
      <role-name>user</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- Upload/Download servlet security constraints.-->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>download</web-resource-name>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/archive</url-pattern>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/defaulteditor/upload/*</url-pattern>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/defaulteditor/download/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
      <role-name>user</role-name>
    </auth-constraint>
  </security-constraint>

  <!-- public resources -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>public</web-resource-name>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/css/*</url-pattern>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/fonts/*</url-pattern>
      <url-pattern>/org.dashbuilder.DashbuilderShowcase/img/*</url-pattern>
    </web-resource-collection>
  </security-constraint>

  <error-page>
    <error-code>403</error-code>
    <location>/not_authorized.jsp</location>
  </error-page>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
</web-app>