<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"
    metadata-complete="true">
    <!-- 
        These settings save 23 seconds on Tomcat startup (Scan jars step is down from 30s to 7 s):
        
        Setting metadata-complete="true" disables scanning your web application and its libraries for classes that use annotations to define
        components of a web application (Servlets etc.)
        
        The <absolute-ordering> element specifies which web fragment JARs (according to the names in their WEB-INF/web-fragment.xml files)
        have to be scanned for SCIs, fragments and annotations. An empty <absolute-ordering/> element configures that none are to be scanned.
        
        We can further exclude most of the jars from other types of scanning with <JarScanFilter> element in context.xml.
    -->
    <absolute-ordering/>

    <display-name>Arkcase</display-name>

    <!--
		SPRING ROOT WEB APPLICATION CONTEXT.  Spring MVC does require us to have a root application
		context with service beans, and a web application context with controllers.  We can't have
		everything in one big application context.  That means controllers have to be defined in
		spring-web-*.xml files, and service beans in spring-library-*.xml files.
	-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/spring/spring-library-configuration.xml,
            classpath*:/spring/spring-library-*.xml,
            classpath*:/spring/spring-extension-library-*.xml,
            classpath*:/spring/spring-custom-library-*.xml
            classpath:/spring/spring-security-config.xml,
            file:${user.home}/.arkcase/acm/spring-security/spring-security-config-*.xml
        </param-value>
    </context-param>

    <!-- The default Spring authentication profile. To use a different profile pass it as system property ex. -Dspring.profiles.active="ssoSaml" -->
    <context-param>
        <param-name>spring.profiles.default</param-name>
        <param-value>ldap</param-value>
    </context-param>

    <context-param>
        <param-name>contextInitializerClasses</param-name>
        <param-value>com.armedia.acm.AcmApplicationContextInitializer</param-value>
    </context-param>

    <filter>
        <filter-name>hazelcast-filter</filter-name>
        <filter-class>com.hazelcast.web.spring.SpringAwareWebFilter</filter-class>
        <!--
            Name of the distributed map storing
            your web session objects
        -->
        <init-param>
            <param-name>map-name</param-name>
            <param-value>sessions-map</param-value>
        </init-param>
        <!--
            How is your load-balancer configured?
            stick-session means all requests of a session
            is routed to the node where the session is first created.
            This is excellent for performance.
            If sticky-session is set to false, when a session is updated
            on a node, entry for this session on all other nodes is invalidated.
            You have to know how your load-balancer is configured before
            setting this parameter. Default is true.
        -->
        <init-param>
            <param-name>sticky-session</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Name of session id cookie
        -->
        <init-param>
            <param-name>cookie-name</param-name>
            <param-value>DSESSIONID</param-value>
        </init-param>
        <!--
            Should cookie only be sent using a secure protocol? Default is false.
        -->
        <init-param>
            <param-name>cookie-secure</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Should HttpOnly attribute be set on cookie ? Default is false.
        -->
        <init-param>
            <param-name>cookie-http-only</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Are you debugging? Default is false.
        -->
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>

        <init-param>
            <param-name>instance-name</param-name>
            <param-value>acmHazelcastInstance</param-value>
        </init-param>

        <!--
            Do you want to connect as a client to an existing cluster?
            Default is false.
        -->
        <init-param>
            <param-name>use-client</param-name>
            <param-value>false</param-value>
        </init-param>
        <!--
            Client configuration location;
                * as servlet resource OR
                * as classpath resource OR
                * as URL
            Default is null.
        -->
        <!--
            Do you want to shutdown HazelcastInstance during
            web application undeploy process?
            Default is true.
        -->
        <init-param>
            <param-name>shutdown-on-destroy</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>hazelcast-filter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <listener>
        <listener-class>com.hazelcast.web.SessionListener</listener-class>
    </listener>

    <filter>
        <filter-name>requestdumper</filter-name>
        <filter-class>
            org.apache.catalina.filters.RequestDumperFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>requestdumper</filter-name>
        <url-pattern>/onlyoffice/*</url-pattern>
    </filter-mapping>

    <!-- Sets RequestId, User Id, Remote address in org.slfj.MDC variables -->
    <filter>
        <filter-name>RequestMDCFilter</filter-name>
        <filter-class>com.armedia.acm.web.api.RequestMDCFilter</filter-class>
        <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
        <filter-name>RequestMDCFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>miltonFilter</filter-name>
        <filter-class>io.milton.servlet.SpringMiltonFilter</filter-class>
        <init-param>
            <param-name>milton.exclude.paths</param-name>
            <param-value>/static,/templates</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:miltonContext.xml</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>miltonFilter</filter-name>
        <url-pattern>/webdav/*</url-pattern>
    </filter-mapping>

    <!--
		SPRING SECURITY
	-->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        <async-supported>true</async-supported>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher><!-- This is needed in order spring security to be applied, forward request to be working-->
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <!-- this may be necessary for Tomcat 7 deployments -->
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/j_spring_security_check</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/logout</url-pattern>
    </servlet-mapping>

    <!--
		SPRING MVC. This servlet MUST be named "Spring MVC Dispatcher Servlet" or else the view resolver will not  be
		able to find JSP files.
	-->
    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/spring/appServlet/servlet-context.xml,
                classpath*:spring/spring-web-configuration.xml,
                classpath*:spring/spring-web-*.xml
                classpath*:spring/spring-extension-web-*.xml
                classpath*:spring/spring-custom-web-*.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- Fix for the 'java.lang.NoClassDefFoundError: com/github/jaiimageio/stream/RawImageInputStream' -->
    <listener>
        <display-name>ImageIO service provider loader/unloader</display-name>
        <listener-class>com.twelvemonkeys.servlet.image.IIOProviderContextListener</listener-class>
    </listener>

    <!--
        FORCE UTF8 ENCODING
    -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>
