ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/ACL/ACLTest.java
Revision: 1.2
Committed: Thu Dec 20 00:59:54 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.1: +41 -2 lines
Log Message:
Fully commented, and further testing in the Socket environment. Probably
ready to integrate into the main source tree under the server util package.

File Contents

# Content
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 // not really needed if we default to deny :)
16 //acl.add(ACL.DENY, "*");
17
18 // dump our ACL to the console
19 System.out.println(acl.getStringACL());
20
21 // run a few tests
22 System.out.println("killigrew.ukc.ac.uk: " + acl.check("killigrew.ukc.ac.uk"));
23 System.out.println("129.12.41.13: " + acl.check("129.12.41.13"));
24 System.out.println("kruskal.18hp.net: " + acl.check("kruskal.18hp.net"));
25 System.out.println("192.168.1.1: " + acl.check("192.168.1.1"));
26
27 // setup an ACLServerSocket putting our ACL in
28 ACLServerSocket ss = null;
29 try {
30 ss = new ACLServerSocket(acl, 1337);
31 }
32 catch(IOException e) {
33 System.out.println("exception: " + e);
34 e.printStackTrace();
35 System.exit(1);
36 }
37
38 // start listening
39 // valid connections (allowed by ACL) will get a message sent back
40 while(true) {
41 try {
42 Socket s = ss.accept();
43 PrintWriter writer = new PrintWriter(s.getOutputStream(), true);
44 writer.println("Connection suceeded from: " + s.getInetAddress().getHostName());
45 writer.println("Closing in 5 seconds");
46 try { Thread.sleep(5000); } catch(Exception ee) {}
47 writer.close();
48 s.close();
49 }
50 catch(IOException e) {
51 System.out.println("exception: " + e);
52 e.printStackTrace();
53 System.exit(1);
54 }
55 }
56 }
57
58 }