| 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 |
+ |
import java.io.Serializable; |
| 9 |
|
|
| 10 |
|
/** |
| 11 |
|
* Access Control List for use primarily |
| 18 |
|
* @author $Author$ |
| 19 |
|
* @version $Id$ |
| 20 |
|
*/ |
| 21 |
< |
public class ACL { |
| 21 |
> |
public class ACL implements Serializable { |
| 22 |
|
|
| 23 |
|
//---FINAL ATTRIBUTES--- |
| 24 |
|
|
| 87 |
|
* @return whether the address was permitted by the ACL |
| 88 |
|
*/ |
| 89 |
|
public boolean check(String address) { |
| 90 |
< |
Iterator i = _acl.iterator(); |
| 91 |
< |
while(i.hasNext()) { |
| 92 |
< |
ACLRule item = (ACLRule) i.next(); |
| 93 |
< |
if(StringUtils.wildcardCheck(address, item._expression)) { |
| 94 |
< |
return item._allow; |
| 90 |
> |
for(int i=0; i < _acl.size(); i++) { |
| 91 |
> |
ACLRule rule = (ACLRule) _acl.get(i); |
| 92 |
> |
if(StringUtils.wildcardCheck(address, rule._expression)) { |
| 93 |
> |
return rule._allow; |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
return _defaultMode; |
| 108 |
|
* @return whether the InetAddress was permitted by the ACL |
| 109 |
|
*/ |
| 110 |
|
public boolean check(InetAddress address) { |
| 111 |
< |
Iterator i = _acl.iterator(); |
| 112 |
< |
while(i.hasNext()) { |
| 113 |
< |
ACLRule item = (ACLRule) i.next(); |
| 114 |
< |
if(StringUtils.wildcardCheck(address.getHostName(), item._expression)) { |
| 116 |
< |
return item._allow; |
| 111 |
> |
for(int i=0; i < _acl.size(); i++) { |
| 112 |
> |
ACLRule rule = (ACLRule) _acl.get(i); |
| 113 |
> |
if(StringUtils.wildcardCheck(address.getHostName(), rule._expression)) { |
| 114 |
> |
return rule._allow; |
| 115 |
|
} |
| 116 |
< |
if(StringUtils.wildcardCheck(address.getHostAddress(), item._expression)) { |
| 117 |
< |
return item._allow; |
| 116 |
> |
if(StringUtils.wildcardCheck(address.getHostAddress(), rule._expression)) { |
| 117 |
> |
return rule._allow; |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
return _defaultMode; |
| 127 |
|
*/ |
| 128 |
|
public String getStringACL() { |
| 129 |
|
String acl = ""; |
| 130 |
< |
Iterator i = _acl.iterator(); |
| 131 |
< |
while(i.hasNext()) { |
| 132 |
< |
ACLRule item = (ACLRule) i.next(); |
| 133 |
< |
if(item._allow) { |
| 136 |
< |
acl += "ALLOW:" + item._expression + " "; |
| 130 |
> |
for(int i=0; i < _acl.size(); i++) { |
| 131 |
> |
ACLRule rule = (ACLRule) _acl.get(i); |
| 132 |
> |
if(rule._allow) { |
| 133 |
> |
acl += "ALLOW:" + rule._expression + " "; |
| 134 |
|
} |
| 135 |
|
else { |
| 136 |
< |
acl += "DENY:" + item._expression + " "; |
| 136 |
> |
acl += "DENY:" + rule._expression + " "; |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
< |
return acl.substring(0, acl.length()-1); |
| 139 |
> |
if(_defaultMode) { |
| 140 |
> |
acl += "DEFAULT:ALLOW"; |
| 141 |
> |
} |
| 142 |
> |
else { |
| 143 |
> |
acl += "DEFAULT:DENY"; |
| 144 |
> |
} |
| 145 |
> |
return acl; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
/** |
| 179 |
|
private String _name = null; |
| 180 |
|
|
| 181 |
|
/** |
| 182 |
< |
* 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. |
| 182 |
> |
* The ACL is stored in this ArrayList. |
| 183 |
|
*/ |
| 184 |
< |
private LinkedList _acl = new LinkedList(); |
| 184 |
> |
private ArrayList _acl = new ArrayList(); |
| 185 |
|
|
| 186 |
|
/** |
| 187 |
|
* The default mode of this ACL. |
| 195 |
|
/** |
| 196 |
|
* Wrapper class for an ACL rule. |
| 197 |
|
*/ |
| 198 |
< |
private class ACLRule { |
| 198 |
> |
private class ACLRule implements Serializable { |
| 199 |
|
|
| 200 |
|
/** |
| 201 |
|
* Construct an ACL rule. |