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.4
Committed: Wed Feb 5 14:27:58 2003 UTC (21 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.3: +3 -3 lines
Log Message:
Util package has been pulled out of the server. Next step will be to modify
the server and conient (and anything else?) to use this instead. New
package name is uk.org.iscream.cms.util. All the java files were moved with
a repo copy, so they retain their history.

File Contents

# User Rev Content
1 tdb 1.2 /*
2     * i-scream central monitoring system
3 tdb 1.3 * http://www.i-scream.org.uk
4 tdb 1.2 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 tdb 1.1 //---PACKAGE DECLARATION---
22 tdb 1.4 package uk.org.iscream.cms.util;
23 tdb 1.1
24     //---IMPORTS---
25     import java.net.ServerSocket;
26     import java.net.Socket;
27     import java.net.InetAddress;
28     import java.io.IOException;
29    
30     /**
31     * Access Control List ServerSocket wrapper. Used
32     * to wrap a ServerSocket with an ACL, whilst extending
33     * ServerSocket to make integration into code easier.
34     * Once the ACL has been set, accept() can be used exactly
35     * as it would be with a ServerSocket.
36     *
37     * @author $Author: tdb $
38 tdb 1.4 * @version $Id: ACLServerSocket.java,v 1.3 2002/05/21 16:47:19 tdb Exp $
39 tdb 1.1 */
40     public class ACLServerSocket extends ServerSocket {
41    
42     //---FINAL ATTRIBUTES---
43    
44     /**
45     * The current CVS revision of this class
46     */
47 tdb 1.4 public static final String REVISION = "$Revision: 1.3 $";
48 tdb 1.1
49     //---STATIC METHODS---
50    
51     //---CONSTRUCTORS---
52    
53     /**
54     * See relevant ServerSocket constructor.
55     */
56     public ACLServerSocket(int port) throws IOException {
57     super(port);
58     setACL(new ACL());
59     }
60    
61     /**
62     * See relevant ServerSocket constructor.
63     */
64     public ACLServerSocket(int port, int backlog) throws IOException {
65     super(port, backlog);
66     setACL(new ACL());
67     }
68    
69     /**
70     * See relevant ServerSocket constructor.
71     */
72     public ACLServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
73     super(port, backlog, bindAddr);
74     setACL(new ACL());
75     }
76    
77     /**
78     * See relevant ServerSocket constructor, and
79     * sets the default acl.
80     */
81     public ACLServerSocket(ACL acl, int port) throws IOException {
82     super(port);
83     setACL(acl);
84     }
85    
86     /**
87     * See relevant ServerSocket constructor, and
88     * sets the default acl.
89     */
90     public ACLServerSocket(ACL acl, int port, int backlog) throws IOException {
91     super(port, backlog);
92     setACL(acl);
93     }
94    
95     /**
96     * See relevant ServerSocket constructor, and
97     * sets the default acl.
98     */
99     public ACLServerSocket(ACL acl, int port, int backlog, InetAddress bindAddr) throws IOException {
100     super(port, backlog, bindAddr);
101     setACL(acl);
102     }
103    
104     //---PUBLIC METHODS---
105    
106     /**
107     * Essentially has the same behaviour as the
108     * ServerSocket.accept() method, except won't
109     * return a Socket unless it is permitted by
110     * the ACL. Closes Socket's immediately that
111     * aren't permitted by the ACL.
112     */
113     public Socket accept() throws IOException {
114     while(true) {
115     Socket s = super.accept();
116     if(_acl.check(s.getInetAddress())) {
117     return s;
118     }
119     else {
120     s.close();
121     }
122     }
123     }
124    
125     /**
126     * Set the ACL at any point in the operation
127     * of the ServerSocket.
128     *
129     * @param acl the new ACL to apply
130     */
131     public void setACL(ACL acl) {
132     _acl = acl;
133     }
134    
135     /**
136     * Overrides the {@link java.lang.Object#toString() Object.toString()}
137     * method to provide clean logging (every class should have this).
138     *
139     * This uses the uk.org.iscream.cms.server.util.FormatName class
140     * to format the toString()
141     *
142     * @return the name of this class and its CVS revision
143     */
144     public String toString() {
145     return FormatName.getName(
146     _name,
147     getClass().getName(),
148     REVISION) + ":" + super.toString();
149     }
150    
151     //---PRIVATE METHODS---
152    
153     //---ACCESSOR/MUTATOR METHODS---
154    
155     //---ATTRIBUTES---
156    
157     /**
158     * This is the friendly identifier of the
159     * component this class is running in.
160     * eg, a Filter may be called "filter1",
161     * If this class does not have an owning
162     * component, a name from the configuration
163     * can be placed here. This name could also
164     * be changed to null for utility classes.
165     */
166     private String _name = null;
167    
168     /**
169     * The ACL used by this ACLServerSocket.
170     */
171     private ACL _acl;
172    
173     //---STATIC ATTRIBUTES---
174    
175     //---INNER CLASSES---
176    
177     }