36 |
|
* static to be used when adding a DENY rule to the ACL. |
37 |
|
*/ |
38 |
|
public static final boolean DENY = false; |
39 |
+ |
|
40 |
+ |
/** |
41 |
+ |
* default setting for the default mode for a new ACL. |
42 |
+ |
*/ |
43 |
+ |
public static final boolean DEFMODE = ACL.ALLOW; |
44 |
|
|
45 |
|
//---STATIC METHODS--- |
46 |
|
|
52 |
|
* blocked by a rule. |
53 |
|
*/ |
54 |
|
public ACL() { |
55 |
< |
// default to ACL.ALLOW |
56 |
< |
this(ACL.ALLOW); |
55 |
> |
// default to DEFMODE |
56 |
> |
this(DEFMODE); |
57 |
|
} |
58 |
|
|
59 |
|
/** |
64 |
|
* @param defaultMode the default mode for non-matched checks |
65 |
|
*/ |
66 |
|
public ACL(boolean defaultMode) { |
67 |
< |
_defaultMode = defaultMode; |
67 |
> |
setDefaultMode(defaultMode); |
68 |
|
} |
69 |
|
|
70 |
+ |
/** |
71 |
+ |
* Construct a new Access Control List with a given |
72 |
+ |
* String representation of the ACL rules. The String |
73 |
+ |
* should be of the format: |
74 |
+ |
* expression:rule;expression:rule;expression:rule... |
75 |
+ |
* Where expression is a wildcard to match against, and |
76 |
+ |
* rule is either 'ALLOW' or 'DENY'. There is a special |
77 |
+ |
* expression of 'DEFAULT' which represents the default |
78 |
+ |
* rule (what should happen if no expression is matched |
79 |
+ |
* when performing a check). |
80 |
+ |
* The default mode is set to ALLOW if one is not |
81 |
+ |
* specified in the String. |
82 |
+ |
* |
83 |
+ |
* @param acl a String representation of the ACL. |
84 |
+ |
*/ |
85 |
+ |
public ACL(String acl) { |
86 |
+ |
setDefaultMode(DEFMODE); |
87 |
+ |
add(acl); |
88 |
+ |
} |
89 |
+ |
|
90 |
|
//---PUBLIC METHODS--- |
91 |
|
|
92 |
|
/** |
113 |
|
} |
114 |
|
|
115 |
|
/** |
116 |
+ |
* Add some new rules to the Access Control List in |
117 |
+ |
* the form of a String. The String should be of the |
118 |
+ |
* following format: |
119 |
+ |
* expression:rule;expression:rule;expression:rule... |
120 |
+ |
* Where expression is a wildcard to match against, and |
121 |
+ |
* rule is either 'ALLOW' or 'DENY'. There is a special |
122 |
+ |
* expression of 'DEFAULT' which represents the default |
123 |
+ |
* rule (what should happen if no expression is matched |
124 |
+ |
* when performing a check). |
125 |
+ |
* |
126 |
+ |
* @param acl a String representation of the ACL. |
127 |
+ |
*/ |
128 |
+ |
public void add(String acl) { |
129 |
+ |
if(acl != null) { |
130 |
+ |
// split the String into expression:rule parts |
131 |
+ |
StringTokenizer st1 = new StringTokenizer(acl, ";"); |
132 |
+ |
while(st1.hasMoreTokens()) { |
133 |
+ |
String token1 = st1.nextToken(); |
134 |
+ |
// if it doesn't have a :, it's not the correct format |
135 |
+ |
if(token1.indexOf(":") != -1) { |
136 |
+ |
// split into expression and rule part |
137 |
+ |
StringTokenizer st2 = new StringTokenizer(token1, ":"); |
138 |
+ |
String expression = ""; |
139 |
+ |
String rule = ""; |
140 |
+ |
if(st2.hasMoreTokens()) { |
141 |
+ |
expression = st2.nextToken(); |
142 |
+ |
} |
143 |
+ |
else { |
144 |
+ |
// mall-formed? |
145 |
+ |
continue; |
146 |
+ |
} |
147 |
+ |
if(st2.hasMoreTokens()) { |
148 |
+ |
rule = st2.nextToken(); |
149 |
+ |
} |
150 |
+ |
else { |
151 |
+ |
// mall-formed? |
152 |
+ |
continue; |
153 |
+ |
} |
154 |
+ |
// check to see what sort of rule |
155 |
+ |
if(rule.equals("ALLOW")) { |
156 |
+ |
// case for special 'DEFAULT' expression |
157 |
+ |
if(expression.equals("DEFAULT")) { |
158 |
+ |
setDefaultMode(ACL.ALLOW); |
159 |
+ |
} |
160 |
+ |
else { |
161 |
+ |
add(ACL.ALLOW, expression); |
162 |
+ |
} |
163 |
+ |
} |
164 |
+ |
else if(rule.equals("DENY")) { |
165 |
+ |
// case for special 'DEFAULT' expression |
166 |
+ |
if(expression.equals("DEFAULT")) { |
167 |
+ |
setDefaultMode(ACL.DENY); |
168 |
+ |
} |
169 |
+ |
else { |
170 |
+ |
add(ACL.DENY, expression); |
171 |
+ |
} |
172 |
+ |
} |
173 |
+ |
// if it's not ALLOW or DENY, it's not a |
174 |
+ |
// proper rule, so we'll ignore it |
175 |
+ |
} |
176 |
+ |
} |
177 |
+ |
} |
178 |
+ |
} |
179 |
+ |
|
180 |
+ |
/** |
181 |
|
* Check to see if a string is permitted by the |
182 |
|
* ACL. Useful for testing, and non-Socket uses |
183 |
|
* of this class. |
234 |
|
} |
235 |
|
|
236 |
|
/** |
237 |
+ |
* Clears the ACL and resets the default mode. |
238 |
+ |
*/ |
239 |
+ |
public void clear() { |
240 |
+ |
// just clear out our underlying ArrayList |
241 |
+ |
// containing our ACL objects |
242 |
+ |
_acl.clear(); |
243 |
+ |
// and reset the default mode to the default |
244 |
+ |
setDefaultMode(DEFMODE); |
245 |
+ |
} |
246 |
+ |
|
247 |
+ |
/** |
248 |
+ |
* Changes the default mode of the ACL. This is what |
249 |
+ |
* the check will return if it does not find an explict |
250 |
+ |
* rule to match against. |
251 |
+ |
* |
252 |
+ |
* @param defaultMode the new default mode |
253 |
+ |
*/ |
254 |
+ |
public void setDefaultMode(boolean defaultMode) { |
255 |
+ |
_defaultMode = defaultMode; |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
/** |
259 |
|
* Gives a String representation of this ACL. |
260 |
|
* |
261 |
|
* @return A String representation of this ACL. |
393 |
|
/** |
394 |
|
* The default mode of this ACL. |
395 |
|
*/ |
396 |
< |
private boolean _defaultMode; |
396 |
> |
private boolean _defaultMode = DEFMODE; |
397 |
|
|
398 |
|
//---STATIC ATTRIBUTES--- |
399 |
|
|