@Override
    public <T extends RegisteredService> T findServiceByName(final String name, final Class<T> clazz) {
        if (StringUtils.isBlank(name)) {
            return null;
        }
        var service = getService(registeredService -> registeredService.getName().equals(name));
        if (service != null && clazz.isAssignableFrom(service.getClass())) {
            return (T) service;
        }
        LOGGER.trace("The service with name [{}] and type [{}] is not found in the cache; trying to find it from [{}]",
            name, clazz, configurationContext.getServiceRegistry().getName());
        service = configurationContext.getServiceRegistry().findServiceByExactServiceName(name, clazz);
        if (service != null) {
            cacheRegisteredService(service);
            LOGGER.trace("The service is found in [{}] and added to the cache [{}]",
                configurationContext.getServiceRegistry().getName(), service);
        }
        return (T) validateRegisteredService(service);
    }
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