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

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

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:wildfly:credential-reference:1.1"
           xmlns="urn:wildfly:credential-reference:1.1"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.0">

    <!-- Shared Credential Reference Types
         See README.md for a description of what needs to be done if you are adding a new version of this schema. -->
    <xs:attributeGroup name="credentialReferenceStoreBased">
        <xs:annotation>
            <xs:documentation>
                Group of attributes used when referencing credential through credential store.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="store" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Credential store name used to fetch credential with given 'alias' from.
                    Credential store name has to be defined elsewhere.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="alias" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Alias of credential in the credential store.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="type" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Type of credential to be fetched from credential store.
                    It is usually fully qualified class name.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:attributeGroup>

    <xs:complexType name="credentialReferenceType">
        <xs:annotation>
            <xs:documentation>
                Credential to be used by the configuration.
            </xs:documentation>
        </xs:annotation>
        <xs:attributeGroup ref="credentialReferenceStoreBased"/>
        <xs:attribute name="clear-text" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    Credential/password in clear text. If used on its own, this should only be used for testing purposes.

                    This attribute can also be specified together with the 'store' attribute. If the 'alias' attribute
                    is also specified, one of the following will then occur:

                    If the credential store does not contain an entry for the given 'alias', a new entry will be added
                    to the credential store to hold the clear text password that was specified.

                    If the credential store does contain an entry for the given 'alias', the existing credential will
                    be replaced with the clear text password that was specified.

                    If the 'clear-text' attribute is specified together with the 'store' attribute but the 'alias' is
                    not specified, an alias will be generated and a new entry will be added to the credential store to
                    hold the clear text password that was specified.

                    In all three cases, the 'clear-text' attribute will be removed from the model after adding / updating
                    an entry in the credential store.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

</xs:schema>
