private Optional<RegisteredService> locateTemplateServiceDefinition(final RegisteredService registeredService,
                                                                        final String templateName) {
        val scriptFactory = ExecutableCompiledScriptFactory.getExecutableCompiledScriptFactory();
        return templateDefinitionFiles
            .stream()
            .filter(__ -> CasRuntimeHintsRegistrar.notInNativeImage())
            .filter(registeredServiceSerializer::supports)
            .filter(file -> FilenameUtils.getBaseName(file.getAbsolutePath()).equalsIgnoreCase(templateName))
            .map(file -> FunctionUtils.doUnchecked(() -> {
                val templateParams = registeredService.getProperties()
                    .entrySet()
                    .stream()
                    .map(entry -> {
                        val listOfValues = new ArrayList<>(entry.getValue().getValues());
                        val values = listOfValues.size() == 1 ? listOfValues.getFirst() : listOfValues;
                        return Pair.of(entry.getKey(), values);
                    })
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

                val template = scriptFactory.createTemplate(file, templateParams);
                return registeredServiceSerializer.from(template);
            }))
            .sorted(Comparator.comparingInt(RegisteredService::getEvaluationOrder))
            .filter(templateService -> templateService.getClass().equals(registeredService.getClass())
                                       && templateService.getTemplateName().equalsIgnoreCase(templateName))
            .findFirst();
    }
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