1 17 18 package org.apache.james.transport.matchers; 19 20 import org.apache.james.util.NetMatcher; 21 import javax.mail.MessagingException ; 22 import java.util.StringTokenizer ; 23 import java.util.Collection ; 24 25 45 public abstract class AbstractNetworkMatcher extends org.apache.mailet.GenericMatcher { 46 47 51 private NetMatcher authorizedNetworks = null; 52 53 public void init() throws MessagingException { 54 Collection nets = allowedNetworks(); 55 if (nets != null) { 56 authorizedNetworks = new NetMatcher() { 57 protected void log(String s) { 58 AbstractNetworkMatcher.this.log(s); 59 } 60 }; 61 authorizedNetworks.initInetNetworks(allowedNetworks()); 62 log("Authorized addresses: " + authorizedNetworks.toString()); 63 } 64 } 65 66 protected Collection allowedNetworks() { 67 Collection networks = null; 68 if (getCondition() != null) { 69 StringTokenizer st = new StringTokenizer (getCondition(), ", ", false); 70 networks = new java.util.ArrayList (); 71 while (st.hasMoreTokens()) networks.add(st.nextToken()); 72 } 73 return networks; 74 } 75 76 protected boolean matchNetwork(java.net.InetAddress addr) { 77 return authorizedNetworks == null ? false : authorizedNetworks.matchInetNetwork(addr); 78 } 79 80 protected boolean matchNetwork(String addr) { 81 return authorizedNetworks == null ? false : authorizedNetworks.matchInetNetwork(addr); 82 } 83 } 84 | Popular Tags |