@Override
    protected String writeMetadata(final String metadata, final Optional<SamlRegisteredService> registeredService) throws Throwable {
        val metadataResource = getConfigurationContext().getSamlIdPMetadataLocator().resolveMetadata(registeredService);
        val metadataFile = metadataResource.getFile();
        LOGGER.info("Writing SAML2 metadata to [{}]", metadataFile);

        val mdProps = getConfigurationContext().getCasProperties().getAuthn().getSamlIdp().getMetadata();
        if (mdProps.getFileSystem().isSignMetadata()) {
            val resolvedCert = getConfigurationContext().getSamlIdPMetadataLocator().resolveSigningCertificate(registeredService);
            val signingCertificate = SamlUtils.readCertificate(resolvedCert);

            val resolvedKey = getConfigurationContext().getSamlIdPMetadataLocator().resolveSigningKey(registeredService);
            val bean = new PrivateKeyFactoryBean();
            bean.setLocation(resolvedKey);
            bean.afterPropertiesSet();
            val signingKey = bean.getObject();

            val signedMetadata = sign(metadata.getBytes(StandardCharsets.UTF_8), signingCertificate, signingKey);
            FileUtils.write(metadataFile, new String(signedMetadata, StandardCharsets.UTF_8), StandardCharsets.UTF_8);
        } else {
            FileUtils.write(metadataFile, metadata, StandardCharsets.UTF_8);
        }
        LOGGER.info("Wrote SAML2 metadata to [{}]", metadataFile);
        return metadata;
    }
A metadata generator based on a predefined template.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-saml-idp-core/src/main/java/org/apereo/cas/support/saml/idp/metadata/generator/FileSystemSamlIdPMetadataGenerator.java