code:     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
              throws ServletException, IOException {
  
          String identityZoneId = request.getHeader(HEADER);
          if (StringUtils.hasText(identityZoneId)) {
              if (!isAuthorizedToSwitchToIdentityZone(identityZoneId)) {
                  response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not authorized to switch to IdentityZone with id "+identityZoneId);
                  return;
              }
              IdentityZone originalIdentityZone = IdentityZoneHolder.get();
              try {
  
                  IdentityZone identityZone = null;
                  try {
                      identityZone = dao.retrieve(identityZoneId);
                  } catch (ZoneDoesNotExistsException ex) {
                  } catch (EmptyResultDataAccessException ex) {
                  } catch (Exception ex) {
                      throw ex;
                  }
                  if (identityZone == null) {
                      response.sendError(HttpServletResponse.SC_NOT_FOUND, "Identity zone with id "+identityZoneId+" does not exist");
                      return;
                  }
                  stripScopesFromAuthentication(identityZoneId, request);
                  IdentityZoneHolder.set(identityZone);
                  filterChain.doFilter(request, response);
              } finally {
                  IdentityZoneHolder.set(originalIdentityZone);
              }
          } else {
              filterChain.doFilter(request, response);
          }
      }
  