01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License. For additional information regarding
15: * copyright in this work, please see the NOTICE file in the top level
16: * directory of this distribution.
17: */
18:
19: package org.apache.roller.ui.core.filters;
20:
21: import java.io.IOException;
22: import javax.servlet.Filter;
23: import javax.servlet.FilterChain;
24: import javax.servlet.FilterConfig;
25: import javax.servlet.ServletException;
26: import javax.servlet.ServletRequest;
27: import javax.servlet.ServletResponse;
28: import javax.servlet.http.HttpServletRequest;
29: import javax.servlet.http.HttpServletResponse;
30: import org.apache.commons.logging.Log;
31: import org.apache.commons.logging.LogFactory;
32: import org.apache.roller.util.IPBanList;
33:
34: /**
35: * Simple IP restriction filter. Denied clients get a 404 reponse.
36: *
37: * @web.filter name="IPBanFilter"
38: */
39: public class IPBanFilter implements Filter {
40:
41: private static Log log = LogFactory.getLog(IPBanFilter.class);
42:
43: public void init(FilterConfig filterConfig) throws ServletException {
44:
45: log.info("INIT IPBanFilter");
46: }
47:
48: public void doFilter(ServletRequest req, ServletResponse res,
49: FilterChain chain) throws IOException, ServletException {
50:
51: HttpServletRequest request = (HttpServletRequest) req;
52: HttpServletResponse response = (HttpServletResponse) res;
53:
54: // check if client is allowed
55: if (IPBanList.getInstance().isBanned(request.getRemoteAddr())) {
56: log.debug("BANNED " + request.getRemoteAddr());
57: response.sendError(HttpServletResponse.SC_NOT_FOUND);
58: return;
59: } else {
60: chain.doFilter(request, response);
61: }
62: }
63:
64: public void destroy() {
65: }
66:
67: }
|