protected static Optional<String> getEntityIdAsParameter(final Service service) {
        try {
            LOGGER.trace("Checking for query parameters in [{}] to locate entity id", service.getId());
            val builder = new URIBuilder(service.getId());
            val param = builder.getQueryParams()
                .stream()
                .filter(p -> p.getName().equals(SamlProtocolConstants.PARAMETER_ENTITY_ID))
                .findFirst();

            if (param.isPresent()) {
                LOGGER.debug("Found entity id in service id [{}]", param.get().getValue());
                return Optional.of(param.get().getValue());
            }

            if (service.getAttributes().containsKey(SamlProtocolConstants.PARAMETER_ENTITY_ID)) {
                val entityId = CollectionUtils.firstElement(service.getAttributes().get(SamlProtocolConstants.PARAMETER_ENTITY_ID)).map(Object::toString);
                LOGGER.debug("Found entity id in service attributes [{}]", entityId);
                return entityId;
            }
            
            val request = WebUtils.getHttpServletRequestFromExternalWebflowContext();
            if (request != null && StringUtils.isNotBlank(request.getQueryString())) {
                LOGGER.debug("Evaluating http request query string [{}]", request.getQueryString());
                val query = request.getQueryString().split("&");
                val paramRequest = Arrays.stream(query)
                    .map(p -> {
                        var params = Splitter.on("=").splitToList(p);
                        return Pair.of(params.getFirst(), params.get(1));
                    })
                    .filter(p -> p.getKey().equals(SamlProtocolConstants.PARAMETER_ENTITY_ID))
                    .map(Pair::getValue)
                    .map(EncodingUtils::urlDecode)
                    .findFirst();
                LOGGER.debug("Found entity id as part of request url [{}]", paramRequest);
                return paramRequest;
            }
        } catch (final Throwable e) {
            LoggingUtils.error(LOGGER, e);
        }
        LOGGER.trace("Unable to locate entity id for [{}]", service);
        return Optional.empty();
    }
Method attempts to resolve the service from the entityId parameter.  If present, an attempt is made
to find a service corresponding to the entityId in the Service Registry.  If a service is not resolved from
a passed entity id, the service= parameter of the request will be returned instead.  This is usually the
callback url to the external Shibboleth IdP.

@param service the provided service by the caller
@return - the resolved service.
support/cas-server-support-shibboleth/src/main/java/org/apereo/cas/support/saml/ShibbolethIdPEntityIdAuthenticationServiceSelectionStrategy.java