--- experimental/server/ACL/ACLTest.java 2001/12/19 23:43:27 1.1 +++ experimental/server/ACL/ACLTest.java 2001/12/20 00:59:54 1.2 @@ -1,19 +1,58 @@ +import java.io.*; +import java.net.*; + class ACLTest { public static void main(String args[]) { + // setup ACL defaulting to DENY ACL acl = new ACL(ACL.DENY); + // add some test rules acl.add(ACL.ALLOW, "*.ukc.ac.uk"); acl.add(ACL.ALLOW, "129.12.*"); + acl.add(ACL.ALLOW, "*.bishnet.net"); + acl.add(ACL.ALLOW, "192.168.*"); // not really needed if we default to deny :) - acl.add(ACL.DENY, "*"); + //acl.add(ACL.DENY, "*"); - System.out.println(acl.getACL()); + // dump our ACL to the console + System.out.println(acl.getStringACL()); + // run a few tests System.out.println("killigrew.ukc.ac.uk: " + acl.check("killigrew.ukc.ac.uk")); System.out.println("129.12.41.13: " + acl.check("129.12.41.13")); System.out.println("kruskal.18hp.net: " + acl.check("kruskal.18hp.net")); System.out.println("192.168.1.1: " + acl.check("192.168.1.1")); + + // setup an ACLServerSocket putting our ACL in + ACLServerSocket ss = null; + try { + ss = new ACLServerSocket(acl, 1337); + } + catch(IOException e) { + System.out.println("exception: " + e); + e.printStackTrace(); + System.exit(1); + } + + // start listening + // valid connections (allowed by ACL) will get a message sent back + while(true) { + try { + Socket s = ss.accept(); + PrintWriter writer = new PrintWriter(s.getOutputStream(), true); + writer.println("Connection suceeded from: " + s.getInetAddress().getHostName()); + writer.println("Closing in 5 seconds"); + try { Thread.sleep(5000); } catch(Exception ee) {} + writer.close(); + s.close(); + } + catch(IOException e) { + System.out.println("exception: " + e); + e.printStackTrace(); + System.exit(1); + } + } } } \ No newline at end of file