File Source: IPBanFilter.java
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.weblogger.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.weblogger.util.IPBanList;
33
34
35 /**
36 * Simple IP restriction filter. Denied clients get a 404 reponse.
37 *
38 * @web.filter name="IPBanFilter"
39 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter()
*/
40 public class IPBanFilter implements Filter {
41
/*
P/P * Method: org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init
*
* Postconditions:
* init'ed(log)
*/
42 private static Log log = LogFactory.getLog(IPBanFilter.class);
43
44
45 public void init(FilterConfig filterConfig) throws ServletException {
46
/*
P/P * Method: void init(FilterConfig)
*
* Preconditions:
* log != null
*/
47 log.info("INIT IPBanFilter");
48 }
49
50
51 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
52 throws IOException, ServletException {
53
/*
P/P * Method: void doFilter(ServletRequest, ServletResponse, FilterChain)
*
* Preconditions:
* org/apache/roller/weblogger/util/IPBanList.instance != null
* init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile)
* req != null
* (soft) chain != null
* (soft) log != null
* (soft) init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIps)
* (soft) init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.myLastModified)
* (soft) org/apache/roller/weblogger/util/IPBanList.log != null
* (soft) res != null
*
* Postconditions:
* org/apache/roller/weblogger/util/IPBanList.instance.bannedIps == One-of{old org/apache/roller/weblogger/util/IPBanList.instance.bannedIps, &new HashSet(loadBannedIps#1)}
* (soft) init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIps)
* init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.myLastModified)
* new HashSet(loadBannedIps#1) num objects <= 1
*/
54 HttpServletRequest request = (HttpServletRequest) req;
55 HttpServletResponse response = (HttpServletResponse) 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
/*
P/P * Method: void destroy()
*/
68 public void destroy() {}
69
70 }
SofCheck Inspector Build Version : 2.18479
| IPBanFilter.java |
2009-Jan-02 14:24:54 |
| IPBanFilter.class |
2009-Sep-04 03:12:44 |