@Override
    public RegisteredService apply(final RegisteredService registeredService) {
        if (templateDefinitionFiles.isEmpty() || StringUtils.isBlank(registeredService.getTemplateName())) {
            LOGGER.trace("Registered service template directory contains no template definitions, "
                         + "or registered service [{}] does specify template name(s)", registeredService.getName());
            return registeredService;
        }

        RegisteredService mergeResult = null;
        val templateNames = org.springframework.util.StringUtils.commaDelimitedListToStringArray(registeredService.getTemplateName().trim());
        for (val templateName : templateNames) {
            val templateDefinition = locateTemplateServiceDefinition(registeredService, templateName);
            if (templateDefinition.isEmpty()) {
                LOGGER.warn("Registered service template definition [{}] cannot be found and is not applicable to [{}]",
                    templateName, registeredService.getName());
            } else {
                val templateService = templateDefinition.get();
                LOGGER.trace("Applying template service definition [{}] to service [{}]", templateService, registeredService.getName());
                mergeResult = registeredServiceSerializer.merge(templateService, Objects.requireNonNullElse(mergeResult, registeredService));
                LOGGER.debug("Resulting service definition after merging with template [{}] is:\n[{}]",
                    templateService.getTemplateName(), mergeResult);
            }
        }
        return Objects.requireNonNullElse(mergeResult, registeredService);
    }
This is {@link DefaultRegisteredServicesTemplatesManager}.

@author Misagh Moayyed
@since 7.0.0
core/cas-server-core-services-registry/src/main/java/org/apereo/cas/services/DefaultRegisteredServicesTemplatesManager.java