KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > filters > IPBanFilter


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 JavaDoc;
22 import javax.servlet.Filter JavaDoc;
23 import javax.servlet.FilterChain JavaDoc;
24 import javax.servlet.FilterConfig JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.ServletRequest JavaDoc;
27 import javax.servlet.ServletResponse JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.roller.util.IPBanList;
33
34
35 /**
36  * Simple IP restriction filter. Denied clients get a 404 reponse.
37  *
38  * @web.filter name="IPBanFilter"
39  */

40 public class IPBanFilter implements Filter JavaDoc {
41     
42     private static Log log = LogFactory.getLog(IPBanFilter.class);
43     
44     
45     public void init(FilterConfig JavaDoc filterConfig) throws ServletException JavaDoc {
46         
47         log.info("INIT IPBanFilter");
48     }
49     
50     
51     public void doFilter(ServletRequest JavaDoc req, ServletResponse JavaDoc res, FilterChain JavaDoc chain)
52             throws IOException JavaDoc, ServletException JavaDoc {
53         
54         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) req;
55         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) res;
56         
57         // check if client is allowed
58
if(IPBanList.getInstance().isBanned(request.getRemoteAddr())) {
59             log.debug("BANNED "+request.getRemoteAddr());
60             response.sendError(HttpServletResponse.SC_NOT_FOUND);
61             return;
62         } else {
63             chain.doFilter(request, response);
64         }
65     }
66     
67     
68     public void destroy() {}
69     
70 }
71
Popular Tags