<?xml version="1.0" encoding="UTF-8"?>
<schema
    targetNamespace="urn:oasis:names:tc:SAML:2.0:metadata"
    xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
    xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="unqualified"
    attributeFormDefault="unqualified"
    blockDefault="substitution"
    version="2.0">
    
    <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
    <import namespace="urn:oasis:names:tc:SAML:2.0:assertion" schemaLocation="sstc-saml-schema-assertion-2.0.xsd"/>
    <import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>

    <element name="Extensions" type="md:ExtensionsType"/>
    <complexType final="#all" name="ExtensionsType">
        <sequence>
            <any namespace="##any" processContents="lax" maxOccurs="unbounded"/>
        </sequence>
    </complexType>

    <simpleType name="EntityIDType">
        <restriction base="anyURI">
            <maxLength value="1024"/>
        </restriction>
    </simpleType>
      
    <element name="EntitiesDescriptor" type="md:EntitiesDescriptorType"/>
    <complexType name="EntitiesDescriptorType">
        <sequence>
            <element ref="md:EntityDescriptor" minOccurs="1" maxOccurs="unbounded"/>
            <element ref="md:Extensions" minOccurs="0"/>
            <element ref="ds:Signature" minOccurs="0"/>
        </sequence>
        <attribute name="Name" type="string" use="optional"/>
    </complexType>

    <element name="EntityDescriptor" type="md:EntityDescriptorType"/>
    <complexType name="EntityDescriptorType">
        <sequence>
            <choice>
                <choice maxOccurs="unbounded">
                    <element ref="md:RoleDescriptor"/>
                    <element ref="md:IDPDescriptor"/>
                    <element ref="md:SPDescriptor"/>
                    <element ref="md:AttributeAuthorityDescriptor"/>
                    <element ref="md:AttributeConsumerDescriptor"/>
                    <element ref="md:PDPDescriptor"/>
                    <any namespace="##other" processContents="lax"/>
                </choice>
                <element ref="md:AffiliationDescriptor"/>
            </choice>
            <element ref="md:Organization" minOccurs="0"/>
            <element ref="md:ContactPerson" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:AdditionalMetadataLocation" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:Extensions" minOccurs="0"/>
            <element ref="ds:Signature" minOccurs="0"/>
        </sequence>
        <attribute name="providerID" type="md:EntityIDType" use="required"/>
        <attribute name="validUntil" type="dateTime" use="optional"/>
        <attribute name="cacheDuration" type="duration" use="optional"/>
        <attribute name="id" type="ID" use="optional"/>
        <anyAttribute namespace="##other" processContents="lax"/>
    </complexType>
    
    <element name="RoleDescriptor" type="md:RoleDescriptorType"/>
    <complexType name="RoleDescriptorType" abstract="true">
        <sequence>
            <element ref="ds:Signature" minOccurs="0"/>
            <element ref="md:KeyDescriptor" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:Organization" minOccurs="0"/>
            <element ref="md:ContactPerson" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:SOAPEndpoint" minOccurs="0"/>
            <element ref="md:Extensions" minOccurs="0"/>
        </sequence>
        <attribute name="id" type="ID" use="optional"/>
        <attribute name="validUntil" type="dateTime" use="optional"/>
        <attribute name="cacheDuration" type="duration" use="optional"/>
        <attribute name="protocolSupportEnumeration" type="NMTOKENS" use="required"/>
        <anyAttribute namespace="##other" processContents="lax"/>
    </complexType>
    <element name="SOAPEndpoint" type="anyURI"/>
    <element name="KeyDescriptor" type="md:KeyDescriptorType"/>
    <complexType name="KeyDescriptorType">
        <sequence>
          <element ref="md:EncryptionMethod" minOccurs="0"/>
          <element ref="md:KeySize" minOccurs="0"/>
          <element ref="ds:KeyInfo" minOccurs="0"/>
          <element ref="md:Extensions" minOccurs="0"/>
        </sequence>
        <attribute name="use" type="md:KeyTypes" use="optional"/>
    </complexType>
    <element name="EncryptionMethod" type="anyURI"/>
    <element name="KeySize" type="integer"/>
    <simpleType name="KeyTypes">
        <restriction base="string">
            <enumeration value="encryption"/>
            <enumeration value="signing"/>
        </restriction>
    </simpleType>

    <element name="ContactPerson" type="md:ContactType"/>
    <complexType name="ContactType">
        <sequence>
            <element ref="md:Company" minOccurs="0"/>
            <element ref="md:GivenName" minOccurs="0"/>
            <element ref="md:SurName" minOccurs="0"/>
            <element ref="md:EmailAddress" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:TelephoneNumber" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:Extensions" minOccurs="0"/>
        </sequence>
        <attribute name="contactType" type="md:ContactTypeType" use="required"/>
        <anyAttribute namespace="##other" processContents="lax"/>
    </complexType>
    <element name="Company" type="string"/>
    <element name="GivenName" type="string"/>
    <element name="SurName" type="string"/>
    <element name="EmailAddress" type="anyURI"/>
    <element name="TelephoneNumber" type="string"/>    
    <simpleType name="ContactTypeType">
        <restriction base="string">
            <enumeration value="technical"/>
            <enumeration value="administrative"/>
            <enumeration value="billing"/>
            <enumeration value="other"/>
        </restriction>
    </simpleType>
    <element name="Organization" type="md:OrganizationType"/>
    <complexType name="OrganizationType">
        <sequence>
            <element ref="md:OrganizationName" maxOccurs="unbounded"/>
            <element ref="md:OrganizationDisplayName" maxOccurs="unbounded"/>
            <element ref="md:OrganizationURL" maxOccurs="unbounded"/>
            <element ref="md:Extensions" minOccurs="0"/>
        </sequence>
        <anyAttribute namespace="##other" processContents="lax"/>
    </complexType>
    <element name="OrganizationName" type="md:localizedNameType"/>
    <complexType name="localizedNameType">
        <simpleContent>
            <extension base="string">
                <attribute ref="xml:lang" use="optional"/>
            </extension>
        </simpleContent>
    </complexType>
    <element name="OrganizationDisplayName" type="md:OrganizationDisplayNameType"/>
    <complexType name="OrganizationDisplayNameType">
        <simpleContent>
            <extension base="string">
                <attribute ref="xml:lang" use="required"/>
            </extension>
        </simpleContent>
    </complexType>
    <element name="OrganizationURL" type="md:localizedURIType"/>
    <complexType name="localizedURIType">
        <simpleContent>
            <extension base="anyURI">
                <attribute ref="xml:lang" use="required"/>
            </extension>
        </simpleContent>
    </complexType>

    <element name="AdditionalMetadataLocation" type="md:AdditionalMetadataLocationType"/>
    <complexType name="AdditionalMetadataLocationType">
        <simpleContent>
            <extension base="anyURI">
                <attribute name="namespace" type="anyURI"/>
            </extension>
        </simpleContent>
    </complexType>

    <complexType name="SSODescriptorType">
        <complexContent>
            <extension base="md:RoleDescriptorType">
                <sequence>
                    <element ref="md:SingleLogoutService" minOccurs="0" maxOccurs="unbounded"/>
                    <element ref="md:SingleLogoutServiceReturnURL" minOccurs="0"/>
                    <element ref="md:FederationTerminationService" minOccurs="0" maxOccurs="unbounded"/>
                    <element ref="md:FederationTerminationServiceReturnURL" minOccurs="0"/>
                    <element ref="md:RegisterNameIdentifierService" minOccurs="0" maxOccurs="unbounded"/>
                    <element ref="md:RegisterNameIdentifierServiceReturnURL" minOccurs="0"/>
                    <element ref="md:NameIdentifierMappingService" minOccurs="0" maxOccurs="unbounded"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <element name="SingleLogoutService" type="md:EndpointType"/>
    <element name="SingleLogoutServiceReturnURL" type="anyURI"/>
    <element name="RegisterNameIdentifierService" type="md:EndpointType"/>
    <element name="RegisterNameIdentifierServiceReturnURL" type="anyURI"/>
    <element name="FederationTerminationService" type="md:EndpointType"/>
    <element name="FederationTerminationServiceReturnURL" type="anyURI"/>
    <element name="NameIdentifierMappingService" type="md:EndpointType"/>
    <complexType name="EndpointType">
        <attribute name="Binding" type="anyURI" use="required"/>
        <attribute name="Location" type="anyURI" use="optional"/>
    </complexType>

    <element name="IDPDescriptor" type="md:IDPDescriptorType"/>
    <complexType name="IDPDescriptorType">
        <complexContent>
            <extension base="md:SSODescriptorType">
                <sequence>
                    <element ref="md:SingleSignOnService" maxOccurs="unbounded"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <element name="SingleSignOnService" type="md:EndpointType"/>
    
    <element name="SPDescriptor" type="md:SPDescriptorType"/>
    <complexType name="SPDescriptorType">
        <complexContent>
            <extension base="md:SSODescriptorType">
                <sequence>
                    <element ref="md:AssertionConsumerServiceURL" maxOccurs="unbounded"/>
                </sequence>
                <attribute name="AuthnRequestsSigned" type="boolean" use="optional"/>
            </extension>
        </complexContent>
    </complexType>
    <element name="AssertionConsumerServiceURL" type="md:AssertionConsumerServiceURLType"/>
    <complexType name="AssertionConsumerServiceURLType">
        <simpleContent>
            <extension base="anyURI">
                <attribute name="id" type="string" use="required"/>
                <attribute name="isDefault" type="boolean" use="optional"/>
            </extension>
        </simpleContent>
    </complexType>
  
    <element name="PDPDescriptor" type="md:PDPDescriptorType"/>
    <complexType name="PDPDescriptorType">
        <complexContent>
            <extension base="md:RoleDescriptorType">
                <sequence>
                    <element ref="md:AuthorizationService" maxOccurs="unbounded"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <element name="AuthorizationService" type="md:EndpointType"/>

    <element name="AttributeAuthorityDescriptor" type="md:AttributeAuthorityDescriptorType"/>
    <complexType name="AttributeAuthorityDescriptorType">
        <complexContent>
            <extension base="md:RoleDescriptorType">
                <sequence>
                    <element ref="md:AttributeService" maxOccurs="unbounded"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <element name="AttributeService" type="md:EndpointType"/>

    <element name="AttributeConsumerDescriptor" type="md:AttributeConsumerDescriptorType"/>
    <complexType name="AttributeConsumerDescriptorType">
        <complexContent>
            <extension base="md:RoleDescriptorType">
                <sequence>
                    <element ref="md:AttributeConsumingService" maxOccurs="unbounded"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <element name="AttributeConsumingService" type="md:AttributeConsumingServiceType"/>
    <complexType name="AttributeConsumingServiceType">
        <sequence>
            <element ref="md:ServiceName" maxOccurs="unbounded"/>
            <element ref="md:ServiceDescription" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="md:WantAttribute" maxOccurs="unbounded"/>
        </sequence>
        <attribute name="isDefault" type="boolean" use="optional"/>
        <anyAttribute namespace="##other" processContents="lax"/>
    </complexType>
    <element name="ServiceName" type="md:localizedNameType"/>
    <element name="ServiceDescription" type="md:localizedNameType"/>
    <element name="WantAttribute" type="md:WantAttributeType"/>
    <complexType name="WantAttributeType">
        <complexContent>
            <extension base="saml:AttributeDesignatorType">
                <attribute name="isRequired" type="boolean" use="optional"/>
            </extension>
        </complexContent>
    </complexType>
    
    <element name="AffiliationDescriptor" type="md:AffiliationDescriptorType"/>
    <complexType name="AffiliationDescriptorType">
        <sequence>
            <element ref="md:AffiliateMember" maxOccurs="unbounded"/>
            <element ref="md:Extensions" minOccurs="0"/>
            <element ref="md:KeyDescriptor" minOccurs="0" maxOccurs="unbounded"/>
            <element ref="ds:Signature" minOccurs="0"/>
        </sequence>
        <attribute name="affiliationOwnerID" type="md:EntityIDType" use="required"/>
        <attribute name="validUntil" type="dateTime" use="optional"/>
        <attribute name="cacheDuration" type="duration" use="optional"/>
        <attribute name="id" type="ID" use="optional"/>
        <anyAttribute namespace="##other" processContents="lax"/>
    </complexType>
    <element name="AffiliateMember" type="md:EntityIDType"/>
</schema>
