class JSCsrfGuardFilter implements Filter {

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest)request;
        String uaHeader = httpRequest.getHeader(HTTP.USER_AGENT);
        boolean isVisualizeRequest = httpRequest.getHeader(CrossDomainCommunicationFilter.X_REMOTE_DOMAIN) != null;

        // !isVisualizeRequest - we do not need to protect Visualize per domain white listing that we implement.
        // isUserAgentProtected() - determines if the reques is coming from a supported browser.
        if (!isVisualizeRequest && isUserAgentProtected(uaHeader)) {
            if (log.isDebugEnabled()) {
                log.debug("Checking for CSRF token in request " + ((HttpServletRequest) request).getRequestURI() + " user-agent: " + uaHeader);
            }

            csrfGuardFilter.doFilter(request, response, filterChain);
        } else {
            filterChain.doFilter(request, response);
        }
	}

}