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