@Test public void testFilterRejectsRemoteAddressesThatAreNotLocal() throws IOException, ServletException { mockRequest.setRemoteAddr("74.125.227.84"); filter.doFilter(mockRequest, mockResponse, mockFilterChain); assertThat(mockResponse.getStatus(), is(HttpServletResponse.SC_FORBIDDEN)); }
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!isAllowed(request.getRemoteAddr())) { denyRequest(request, response); return; } } chain.doFilter(req, res); }
LocalAddrFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!isAllowed(request.getRemoteAddr())) { denyRequest(request, response); return; } } chain.doFilter(req, res); } }
LocalAddrFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!isAllowed(request.getRemoteAddr())) { denyRequest(request, response); return; } } chain.doFilter(req, res); }  }
LocalAddrFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!isAllowed(request.getRemoteAddr())) { denyRequest(request, response); return; } } chain.doFilter(req, res); }  int getDenyStatus(); void setDenyStatus(int denyStatus); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); @Override void destroy(); static String getLocalAddr(); }
LocalAddrFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (!isAllowed(request.getRemoteAddr())) { denyRequest(request, response); return; } } chain.doFilter(req, res); }  int getDenyStatus(); void setDenyStatus(int denyStatus); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); @Override void destroy(); static String getLocalAddr();  }