code: protected static Optional<String> getEntityIdAsParameter(final Service service) {
          try {
              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());
              }
              val request = WebUtils.getHttpServletRequestFromExternalWebflowContext();
              if (request != null && StringUtils.isNotBlank(request.getQueryString())) {
                  val query = request.getQueryString().split("&");
                  val paramRequest = Arrays.stream(query)
                      .map(p -> {
                          var params = Splitter.on("=").splitToList(p);
                          return Pair.of(params.get(0), 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 Exception e) {
              LOGGER.error(e.getMessage(), e);
          }
          return Optional.empty();
      }
docs: Gets entity id as parameter.
  
  @param service the service
  @return the entity id as parameter