ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/ACL/ACLServerSocket.java
Revision: 1.1
Committed: Wed Dec 19 23:43:27 2001 UTC (22 years, 4 months ago) by tdb
Branch: MAIN
Log Message:
Initial checkin of ACL code for i-scream server. At present it should allow for
ServerSocket's to be wrapped up with an access control list. Very simple to
use, will javadoc sometime soon. Essentially construct a ACLServerSocket
instead of a ServerSocket, then set an ACL (defaults to open ACL). Then it
can be used as a ServerSocket due to inheritance, and will only return from
the allow() method if the connecting Socket is permitted by the ACL.

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2     //package uk.org.iscream.cms.server.util;
3    
4     //---IMPORTS---
5     import uk.org.iscream.cms.server.util.*;
6     import java.net.ServerSocket;
7     import java.net.Socket;
8     import java.net.InetAddress;
9     import java.io.IOException;
10    
11     /**
12     * Access Control List ServerSocket wrapper
13     *
14     * @author $Author$
15     * @version $Id$
16     */
17     public class ACLServerSocket extends ServerSocket {
18    
19     //---FINAL ATTRIBUTES---
20    
21     /**
22     * The current CVS revision of this class
23     */
24     public static final String REVISION = "$Revision$";
25    
26     //---STATIC METHODS---
27    
28     //---CONSTRUCTORS---
29    
30     public ACLServerSocket(int port) throws IOException {
31     super(port);
32     setACL(new ACL());
33     }
34    
35     public ACLServerSocket(int port, int backlog) throws IOException {
36     super(port, backlog);
37     setACL(new ACL());
38     }
39    
40     public ACLServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
41     super(port, backlog, bindAddr);
42     setACL(new ACL());
43     }
44    
45     public ACLServerSocket(ACL acl, int port) throws IOException {
46     super(port);
47     setACL(acl);
48     }
49    
50     public ACLServerSocket(ACL acl, int port, int backlog) throws IOException {
51     super(port, backlog);
52     setACL(acl);
53     }
54    
55     public ACLServerSocket(ACL acl, int port, int backlog, InetAddress bindAddr) throws IOException {
56     super(port, backlog, bindAddr);
57     setACL(acl);
58     }
59    
60     //---PUBLIC METHODS---
61    
62     public Socket accept() throws IOException {
63     while(true) {
64     Socket s = super.accept();
65     if(_acl.check(s.getInetAddress())) {
66     return s;
67     }
68     else {
69     s.close();
70     }
71     }
72     }
73    
74     public void setACL(ACL acl) {
75     _acl = acl;
76     }
77    
78     /**
79     * Overrides the {@link java.lang.Object#toString() Object.toString()}
80     * method to provide clean logging (every class should have this).
81     *
82     * This uses the uk.org.iscream.cms.server.util.FormatName class
83     * to format the toString()
84     *
85     * @return the name of this class and its CVS revision
86     */
87     public String toString() {
88     return FormatName.getName(
89     _name,
90     getClass().getName(),
91     REVISION);
92     }
93    
94     //---PRIVATE METHODS---
95    
96     //---ACCESSOR/MUTATOR METHODS---
97    
98     //---ATTRIBUTES---
99    
100     /**
101     * This is the friendly identifier of the
102     * component this class is running in.
103     * eg, a Filter may be called "filter1",
104     * If this class does not have an owning
105     * component, a name from the configuration
106     * can be placed here. This name could also
107     * be changed to null for utility classes.
108     */
109     private String _name = null;
110    
111     private ACL _acl;
112    
113     //---STATIC ATTRIBUTES---
114    
115     //---INNER CLASSES---
116    
117     }