@Test public void accessShouldBeDeniedByDefault() throws Exception { IpFilter filter = new IpFilter(); HttpServletRequest request = createNiceMock(HttpServletRequest.class); expect(request.getRemoteAddr()).andReturn("192.168.42.42"); replay(request); assertFalse(filter.isAccessAllowed(request, null, null)); verify(request); }
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { String remoteIp = getHostFromRequest(request); for (IpAddressMatcher matcher : deniedIpMatchers) { if (matcher.matches(remoteIp)) { return false; } } for (String ip : ipSource.getDeniedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return false; } } for (IpAddressMatcher matcher : authorizedIpMatchers) { if (matcher.matches(remoteIp)) { return true; } } for (String ip : ipSource.getAuthorizedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return true; } } return false; }
IpFilter extends AuthorizationFilter { protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { String remoteIp = getHostFromRequest(request); for (IpAddressMatcher matcher : deniedIpMatchers) { if (matcher.matches(remoteIp)) { return false; } } for (String ip : ipSource.getDeniedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return false; } } for (IpAddressMatcher matcher : authorizedIpMatchers) { if (matcher.matches(remoteIp)) { return true; } } for (String ip : ipSource.getAuthorizedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return true; } } return false; } }
IpFilter extends AuthorizationFilter { protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { String remoteIp = getHostFromRequest(request); for (IpAddressMatcher matcher : deniedIpMatchers) { if (matcher.matches(remoteIp)) { return false; } } for (String ip : ipSource.getDeniedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return false; } } for (IpAddressMatcher matcher : authorizedIpMatchers) { if (matcher.matches(remoteIp)) { return true; } } for (String ip : ipSource.getAuthorizedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return true; } } return false; }  }
IpFilter extends AuthorizationFilter { protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { String remoteIp = getHostFromRequest(request); for (IpAddressMatcher matcher : deniedIpMatchers) { if (matcher.matches(remoteIp)) { return false; } } for (String ip : ipSource.getDeniedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return false; } } for (IpAddressMatcher matcher : authorizedIpMatchers) { if (matcher.matches(remoteIp)) { return true; } } for (String ip : ipSource.getAuthorizedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return true; } } return false; }  void setAuthorizedIps(String authorizedIps); void setDeniedIps(String deniedIps); void setIpSource(IpSource source); String getHostFromRequest(ServletRequest request); }
IpFilter extends AuthorizationFilter { protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { String remoteIp = getHostFromRequest(request); for (IpAddressMatcher matcher : deniedIpMatchers) { if (matcher.matches(remoteIp)) { return false; } } for (String ip : ipSource.getDeniedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return false; } } for (IpAddressMatcher matcher : authorizedIpMatchers) { if (matcher.matches(remoteIp)) { return true; } } for (String ip : ipSource.getAuthorizedIps()) { IpAddressMatcher matcher = new IpAddressMatcher(ip); if (matcher.matches(remoteIp)) { return true; } } return false; }  void setAuthorizedIps(String authorizedIps); void setDeniedIps(String deniedIps); void setIpSource(IpSource source); String getHostFromRequest(ServletRequest request);  }