--- experimental/server/ACL/ACLTest.java 2001/12/20 00:59:54 1.2 +++ experimental/server/ACL/ACLTest.java 2002/01/08 13:31:34 1.7 @@ -9,15 +9,59 @@ class ACLTest { // add some test rules acl.add(ACL.ALLOW, "*.ukc.ac.uk"); - acl.add(ACL.ALLOW, "129.12.*"); + acl.add(ACL.ALLOW, "129.12.*.*"); acl.add(ACL.ALLOW, "*.bishnet.net"); acl.add(ACL.ALLOW, "192.168.*"); + acl.add(ACL.ALLOW, "192.168.*.*"); + acl.add(ACL.ALLOW, "one.two.three.four.five.six.*"); + acl.add(ACL.ALLOW, "192.129.12.*.*"); + acl.add(ACL.ALLOW, "129.12.*"); + acl.add(ACL.ALLOW, "129.12.4"); + acl.add(ACL.ALLOW, "129.*"); + acl.add(ACL.ALLOW, "129*"); + acl.add(ACL.ALLOW, "*.*.3.1"); + acl.add(ACL.ALLOW, "*.3.1"); + acl.add(ACL.ALLOW, "*.3.*"); + acl.add(ACL.ALLOW, "*3.1"); + acl.add(ACL.ALLOW, "*"); + acl.add(ACL.ALLOW, ""); // not really needed if we default to deny :) //acl.add(ACL.DENY, "*"); - // dump our ACL to the console - System.out.println(acl.getStringACL()); + // dump our ACL to the console before serialization + System.out.println("BEFORE: " + acl); + // name for our serialized ACL + String aclFilename = "aclfile"; + + // write out our ACL to a file + try { + ObjectOutputStream ostream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(aclFilename))); + ostream.writeObject(acl); + ostream.flush(); + ostream.close(); + } + catch (Exception e) { + System.out.println("exception: " + e); + e.printStackTrace(); + System.exit(1); + } + + // and read it back in :) + try { + ObjectInputStream istream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(aclFilename))); + acl = (ACL) istream.readObject(); + istream.close(); + } + catch (Exception e) { + System.out.println("exception: " + e); + e.printStackTrace(); + System.exit(1); + } + + // dump our ACL to the console after serialization + System.out.println("AFTER: " + acl); + // 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")); @@ -25,15 +69,21 @@ class ACLTest { System.out.println("192.168.1.1: " + acl.check("192.168.1.1")); // setup an ACLServerSocket putting our ACL in + // and an ACLDatagramSocket (which we'll test better later) ACLServerSocket ss = null; + ACLDatagramSocket ds = null; try { ss = new ACLServerSocket(acl, 1337); + ds = new ACLDatagramSocket(acl, 1337); } catch(IOException e) { System.out.println("exception: " + e); e.printStackTrace(); System.exit(1); } + + System.out.println(ss); + System.out.println(ds); // start listening // valid connections (allowed by ACL) will get a message sent back