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

<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="urn:jboss:shared-session-config:2.0"
            xmlns="urn:jboss:shared-session-config:2.0"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            version="2.0">

    <!-- Root element -->
    <xsd:element name="shared-session-config" type="sharedSessionType">
        <xsd:annotation>
            <xsd:documentation>
                Root element for the shared session config. If this is present in the root of
                an ear then all war's deployed in the ear will share a single session manager.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:element>

    <xsd:complexType name="sharedSessionType">
        <xsd:sequence>
            <xsd:element name="distributable" type="empty" minOccurs="0" maxOccurs="1"/>
            <xsd:element name="max-active-sessions" type="xsd:string" minOccurs="0" maxOccurs="1"/>
            <xsd:element name="session-config" type="session-configType" minOccurs="0" maxOccurs="1"/>
            <xsd:element name="replication-config" type="replication-configType" minOccurs="0" maxOccurs="1"/>

        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="session-configType">
        <xsd:annotation>
            <xsd:documentation>

                The session-configType defines the session parameters
                for this web application.

                Used in: web-app

            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="session-timeout"
                         type="xsd:integer"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The session-timeout element defines the default
                        session timeout interval for all sessions created
                        in this web application. The specified timeout
                        must be expressed in a whole number of minutes.
                        If the timeout is 0 or less, the container ensures
                        the default behaviour of sessions is never to time
                        out. If this element is not specified, the container
                        must set its default timeout period.

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="cookie-config"
                         type="cookie-configType"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The cookie-config element defines the configuration of the
                        session tracking cookies created by this web application.

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="tracking-mode"
                         type="tracking-modeType"
                         minOccurs="0"
                         maxOccurs="3">
                <xsd:annotation>
                    <xsd:documentation>

                        The tracking-mode element defines the tracking modes
                        for sessions created by this web application

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="id"
                       type="xsd:ID"/>
    </xsd:complexType>

    <xsd:simpleType name="tracking-modeType">
        <xsd:annotation>
            <xsd:documentation>

                The tracking modes for sessions created by this web
                application

                Used in: session-config

            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="COOKIE"/>
            <xsd:enumeration value="URL"/>
            <xsd:enumeration value="SSL"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="cookie-configType">
        <xsd:annotation>
            <xsd:documentation>

                The cookie-configType defines the configuration for the
                session tracking cookies of this web application.

                Used in: session-config

            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="name"
                         type="xsd:string"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The name that will be assigned to any session tracking
                        cookies created by this web application.
                        The default is JSESSIONID

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="domain"
                         type="xsd:string"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The domain name that will be assigned to any session tracking
                        cookies created by this web application.

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="path"
                         type="xsd:string"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The path that will be assigned to any session tracking
                        cookies created by this web application.

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="comment"
                         type="xsd:string"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The comment that will be assigned to any session tracking
                        cookies created by this web application.

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="http-only"
                         type="xsd:boolean"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        Specifies whether any session tracking cookies created
                        by this web application will be marked as HttpOnly

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="secure"
                         type="xsd:boolean"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        Specifies whether any session tracking cookies created
                        by this web application will be marked as secure
                        even if the request that initiated the corresponding session
                        is using plain HTTP instead of HTTPS

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="max-age"
                         type="xsd:integer"
                         minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>

                        The lifetime (in seconds) that will be assigned to any
                        session tracking cookies created by this web application.
                        Default is -1

                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
        <xsd:attribute name="id"
                       type="xsd:ID"/>
    </xsd:complexType>


    <xsd:complexType name="replication-configType">
        <xsd:annotation>
            <xsd:documentation>
                <![CDATA[

            HTTP Session clustering configuration (optional tags)

            ]]>
            </xsd:documentation>
        </xsd:annotation>

        <xsd:sequence>
            <xsd:element name="cache-name" type="xsd:string" minOccurs="0">
                <xsd:annotation>
                    <xsd:documentation>
                        <![CDATA[

                    Clustering only: Specifies the name of the Infinispan container and cache in which to store session data.

                    Default value, if not explicitly set, is determined by the application server.

                    To use a specific cache within a cache container, use the form "container.cache".
                    If unqualified, the default cache of the specified container is used.

                    e.g. <cache-name>web</cache-name>
                         <cache-name>web.dist</cache-name>

                    ]]>
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="replication-granularity" type="replication-granularityType" minOccurs="0"
                         default="SESSION">
                <xsd:annotation>
                    <xsd:documentation>
                        <![CDATA[

                    Clustering only: Determines the session replication granularity level.
                    Possible values are:
                            1 - "SESSION" (default)
                            2 - "ATTRIBUTE"

                    Using SESSION granularity, all session attributes are replicated if any were modified within
                    the scrope of a request. This policy is required if an object reference is shared by multiple
                    session attributes. However, this can be inefficient if session attributes are sufficiently
                    large and/org are modified infrequently, since all attributes must be replicated reglardless
                    of  whether they were modified or not.

                    Using ATTRIBUTE granularity, only those attributes that were modified within the scope of a
                    request are replicated. This policy is not appropriate if an object reference is shared by
                    multiple session attributes. This can be more efficient than SESSION granularity if the
                    session attributes are sufficiently large and/or modified infrequently.

                    Examples:
                          <replication-granularity>SESSION</replication-granularity>
                       or
                          <replication-granularity>ATTRIBUTE</replication-granularity>

                    ]]>
                    </xsd:documentation>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="replication-granularityType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="SESSION"/>
            <xsd:enumeration value="ATTRIBUTE"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="empty"/>
</xsd:schema>

