ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/ACL/ACLTest.java
(Generate patch)

Comparing experimental/server/ACL/ACLTest.java (file contents):
Revision 1.1 by tdb, Wed Dec 19 23:43:27 2001 UTC vs.
Revision 1.7 by tdb, Tue Jan 8 13:31:34 2002 UTC

# Line 1 | Line 1
1 + import java.io.*;
2 + import java.net.*;
3 +
4   class ACLTest {
5      
6      public static void main(String args[]) {
7 +        // setup ACL defaulting to DENY
8          ACL acl = new ACL(ACL.DENY);
9          
10 +        // add some test rules
11          acl.add(ACL.ALLOW, "*.ukc.ac.uk");
12 +        acl.add(ACL.ALLOW, "129.12.*.*");
13 +        acl.add(ACL.ALLOW, "*.bishnet.net");
14 +        acl.add(ACL.ALLOW, "192.168.*");
15 +        acl.add(ACL.ALLOW, "192.168.*.*");
16 +        acl.add(ACL.ALLOW, "one.two.three.four.five.six.*");
17 +        acl.add(ACL.ALLOW, "192.129.12.*.*");
18          acl.add(ACL.ALLOW, "129.12.*");
19 +        acl.add(ACL.ALLOW, "129.12.4");
20 +        acl.add(ACL.ALLOW, "129.*");
21 +        acl.add(ACL.ALLOW, "129*");
22 +        acl.add(ACL.ALLOW, "*.*.3.1");
23 +        acl.add(ACL.ALLOW, "*.3.1");
24 +        acl.add(ACL.ALLOW, "*.3.*");
25 +        acl.add(ACL.ALLOW, "*3.1");
26 +        acl.add(ACL.ALLOW, "*");
27 +        acl.add(ACL.ALLOW, "");
28          // not really needed if we default to deny :)
29 <        acl.add(ACL.DENY, "*");
29 >        //acl.add(ACL.DENY, "*");
30          
31 <        System.out.println(acl.getACL());
31 >        // dump our ACL to the console before serialization
32 >        System.out.println("BEFORE: " + acl);
33          
34 +        // name for our serialized ACL
35 +        String aclFilename = "aclfile";
36 +        
37 +        // write out our ACL to a file
38 +        try {
39 +            ObjectOutputStream ostream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(aclFilename)));
40 +            ostream.writeObject(acl);
41 +            ostream.flush();
42 +            ostream.close();
43 +        }
44 +        catch (Exception e) {
45 +            System.out.println("exception: " + e);
46 +            e.printStackTrace();
47 +            System.exit(1);
48 +        }
49 +        
50 +        // and read it back in :)
51 +        try {
52 +            ObjectInputStream istream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(aclFilename)));
53 +            acl = (ACL) istream.readObject();
54 +            istream.close();
55 +        }
56 +        catch (Exception e) {
57 +            System.out.println("exception: " + e);
58 +            e.printStackTrace();
59 +            System.exit(1);
60 +        }
61 +        
62 +        // dump our ACL to the console after serialization
63 +        System.out.println("AFTER: " + acl);
64 +        
65 +        // run a few tests
66          System.out.println("killigrew.ukc.ac.uk: " + acl.check("killigrew.ukc.ac.uk"));
67          System.out.println("129.12.41.13: " + acl.check("129.12.41.13"));
68          System.out.println("kruskal.18hp.net: " + acl.check("kruskal.18hp.net"));
69          System.out.println("192.168.1.1: " + acl.check("192.168.1.1"));
70 +        
71 +        // setup an ACLServerSocket putting our ACL in
72 +        // and an ACLDatagramSocket (which we'll test better later)
73 +        ACLServerSocket ss = null;
74 +        ACLDatagramSocket ds = null;
75 +        try {
76 +            ss = new ACLServerSocket(acl, 1337);
77 +            ds = new ACLDatagramSocket(acl, 1337);
78 +        }
79 +        catch(IOException e) {
80 +            System.out.println("exception: " + e);
81 +            e.printStackTrace();
82 +            System.exit(1);
83 +        }
84 +        
85 +        System.out.println(ss);
86 +        System.out.println(ds);
87 +        
88 +        // start listening
89 +        // valid connections (allowed by ACL) will get a message sent back
90 +        while(true) {
91 +            try {
92 +                Socket s = ss.accept();
93 +                PrintWriter writer = new PrintWriter(s.getOutputStream(), true);
94 +                writer.println("Connection suceeded from: " + s.getInetAddress().getHostName());
95 +                writer.println("Closing in 5 seconds");
96 +                try { Thread.sleep(5000); } catch(Exception ee) {}
97 +                writer.close();
98 +                s.close();
99 +            }
100 +            catch(IOException e) {
101 +                System.out.println("exception: " + e);
102 +                e.printStackTrace();
103 +                System.exit(1);
104 +            }
105 +        }
106      }
107      
108   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines