<SPConfig xmlns="urn:mace:shibboleth:2.0:native:sp:config"
    xmlns:conf="urn:mace:shibboleth:2.0:native:sp:config"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
    clockSkew="180">


    <!--
    The InProcess section contains settings affecting web server modules.
    Required for IIS, but can be removed when using other web servers.
    -->
    <InProcess logger="native.logger">
        <ISAPI normalizeRequest="true" safeHeaderNames="true">
        <!--
        Maps IIS Instance ID values to the host scheme/name/port. The name is
        required so that the proper <Host> in the request map above is found without
        having to cover every possible DNS/IP combination the user might enter.

        When the port and scheme are omitted, the HTTP request's port and scheme are used.
        If these are wrong because of virtualization, they can be explicitly set
        (e.g. with scheme="https" port="443" ) ensure proper redirect generation.

        Fore information on https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPISAPI
        -->
            <Site id="1" name="{hostname}"/>
        </ISAPI>
    </InProcess>

    <!--
    To customize behavior for specific resources on Apache, and to link vhosts or
    resources to ApplicationOverride settings below, use web server options/commands.
    More information on: https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPConfigurationElements

    For examples with the RequestMap XML syntax instead, see the example-shibboleth2.xml
    file and https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPRequestMapHowTo
    -->
    <RequestMapper type="Native">
        <RequestMap applicationId="default">
            <!--
            The example below requires a session for documents in /secure on the containing host with http and
            https on the default ports. Note that the name and port in the <Host> elements MUST match
            Apache's ServerName and Port directives or the IIS Site name in the <ISAPI> element
            below.
            -->
            <Host name="{hostname}">
                <Path name="secure"
                      authType="shibboleth"
                      requireSession="true"/>
            </Host>

        </RequestMap>
    </RequestMapper>

    <!-- The ApplicationDefaults element is where most of Shibboleth's SAML bits are defined. -->
    <ApplicationDefaults entityID="https://{hostname}/shibboleth"
                         homeURL="{targetURL}"
                         metadataAttributePrefix="Meta-"
                         REMOTE_USER="persistent-id targeted-id uniqueID"
                         signing="back"
                         requireTransportAuth="false">

        <!--
        Controls session lifetimes, address checks, cookie handling, and the protocol handlers.
        More information on: https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPSessions
        -->
        <Sessions lifetime="28800"
                  timeout="3600"
                  relayState="ss:mem"
                  checkAddress="false"
                  consistentAddress="true"
                  handlerSSL="true"
                  redirectLimit="host"
                  cookieProps="https">

            <!--
            In order to use a default Identity Provider add an attribute like:
            entityID="https://idp.example.org/shibboleth" to the SSO element.
            It's value should be the entityID of the default Identity Provider.
            More information on: https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPServiceSSO
            -->
            <SSO discoveryProtocol="SAMLDS"
                 discoveryURL="{wayfURL}">
              SAML2
            </SSO>

            <!-- SAML and local-only logout. -->
            <Logout>Local</Logout>

            <!-- Extension service that generates "approximate" metadata based on SP configuration. -->
            <Handler type="MetadataGenerator"
                     Location="/Metadata"
                     signing="false"/>

            <!-- Status reporting service. The first IPv4/IPv6 address pair allows access from local host. The remaining addresses are used (or will be used in the future) by the AAI Resource Registry operated by SWITCH -->
            <Handler type="Status"
                     Location="/Status"
                     acl="127.0.0.1 ::1 130.59.118.224 2001:620:0:1006::255 130.59.198.12 2001:620:0:3006::256"/>

            <!-- Session diagnostic service. -->
            <Handler type="Session"
                     showAttributeValues="true"
                     Location="/Session"/>

            <!-- JSON feed of discovery information. -->
            <Handler type="DiscoveryFeed"
                     Location="/DiscoFeed"/>
        </Sessions>

        <!--
        Allows overriding of error template information/filenames. You can
        also add attributes with values that can be plugged into the templates.
        More information on: https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPErrors
        -->
        <Errors access="accessError.html"
                supportContact="{supportEmail}"
                helpLocation="https://www.switch.ch/aai/help"
                logoLocation="https://www.switch.ch/aai/design/images/SWITCHaai.gif"
                styleSheet="https://www.switch.ch/aai/design/shib-error.css"/>

        <!-- Download and verify {federation} metadata -->
        <MetadataProvider type="XML"
                          validate="true"
                          url="{metadataURL}"
                          backingFilePath="{metadataFile}"
                          reloadInterval="3600">
            <MetadataFilter type="RequireValidUntil"
                            maxValidityInterval="604800"/>
            <MetadataFilter type="Signature" verifyBackup="false">
                <TrustEngine type="StaticPKIX"
                             certificate="SWITCHaaiRootCA.crt.pem"
                             verifyDepth="2"
                             checkRevocation="fullChain"
                             policyMappingInhibit="true"
                             anyPolicyInhibit="true">
                      <TrustedName>SWITCHaai Metadata Signer</TrustedName>
                      <PolicyOID>2.16.756.1.2.6.7</PolicyOID>
               </TrustEngine>
            </MetadataFilter>
            <MetadataFilter type="EntityRoleWhiteList">
                <RetainedRole>md:IDPSSODescriptor</RetainedRole>
                <RetainedRole>md:AttributeAuthorityDescriptor</RetainedRole>
            </MetadataFilter>
        </MetadataProvider>

        <!-- Download and verify Interfederation metadata -->
        <MetadataProvider type="XML"
                          validate="true"
                          url="http://metadata.aai.switch.ch/entities/interfederation+idp"
                          backingFilePath="metadata.interfederation-idps.xml"
                          reloadInterval="3600">
            <MetadataFilter type="RequireValidUntil"
                            maxValidityInterval="604800"/>
            <MetadataFilter type="Signature">
                <TrustEngine type="StaticPKIX"
                             certificate="SWITCHaaiRootCA.crt.pem"
                             verifyDepth="2"
                             checkRevocation="fullChain"
                             policyMappingInhibit="true"
                             anyPolicyInhibit="true">
                      <TrustedName>SWITCHaai Interfederation Metadata Signer</TrustedName>
                      <PolicyOID>2.16.756.1.2.6.8</PolicyOID>
               </TrustEngine>
            </MetadataFilter>
            <MetadataFilter type="EntityRoleWhiteList">
                <RetainedRole>md:IDPSSODescriptor</RetainedRole>
                <RetainedRole>md:AttributeAuthorityDescriptor</RetainedRole>
            </MetadataFilter>
        </MetadataProvider>

        <!-- Map to extract attributes from SAML assertions. -->
        <AttributeExtractor type="XML"
                            validate="true"
                            reloadChanges="false"
                            path="attribute-map.xml"/>

        <!-- Extract further attributes about Identity Providers from metadata -->
        <AttributeExtractor  type="Metadata"
                             errorURL="errorURL"
                             DisplayName="displayName"
                             InformationURL="informationURL"
                             PrivacyStatementURL="privacyStatementURL"
                             OrganizationURL="organizationURL">
            <ContactPerson
                    id="technicalContactDisplayName"
                    contactType="technical"
                    formatter="$GivenName $SurName" />
            <ContactPerson
                    id="technicalContactMailtoURI"
                    contactType="technical"
                    formatter="$EmailAddress" />
            <ContactPerson
                    id="supportContactDisplayName"
                    contactType="support"
                    formatter="$GivenName $SurName" />
            <ContactPerson
                    id="supportContactMailtoURI"
                    contactType="support"
                    formatter="$EmailAddress" />
            <ContactPerson
                    id="administrativeContactDisplayName"
                    contactType="administrative"
                    formatter="$GivenName $SurName" />
            <ContactPerson
                    id="administrativeContactMailtoURI"
                    contactType="administrative"
                    formatter="$EmailAddress" />
            <Logo
                   id="smallLogo"
                   height="16"
                   width="16"
                   formatter="&lt;img src='$_string' height='$height' width='$width'/&gt;"/>
            <Logo
                    id="largeLogo"
                    height="60"
                    width="80"
                    formatter="&lt;img src='$_string' height='$height' width='$width'/&gt;"/>
        </AttributeExtractor>

        <!-- Use a SAML query if no attributes are supplied during SSO. -->
        <AttributeResolver type="Query"
                           subjectMatch="true"/>

        <!-- Query the SWITCHtoolbox for group attributes -->
        <AttributeResolver type="SimpleAggregation"
                           attributeId="uniqueID"
                           format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
            <Entity>https://toolbox.switch.ch/idp/shibboleth</Entity>
       </AttributeResolver>

        <!-- Default filtering policy for recognized attributes, lets other data pass -->
        <AttributeFilter type="XML"
                         validate="true"
                         reloadChanges="false"
                         path="attribute-policy.xml"/>

        <!--
        Certificate/Private key pairs are read in sequence.
        Unless specificially defined only the first
        CredentialResolver is used for attribute requests.
        More information:
        https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPCredentialResolver
        -->
        <CredentialResolver type="Chaining">
             <!-- Active certificate -->
             <CredentialResolver type="File"
                                 key="{keyPath}"
                                 certificate="{certPath}"/>
        </CredentialResolver>

        <!--
        The default settings can be overridden by creating ApplicationOverride elements.
        More Information and examples on:
        https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPApplicationOverride
        -->
    </ApplicationDefaults>

    <!-- Policies that determine how to process and authenticate runtime messages. -->
    <SecurityPolicyProvider type="XML"
                            validate="true"
                            reloadChanges="false"
                            path="security-policy.xml"/>

    <!-- Low-level configuration about protocols and bindings available for use. -->
    <ProtocolProvider type="XML"
                      validate="true"
                      reloadChanges="false"
                      path="protocols.xml"/>

</SPConfig>
