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 |
|
/** |
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. |
81 |
> |
* specified in the String. |
82 |
|
* |
83 |
|
* @param acl a String representation of the ACL. |
84 |
|
*/ |
85 |
|
public ACL(String acl) { |
86 |
< |
// default to ALLOW |
87 |
< |
_defaultMode = ACL.ALLOW; |
86 |
> |
setDefaultMode(DEFMODE); |
87 |
> |
add(acl); |
88 |
> |
} |
89 |
> |
|
90 |
> |
//---PUBLIC METHODS--- |
91 |
> |
|
92 |
> |
/** |
93 |
> |
* Add a new rule to the ACL immediately after the |
94 |
> |
* previous rule. The rule can either be an ACL.ALLOW |
95 |
> |
* rule, or an ACL.DENY rule. The expression can |
96 |
> |
* contain a wildcard (a * only). Rules can only be |
97 |
> |
* added to the end of the list. |
98 |
> |
* |
99 |
> |
* param allow whether this is an ALLOW or DENY rule |
100 |
> |
* param expression what this rule matches using wildcards |
101 |
> |
*/ |
102 |
> |
public void add(boolean allow, String expression) { |
103 |
> |
// try and convert the expression into an IP address |
104 |
> |
short[] ipaddr = ipStringToShort(expression); |
105 |
> |
// a result of null means it's not an IP address |
106 |
> |
// add either a name rule or an IP rule |
107 |
> |
if(ipaddr != null) { |
108 |
> |
_acl.add(new ACLRule(allow, expression, ipaddr, true)); |
109 |
> |
} |
110 |
> |
else { |
111 |
> |
_acl.add(new ACLRule(allow, expression, ipaddr, false)); |
112 |
> |
} |
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, ";"); |
155 |
|
if(rule.equals("ALLOW")) { |
156 |
|
// case for special 'DEFAULT' expression |
157 |
|
if(expression.equals("DEFAULT")) { |
158 |
< |
_defaultMode = ACL.ALLOW; |
158 |
> |
setDefaultMode(ACL.ALLOW); |
159 |
|
} |
160 |
|
else { |
161 |
|
add(ACL.ALLOW, expression); |
164 |
|
else if(rule.equals("DENY")) { |
165 |
|
// case for special 'DEFAULT' expression |
166 |
|
if(expression.equals("DEFAULT")) { |
167 |
< |
_defaultMode = ACL.DENY; |
167 |
> |
setDefaultMode(ACL.DENY); |
168 |
|
} |
169 |
|
else { |
170 |
|
add(ACL.DENY, expression); |
176 |
|
} |
177 |
|
} |
178 |
|
} |
133 |
– |
|
134 |
– |
//---PUBLIC METHODS--- |
135 |
– |
|
136 |
– |
/** |
137 |
– |
* Add a new rule to the ACL immediately after the |
138 |
– |
* previous rule. The rule can either be an ACL.ALLOW |
139 |
– |
* rule, or an ACL.DENY rule. The expression can |
140 |
– |
* contain a wildcard (a * only). Rules can only be |
141 |
– |
* added to the end of the list. |
142 |
– |
* |
143 |
– |
* param allow whether this is an ALLOW or DENY rule |
144 |
– |
* param expression what this rule matches using wildcards |
145 |
– |
*/ |
146 |
– |
public void add(boolean allow, String expression) { |
147 |
– |
// try and convert the expression into an IP address |
148 |
– |
short[] ipaddr = ipStringToShort(expression); |
149 |
– |
// a result of null means it's not an IP address |
150 |
– |
// add either a name rule or an IP rule |
151 |
– |
if(ipaddr != null) { |
152 |
– |
_acl.add(new ACLRule(allow, expression, ipaddr, true)); |
153 |
– |
} |
154 |
– |
else { |
155 |
– |
_acl.add(new ACLRule(allow, expression, ipaddr, false)); |
156 |
– |
} |
157 |
– |
} |
179 |
|
|
180 |
|
/** |
181 |
|
* Check to see if a string is permitted by the |
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 |
|
|