@Audit(action = AuditableActions.SAML2_METADATA_RESOLUTION,
        actionResolverName = AuditActionResolvers.SAML2_METADATA_RESOLUTION_ACTION_RESOLVER,
        resourceResolverName = AuditResourceResolvers.SAML2_METADATA_RESOLUTION_RESOURCE_RESOLVER)
    @Override
    public Collection<? extends MetadataResolver> resolve(final SamlRegisteredService service, final CriteriaSet criteriaSet) {
        HttpResponse response = null;
        try {
            RegisteredServiceAccessStrategyUtils.ensureServiceAccessIsAllowed(service);
            val metadataLocations = getMetadataLocationsForService(service, criteriaSet);

            for (val metadataLocation : metadataLocations) {
                LOGGER.info("Loading SAML metadata from [{}]", metadataLocations);
                val metadataResource = new UrlResource(metadataLocation);

                val backupFile = getMetadataBackupFile(metadataResource, service);
                if (backupFile.exists() && samlIdPProperties.getMetadata().getHttp().isForceMetadataRefresh()) {
                    LOGGER.debug("CAS is configured to forcefully refresh metadata for service [{}]. Old metadata backup files "
                        + "will now be deleted for this service.", service.getName());
                    cleanUpExpiredBackupMetadataFilesFor(metadataResource, service);
                }
                val canonicalPath = backupFile.getCanonicalPath();
                LOGGER.debug("Metadata backup file for [{}] will be at [{}]", service.getName(), canonicalPath);
                FileUtils.forceMkdirParent(backupFile);

                if (backupFile.exists() && backupFile.canRead()) {
                    try {
                        val metadataProvider = getMetadataResolverFromFile(backupFile);
                        configureAndInitializeSingleMetadataResolver(metadataProvider, service);
                        if (Boolean.TRUE.equals(metadataProvider.isRootValid())) {
                            LOGGER.debug("Metadata backup file for service [{}] at [{}] is valid. CAS will reuse the SAML2 metadata file "
                                    + "at [{}] and will not download new metadata from [{}]",
                                service.getName(), canonicalPath, canonicalPath, metadataLocation);
                            return CollectionUtils.wrap(metadataProvider);
                        }
                    } catch (final Exception e) {
                        LoggingUtils.error(LOGGER, e);
                    }

                    LOGGER.info("Metadata backup file found for service [{}] at [{}] is invalid and will be disregarded. "
                            + "CAS will proceed to download new metadata from [{}]",
                        service.getName(), canonicalPath, metadataLocation);
                    FileUtils.forceDelete(backupFile);

                }

                response = fetchMetadata(service, metadataLocation, criteriaSet, backupFile);
                val status = response != null ? HttpStatus.valueOf(response.getCode()) : HttpStatus.BAD_REQUEST;
                LOGGER.debug("Received metadata response status code [{}]", status);
                if (shouldHttpResponseStatusBeProcessed(status)) {
                    val metadataProvider = getMetadataResolverFromResponse(response, backupFile);
                    configureAndInitializeSingleMetadataResolver(metadataProvider, service);
                    return CollectionUtils.wrap(metadataProvider);
                }
            }
        } catch (final UnauthorizedServiceException e) {
            LoggingUtils.error(LOGGER, e);
            throw new SamlException(e.getMessage(), e);
        } catch (final Exception e) {
            LoggingUtils.error(LOGGER, e);
        } finally {
            HttpUtils.close(response);
        }
        return new ArrayList<>();
    }
This is {@link UrlResourceMetadataResolver}.

@author Misagh Moayyed
@since 5.2.0
support/cas-server-support-saml-idp-metadata/src/main/java/org/apereo/cas/support/saml/services/idp/metadata/cache/resolver/UrlResourceMetadataResolver.java