//# 0 errors, 83 messages
//#
/*
    //#IPBanFilter.java:1:1: class: org.apache.roller.weblogger.ui.core.filters.IPBanFilter
* Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  The ASF licenses this file to You
* under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.  For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/

package org.apache.roller.weblogger.ui.core.filters;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.util.IPBanList;


/**
 * Simple IP restriction filter.  Denied clients get a 404 reponse.
 *
 * @web.filter name="IPBanFilter"
 */
public class IPBanFilter implements Filter {
    //#IPBanFilter.java:40: method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.org.apache.roller.weblogger.ui.core.filters.IPBanFilter()
    //#IPBanFilter.java:40: end of method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.org.apache.roller.weblogger.ui.core.filters.IPBanFilter()
    
    private static Log log = LogFactory.getLog(IPBanFilter.class);
    //#IPBanFilter.java:42: method: org.apache.roller.weblogger.ui.core.filters.IPBanFilter.org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init
    //#IPBanFilter.java:42: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.IPBanFilter
    //#    method: org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/filters/IPBanFilter]
    //#output(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Dispatch_Table.destroy()V
    //#output(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Dispatch_Table.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V
    //#output(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Dispatch_Table.init(Ljavax/servlet/FilterConfig;)V
    //#output(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): log
    //#post(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/core/filters/IPBanFilter] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Dispatch_Table.destroy()V == &destroy
    //#post(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Dispatch_Table.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V == &doFilter
    //#post(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): __Dispatch_Table.init(Ljavax/servlet/FilterConfig;)V == &init
    //#post(org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init): init'ed(log)
    //#IPBanFilter.java:42: end of method: org.apache.roller.weblogger.ui.core.filters.IPBanFilter.org.apache.roller.weblogger.ui.core.filters.IPBanFilter__static_init
    
    
    public void init(FilterConfig filterConfig) throws ServletException {
        
        log.info("INIT IPBanFilter");
    //#IPBanFilter.java:47: method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.init(FilterConfig)
    //#IPBanFilter.java:47: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:info(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.IPBanFilter
    //#    method: void init(FilterConfig)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:info(Object)
    //#input(void init(FilterConfig)): log
    //#pre[1] (void init(FilterConfig)): log != null
    }
    //#IPBanFilter.java:48: end of method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.init(FilterConfig)
    
    
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
            throws IOException, ServletException {
        
        HttpServletRequest request = (HttpServletRequest) req;
    //#IPBanFilter.java:54: method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): " banned ips loaded"._tainted
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): "BANNED "._tainted
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): chain
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): log
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList$ModifiedFile.__Descendant_Table[org/apache/roller/weblogger/util/IPBanList$ModifiedFile]
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList$ModifiedFile.__Descendant_Table[others]
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList$ModifiedFile.__Dispatch_Table.clearChanged()V
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList$ModifiedFile.__Dispatch_Table.hasChanged()Z
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.__Descendant_Table[org/apache/roller/weblogger/util/IPBanList]
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.__Descendant_Table[others]
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.__Dispatch_Table.isBanned(Ljava/lang/String;)Z
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.__Tag
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIps
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.__Tag
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.myLastModified
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.log
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): req
    //#input(void doFilter(ServletRequest, ServletResponse, FilterChain)): res
    //#output(void doFilter(ServletRequest, ServletResponse, FilterChain)): new HashSet(loadBannedIps#1) num objects
    //#output(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIps
    //#output(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.myLastModified
    //#new obj(void doFilter(ServletRequest, ServletResponse, FilterChain)): new HashSet(loadBannedIps#1)
    //#pre[5] (void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance != null
    //#pre[6] (void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.__Tag == org/apache/roller/weblogger/util/IPBanList
    //#pre[7] (void doFilter(ServletRequest, ServletResponse, FilterChain)): init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile)
    //#pre[10] (void doFilter(ServletRequest, ServletResponse, FilterChain)): req != null
    //#pre[1] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) chain != null
    //#pre[2] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) log != null
    //#pre[3] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIps)
    //#pre[4] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.myLastModified)
    //#pre[8] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.__Tag == org/apache/roller/weblogger/util/IPBanList$ModifiedFile
    //#pre[9] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) org/apache/roller/weblogger/util/IPBanList.log != null
    //#pre[11] (void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) res != null
    //#post(void doFilter(ServletRequest, ServletResponse, FilterChain)): org/apache/roller/weblogger/util/IPBanList.instance.bannedIps == One-of{old org/apache/roller/weblogger/util/IPBanList.instance.bannedIps, &new HashSet(loadBannedIps#1)}
    //#post(void doFilter(ServletRequest, ServletResponse, FilterChain)): (soft) init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIps)
    //#post(void doFilter(ServletRequest, ServletResponse, FilterChain)): init'ed(org/apache/roller/weblogger/util/IPBanList.instance.bannedIpsFile.myLastModified)
    //#post(void doFilter(ServletRequest, ServletResponse, FilterChain)): new HashSet(loadBannedIps#1) num objects <= 1
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:loadBannedIpsIfNeeded
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.util.Set:contains
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:org.apache.roller.weblogger.util.IPBanList$ModifiedFile:lastModified
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.lang.Throwable:__curr_excep_obj
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:loadBannedIps
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.util.HashSet
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.io.FileReader
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.io.BufferedReader
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.io.BufferedReader:readLine
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.util.HashSet:add
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.io.BufferedReader:close
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:java.util.Set:size
    //#unanalyzed(void doFilter(ServletRequest, ServletResponse, FilterChain)): Effects-of-calling:org.apache.commons.logging.Log:info
        HttpServletResponse response = (HttpServletResponse) res;
        
        // check if client is allowed
        if(IPBanList.getInstance().isBanned(request.getRemoteAddr())) {
            log.debug("BANNED "+request.getRemoteAddr());
    //#IPBanFilter.java:59: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:debug(Object)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.core.filters.IPBanFilter
    //#    method: void doFilter(ServletRequest, ServletResponse, FilterChain)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:debug(Object)
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        } else {
            chain.doFilter(request, response);
        }
    }
    //#IPBanFilter.java:65: end of method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.doFilter(ServletRequest, ServletResponse, FilterChain)
    
    
    public void destroy() {}
    //#IPBanFilter.java:68: method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.destroy()
    //#IPBanFilter.java:68: end of method: void org.apache.roller.weblogger.ui.core.filters.IPBanFilter.destroy()
    
}
    //#IPBanFilter.java:: end of class: org.apache.roller.weblogger.ui.core.filters.IPBanFilter
