3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import uk.org.iscream.cms.server.util.*; |
6 |
< |
import java.util.LinkedList; |
7 |
< |
import java.util.Iterator; |
6 |
> |
import java.util.ArrayList; |
7 |
|
import java.net.InetAddress; |
8 |
|
|
9 |
|
/** |
86 |
|
* @return whether the address was permitted by the ACL |
87 |
|
*/ |
88 |
|
public boolean check(String address) { |
89 |
< |
Iterator i = _acl.iterator(); |
90 |
< |
while(i.hasNext()) { |
91 |
< |
ACLRule item = (ACLRule) i.next(); |
92 |
< |
if(StringUtils.wildcardCheck(address, item._expression)) { |
94 |
< |
return item._allow; |
89 |
> |
for(int i=0; i < _acl.size(); i++) { |
90 |
> |
ACLRule rule = (ACLRule) _acl.get(i); |
91 |
> |
if(StringUtils.wildcardCheck(address, rule._expression)) { |
92 |
> |
return rule._allow; |
93 |
|
} |
94 |
|
} |
95 |
|
return _defaultMode; |
107 |
|
* @return whether the InetAddress was permitted by the ACL |
108 |
|
*/ |
109 |
|
public boolean check(InetAddress address) { |
110 |
< |
Iterator i = _acl.iterator(); |
111 |
< |
while(i.hasNext()) { |
112 |
< |
ACLRule item = (ACLRule) i.next(); |
113 |
< |
if(StringUtils.wildcardCheck(address.getHostName(), item._expression)) { |
116 |
< |
return item._allow; |
110 |
> |
for(int i=0; i < _acl.size(); i++) { |
111 |
> |
ACLRule rule = (ACLRule) _acl.get(i); |
112 |
> |
if(StringUtils.wildcardCheck(address.getHostName(), rule._expression)) { |
113 |
> |
return rule._allow; |
114 |
|
} |
115 |
< |
if(StringUtils.wildcardCheck(address.getHostAddress(), item._expression)) { |
116 |
< |
return item._allow; |
115 |
> |
if(StringUtils.wildcardCheck(address.getHostAddress(), rule._expression)) { |
116 |
> |
return rule._allow; |
117 |
|
} |
118 |
|
} |
119 |
|
return _defaultMode; |
126 |
|
*/ |
127 |
|
public String getStringACL() { |
128 |
|
String acl = ""; |
129 |
< |
Iterator i = _acl.iterator(); |
130 |
< |
while(i.hasNext()) { |
131 |
< |
ACLRule item = (ACLRule) i.next(); |
132 |
< |
if(item._allow) { |
136 |
< |
acl += "ALLOW:" + item._expression + " "; |
129 |
> |
for(int i=0; i < _acl.size(); i++) { |
130 |
> |
ACLRule rule = (ACLRule) _acl.get(i); |
131 |
> |
if(rule._allow) { |
132 |
> |
acl += "ALLOW:" + rule._expression + " "; |
133 |
|
} |
134 |
|
else { |
135 |
< |
acl += "DENY:" + item._expression + " "; |
135 |
> |
acl += "DENY:" + rule._expression + " "; |
136 |
|
} |
137 |
|
} |
138 |
< |
return acl.substring(0, acl.length()-1); |
138 |
> |
if(_defaultMode) { |
139 |
> |
acl += "DEFAULT:ALLOW"; |
140 |
> |
} |
141 |
> |
else { |
142 |
> |
acl += "DEFAULT:DENY"; |
143 |
> |
} |
144 |
> |
return acl; |
145 |
|
} |
146 |
|
|
147 |
|
/** |
178 |
|
private String _name = null; |
179 |
|
|
180 |
|
/** |
181 |
< |
* The ACL is stored in this LinkedList. |
180 |
< |
* This is ideal as the list is always searched |
181 |
< |
* from beginning to end in an iterative fashion. |
181 |
> |
* The ACL is stored in this ArrayList. |
182 |
|
*/ |
183 |
< |
private LinkedList _acl = new LinkedList(); |
183 |
> |
private ArrayList _acl = new ArrayList(); |
184 |
|
|
185 |
|
/** |
186 |
|
* The default mode of this ACL. |