@Override
    protected SamlIdPMetadataDocument finalizeMetadataDocument(final SamlIdPMetadataDocument doc,
                                                               final Optional<SamlRegisteredService> registeredService) throws Exception {
        doc.setAppliesTo(getAppliesToFor(registeredService));
        val properties = getConfigurationContext().getCasProperties().getAuthn().getSamlIdp().getMetadata().getRest();
        val url = StringUtils.appendIfMissing(properties.getUrl(), "/").concat("idp");
        HttpResponse response = null;
        try {
            val headers = CollectionUtils.<String, String>wrap(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
            headers.putAll(properties.getHeaders());

            val exec = HttpExecutionRequest.builder()
                .basicAuthPassword(properties.getBasicAuthPassword())
                .basicAuthUsername(properties.getBasicAuthUsername())
                .method(HttpMethod.POST)
                .url(url)
                .headers(headers)
                .entity(MAPPER.writeValueAsString(doc))
                .build();
            response = HttpUtils.execute(exec);
            if (response != null) {
                val status = HttpStatus.valueOf(response.getCode());
                if (status.is2xxSuccessful()) {
                    return doc;
                }
            }
        } finally {
            HttpUtils.close(response);
        }
        return null;
    }
This is {@link RestfulSamlIdPMetadataGenerator}.

@author Misagh Moayyed
@since 6.2.0
support/cas-server-support-saml-idp-metadata-rest/src/main/java/org/apereo/cas/support/saml/idp/metadata/RestfulSamlIdPMetadataGenerator.java