@Override
    public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
        val request = (HttpServletRequest) req;
        val response = (HttpServletResponse) res;
        val servletPath = StringUtils.prependIfMissing(request.getServletPath(), "/");
        if (isValidServletPath(servletPath)) {
            val tenantDefinitions = tenantExtractor.getTenantsManager().findTenants();
            for (val tenantDefinition : tenantDefinitions) {
                val bindingContext = tenantDefinition.bindProperties();
                if (bindingContext.isBound()) {
                    val tenantHostname = extractTenantHost(bindingContext);
                    if (StringUtils.equalsIgnoreCase(request.getServerName(), tenantHostname)) {
                        val dispatch = "/tenants/" + tenantDefinition.getId() + servletPath;
                        LOGGER.info("Routing request [{}] to tenant [{}] at [{}]", request.getRequestURI(), tenantDefinition.getId(), dispatch);
                        val dispatcher = request.getRequestDispatcher(dispatch);
                        dispatcher.forward(request, response);
                        return;
                    }
                }
            }
        }
        chain.doFilter(request, response);
    }
This is {@link TenantRoutingFilter}.

@author Misagh Moayyed
@since 7.3.0
core/cas-server-core-multitenancy/src/main/java/org/apereo/cas/multitenancy/TenantRoutingFilter.java