@Override
    public SamlIdPMetadataDocument generate(final Optional<SamlRegisteredService> registeredService) throws Throwable {
        val idp = configurationContext.getCasProperties().getAuthn().getSamlIdp();
        LOGGER.debug("Preparing to generate metadata for entity id [{}]", idp.getCore().getEntityId());
        if (!doesMetadataExistFor(registeredService)) {
            val owner = getAppliesToFor(registeredService);
            LOGGER.trace("Metadata does not exist for [{}]", owner);
            if (shouldGenerateMetadata(registeredService)) {
                LOGGER.trace("Creating metadata artifacts for [{}]...", owner);

                val doc = newSamlIdPMetadataDocument();
                try (val executor = Executors.newVirtualThreadPerTaskExecutor()) {
                    val signingCertTask = Unchecked.callable(() -> {
                        LOGGER.info("Creating self-signed certificate for signing...");
                        return buildSelfSignedSigningCert(registeredService);
                    });
                    val encryptionCertTask = Unchecked.callable(() -> {
                        LOGGER.info("Creating self-signed certificate for encryption...");
                        return buildSelfSignedEncryptionCert(registeredService);
                    });

                    val signingFuture = executor.submit(signingCertTask);
                    val encryptionFuture = executor.submit(encryptionCertTask);
                    val signing = signingFuture.get();
                    val encryption = encryptionFuture.get();
                    LOGGER.info("Creating SAML2 metadata for identity provider...");
                    val metadata = buildMetadataGeneratorParameters(signing, encryption, registeredService);

                    doc.setEncryptionCertificate(encryption.getKey());
                    doc.setEncryptionKey(encryption.getValue());
                    doc.setSigningCertificate(signing.getKey());
                    doc.setSigningKey(signing.getValue());
                    doc.setMetadata(metadata);
                }
                return finalizeMetadataDocument(doc, registeredService);
            }
            LOGGER.debug("Skipping metadata generation process for [{}]", owner);
        }

        val samlIdPMetadataLocator = configurationContext.getSamlIdPMetadataLocator();
        return samlIdPMetadataLocator.fetch(registeredService);
    }
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/BaseSamlIdPMetadataGenerator.java