KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jsmtpd > plugins > inputIPFilters > BlackList


1 /*
2  *
3  * Jsmtpd, Java SMTP daemon
4  * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  */

21 package org.jsmtpd.plugins.inputIPFilters;
22
23 import java.net.InetAddress JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.jsmtpd.core.common.PluginInitException;
29 import org.jsmtpd.core.common.PluginStore;
30 import org.jsmtpd.core.common.acl.IACL;
31 import org.jsmtpd.core.common.inputIPFilter.IFilterIP;
32
33 /**
34  * TODO : add a temporary map, read it from a file on init, write it to a file on shutdown
35  * @author Jean-Francois POUX
36  */

37 public class BlackList implements IFilterIP {
38
39     private List JavaDoc<String JavaDoc> blacklist = new ArrayList JavaDoc<String JavaDoc>();
40     private IACL acl = null;
41     private boolean bypassLocal = false;
42
43     public boolean checkIP(InetAddress JavaDoc input) {
44         String JavaDoc check = input.getHostAddress();
45         if (bypassLocal && acl.isValidRelay(check)) // don't check local IPS
46
return true;
47         for (Iterator JavaDoc<String JavaDoc> iter = blacklist.iterator(); iter.hasNext();) {
48             String JavaDoc element = iter.next();
49             if (check.equals(element))
50                 return false;
51         }
52         return true;
53     }
54
55     public String JavaDoc getPluginName() {
56
57         
58         return "Simple IP blacklist for Jsmtpd";
59     }
60
61     public void initPlugin() throws PluginInitException {
62         acl = PluginStore.getInstance().getAcl();
63         if (acl == null)
64             throw new PluginInitException();
65     }
66
67     public void shutdownPlugin() {
68     }
69
70     public void setBypassLocal(boolean b) {
71         bypassLocal = b;
72     }
73
74     public void setBlacklistedIP(String JavaDoc ip) {
75         blacklist.add(ip);
76     }
77
78 }
Popular Tags