@Override
    public RegisteredService findServiceBy(final Service service) {
        if (service == null) {
            return null;
        }

        val candidates = getCandidateServicesToMatch(service.getId());
        var foundService = configurationContext.getRegisteredServiceLocators()
            .stream()
            .map(locator -> locator.locate(candidates, service))
            .filter(registeredService -> validateRegisteredService(registeredService) != null)
            .findFirst();

        if (foundService.isEmpty()) {
            val serviceRegistry = configurationContext.getServiceRegistry();
            LOGGER.trace("Service [{}] is not cached; Searching [{}]", service.getId(), serviceRegistry.getName());
            foundService = Optional.ofNullable(serviceRegistry.findServiceBy(service.getId()));
            if (foundService.isPresent()) {
                val registeredService = foundService.get();
                foundService = configurationContext.getRegisteredServiceLocators()
                    .stream()
                    .filter(locator -> locator.supports(registeredService, service))
                    .findFirst()
                    .map(locator -> {
                        LOGGER.debug("Service [{}] is found in service registry and can be supported by [{}]", registeredService, locator.getName());
                        cacheRegisteredService(registeredService);
                        LOGGER.trace("Service [{}] is now cached from [{}]", service, serviceRegistry.getName());
                        return Optional.of(registeredService);
                    })
                    .orElseGet(Optional::empty);
            }
        }

        foundService.ifPresent(RegisteredService::initialize);
        return validateRegisteredService(foundService.orElse(null));
    }
This is {@link AbstractServicesManager}.

@author Misagh Moayyed
@since 5.2.0
core/cas-server-core-services-registry/src/main/java/org/apereo/cas/services/mgmt/AbstractServicesManager.java