private byte[] sign(final byte[] metadata, final X509Certificate signingCertificate,
                        final PrivateKey privateKey) throws Exception {
        try (var is = new ByteArrayInputStream(metadata)) {
            val document = getConfigurationContext().getOpenSamlConfigBean().getParserPool().parse(is);
            val documentElement = document.getDocumentElement();
            val unmarshaller = getConfigurationContext().getOpenSamlConfigBean()
                .getUnmarshallerFactory().getUnmarshaller(documentElement);
            val xmlObject = Objects.requireNonNull(unmarshaller).unmarshall(documentElement);
            if (xmlObject instanceof final SignableXMLObject root && !root.isSigned()) {
                val signingParameters = new SignatureSigningParameters();
                val credential = new BasicX509Credential(signingCertificate, privateKey);
                val mgmr = DefaultSecurityConfigurationBootstrap.buildBasicKeyInfoGeneratorManager();
                val keyInfoGenerator = mgmr.getDefaultManager().getFactory(credential).newInstance();
                signingParameters.setKeyInfoGenerator(keyInfoGenerator);
                signingParameters.setSigningCredential(credential);
                signingParameters.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
                signingParameters.setSignatureReferenceDigestMethod(SignatureConstants.ALGO_ID_DIGEST_SHA256);
                signingParameters.setSignatureCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
                SignatureSupport.signObject(root, signingParameters);
                return SamlUtils.transformSamlObject(getConfigurationContext().getOpenSamlConfigBean(), root)
                    .toString().getBytes(StandardCharsets.UTF_8);
            }
            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