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

<!--
  ~ JBoss, Home of Professional Open Source
  ~ Copyright 2019, Red Hat, Inc., and individual contributors as indicated
  ~ by the @authors tag.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<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>
