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.2
Committed: Sat May 18 18:16:03 2002 UTC (21 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.1: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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