1 14 15 package org.quickserver.util.xmlreader; 16 17 import java.util.*; 18 import java.net.*; 19 import java.io.*; 20 import java.util.logging.*; 21 22 28 public class AccessConstraintConfig implements Serializable { 29 private static Logger logger = Logger.getLogger(AccessConstraintConfig.class.getName()); 30 31 private IpFilterConfig ipFilterConfig; 32 33 34 38 public IpFilterConfig getIpFilterConfig() { 39 return ipFilterConfig; 40 } 41 46 public void setIpFilterConfig(IpFilterConfig ipFilterConfig) { 47 this.ipFilterConfig = ipFilterConfig; 48 } 49 50 53 public String toXML(String pad) { 54 if(pad==null) pad=""; 55 StringBuffer sb = new StringBuffer (); 56 57 sb.append(pad+"<access-constraint>\n"); 58 if(getIpFilterConfig()!=null) 59 sb.append(getIpFilterConfig().toXML(pad+"\t")); 60 sb.append(pad+"</access-constraint>\n"); 61 return sb.toString(); 62 } 63 64 69 public void checkAccept(Socket socket) { 70 if(socket==null || ipFilterConfig==null || ipFilterConfig.getEnable()==false) 71 return; 72 String remoteIp = socket.getInetAddress().getHostAddress(); 73 boolean accessFlag = ipFilterConfig.getAllowAccess()==true; 74 75 if(ipFilterConfig.getIpCollection().contains(remoteIp)!=accessFlag) { 76 try { 77 socket.close(); 78 } catch(IOException e) { 79 logger.warning("IOException : "+e.getMessage()); 80 } 81 socket = null; 82 throw new SecurityException ("Accept denied from "+remoteIp); 83 } 84 } 85 } 86 | Popular Tags |