ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/ACLServerSocket.java
Revision: 1.1
Committed: Tue Jan 8 14:24:28 2002 UTC (22 years, 3 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Log Message:
Merged ACL code into the util package.
This code was previously in CVS:experimental/server/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 java.net.ServerSocket;
6     import java.net.Socket;
7     import java.net.InetAddress;
8     import java.io.IOException;
9    
10     /**
11     * Access Control List ServerSocket wrapper. Used
12     * to wrap a ServerSocket with an ACL, whilst extending
13     * ServerSocket to make integration into code easier.
14     * Once the ACL has been set, accept() can be used exactly
15     * as it would be with a ServerSocket.
16     *
17     * @author $Author: tdb $
18     * @version $Id: ACLServerSocket.java,v 1.3 2001/12/31 02:57:00 tdb Exp $
19     */
20     public class ACLServerSocket extends ServerSocket {
21    
22     //---FINAL ATTRIBUTES---
23    
24     /**
25     * The current CVS revision of this class
26     */
27     public static final String REVISION = "$Revision: 1.3 $";
28    
29     //---STATIC METHODS---
30    
31     //---CONSTRUCTORS---
32    
33     /**
34     * See relevant ServerSocket constructor.
35     */
36     public ACLServerSocket(int port) throws IOException {
37     super(port);
38     setACL(new ACL());
39     }
40    
41     /**
42     * See relevant ServerSocket constructor.
43     */
44     public ACLServerSocket(int port, int backlog) throws IOException {
45     super(port, backlog);
46     setACL(new ACL());
47     }
48    
49     /**
50     * See relevant ServerSocket constructor.
51     */
52     public ACLServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
53     super(port, backlog, bindAddr);
54     setACL(new ACL());
55     }
56    
57     /**
58     * See relevant ServerSocket constructor, and
59     * sets the default acl.
60     */
61     public ACLServerSocket(ACL acl, int port) throws IOException {
62     super(port);
63     setACL(acl);
64     }
65    
66     /**
67     * See relevant ServerSocket constructor, and
68     * sets the default acl.
69     */
70     public ACLServerSocket(ACL acl, int port, int backlog) throws IOException {
71     super(port, backlog);
72     setACL(acl);
73     }
74    
75     /**
76     * See relevant ServerSocket constructor, and
77     * sets the default acl.
78     */
79     public ACLServerSocket(ACL acl, int port, int backlog, InetAddress bindAddr) throws IOException {
80     super(port, backlog, bindAddr);
81     setACL(acl);
82     }
83    
84     //---PUBLIC METHODS---
85    
86     /**
87     * Essentially has the same behaviour as the
88     * ServerSocket.accept() method, except won't
89     * return a Socket unless it is permitted by
90     * the ACL. Closes Socket's immediately that
91     * aren't permitted by the ACL.
92     */
93     public Socket accept() throws IOException {
94     while(true) {
95     Socket s = super.accept();
96     if(_acl.check(s.getInetAddress())) {
97     return s;
98     }
99     else {
100     s.close();
101     }
102     }
103     }
104    
105     /**
106     * Set the ACL at any point in the operation
107     * of the ServerSocket.
108     *
109     * @param acl the new ACL to apply
110     */
111     public void setACL(ACL acl) {
112     _acl = acl;
113     }
114    
115     /**
116     * Overrides the {@link java.lang.Object#toString() Object.toString()}
117     * method to provide clean logging (every class should have this).
118     *
119     * This uses the uk.org.iscream.cms.server.util.FormatName class
120     * to format the toString()
121     *
122     * @return the name of this class and its CVS revision
123     */
124     public String toString() {
125     return FormatName.getName(
126     _name,
127     getClass().getName(),
128     REVISION) + ":" + super.toString();
129     }
130    
131     //---PRIVATE METHODS---
132    
133     //---ACCESSOR/MUTATOR METHODS---
134    
135     //---ATTRIBUTES---
136    
137     /**
138     * This is the friendly identifier of the
139     * component this class is running in.
140     * eg, a Filter may be called "filter1",
141     * If this class does not have an owning
142     * component, a name from the configuration
143     * can be placed here. This name could also
144     * be changed to null for utility classes.
145     */
146     private String _name = null;
147    
148     /**
149     * The ACL used by this ACLServerSocket.
150     */
151     private ACL _acl;
152    
153     //---STATIC ATTRIBUTES---
154    
155     //---INNER CLASSES---
156    
157     }