protected SamlRegisteredService findRegisteredService(final String serviceId) throws Throwable {
        var matchedServices = (Collection<RegisteredService>) null;
        if (NumberUtils.isCreatable(serviceId)) {
            val id = Long.parseLong(serviceId);
            val samlService = servicesManager.getObject().findServiceBy(id, SamlRegisteredService.class);
            matchedServices = samlService != null ? List.of(samlService) : List.of();
        } else {
            matchedServices = servicesManager.getObject().findServiceBy(svc -> svc instanceof SamlRegisteredService
                && (svc.getName().equalsIgnoreCase(serviceId) || svc.getServiceId().equalsIgnoreCase(serviceId)));
        }
        if (matchedServices.isEmpty()) {
            throw UnauthorizedServiceException.denied("Unable to locate service " + serviceId);
        }
        val registeredService = (SamlRegisteredService) matchedServices.iterator().next();
        val ctx = AuditableContext.builder()
            .registeredService(registeredService)
            .build();
        val result = registeredServiceAccessStrategyEnforcer.getObject().execute(ctx);
        result.throwExceptionIfNeeded();
        LOGGER.debug("Located registered service definition [{}]", registeredService);
        return registeredService;
    }
Gets cached metadata object.

@param serviceId the service id
@param entityId  the entity id
@param force     the force
@return the cached metadata object
support/cas-server-support-saml-idp-web/src/main/java/org/apereo/cas/support/saml/web/idp/metadata/SamlRegisteredServiceCachedMetadataEndpoint.java