62 |
|
_defaultMode = defaultMode; |
63 |
|
} |
64 |
|
|
65 |
+ |
/** |
66 |
+ |
* Construct a new Access Control List with a given |
67 |
+ |
* String representation of the ACL rules. The String |
68 |
+ |
* should be of the format: |
69 |
+ |
* expression:rule;expression:rule;expression:rule... |
70 |
+ |
* Where expression is a wildcard to match against, and |
71 |
+ |
* rule is either 'ALLOW' or 'DENY'. There is a special |
72 |
+ |
* expression of 'DEFAULT' which represents the default |
73 |
+ |
* rule (what should happen if no expression is matched |
74 |
+ |
* when performing a check). |
75 |
+ |
* The default mode is set to ALLOW if one is not |
76 |
+ |
* specified. |
77 |
+ |
* |
78 |
+ |
* @param acl a String representation of the ACL. |
79 |
+ |
*/ |
80 |
+ |
public ACL(String acl) { |
81 |
+ |
// default to ALLOW |
82 |
+ |
_defaultMode = ACL.ALLOW; |
83 |
+ |
if(acl != null) { |
84 |
+ |
// split the String into expression:rule parts |
85 |
+ |
StringTokenizer st1 = new StringTokenizer(acl, ";"); |
86 |
+ |
while(st1.hasMoreTokens()) { |
87 |
+ |
String token1 = st1.nextToken(); |
88 |
+ |
// if it doesn't have a :, it's not the correct format |
89 |
+ |
if(token1.indexOf(":") != -1) { |
90 |
+ |
// split into expression and rule part |
91 |
+ |
StringTokenizer st2 = new StringTokenizer(token1, ":"); |
92 |
+ |
String expression = ""; |
93 |
+ |
String rule = ""; |
94 |
+ |
if(st2.hasMoreTokens()) { |
95 |
+ |
expression = st2.nextToken(); |
96 |
+ |
} |
97 |
+ |
else { |
98 |
+ |
// mall-formed? |
99 |
+ |
continue; |
100 |
+ |
} |
101 |
+ |
if(st2.hasMoreTokens()) { |
102 |
+ |
rule = st2.nextToken(); |
103 |
+ |
} |
104 |
+ |
else { |
105 |
+ |
// mall-formed? |
106 |
+ |
continue; |
107 |
+ |
} |
108 |
+ |
// check to see what sort of rule |
109 |
+ |
if(rule.equals("ALLOW")) { |
110 |
+ |
// case for special 'DEFAULT' expression |
111 |
+ |
if(expression.equals("DEFAULT")) { |
112 |
+ |
_defaultMode = ACL.ALLOW; |
113 |
+ |
} |
114 |
+ |
else { |
115 |
+ |
add(ACL.ALLOW, expression); |
116 |
+ |
} |
117 |
+ |
} |
118 |
+ |
else if(rule.equals("DENY")) { |
119 |
+ |
// case for special 'DEFAULT' expression |
120 |
+ |
if(expression.equals("DEFAULT")) { |
121 |
+ |
_defaultMode = ACL.DENY; |
122 |
+ |
} |
123 |
+ |
else { |
124 |
+ |
add(ACL.DENY, expression); |
125 |
+ |
} |
126 |
+ |
} |
127 |
+ |
// if it's not ALLOW or DENY, it's not a |
128 |
+ |
// proper rule, so we'll ignore it |
129 |
+ |
} |
130 |
+ |
} |
131 |
+ |
} |
132 |
+ |
} |
133 |
+ |
|
134 |
|
//---PUBLIC METHODS--- |
135 |
|
|
136 |
|
/** |