--- experimental/server/ACL/ACL.java 2001/12/20 00:59:54 1.2 +++ experimental/server/ACL/ACL.java 2001/12/21 16:49:18 1.3 @@ -3,8 +3,7 @@ //---IMPORTS--- import uk.org.iscream.cms.server.util.*; -import java.util.LinkedList; -import java.util.Iterator; +import java.util.ArrayList; import java.net.InetAddress; /** @@ -16,7 +15,7 @@ import java.net.InetAddress; * the relevant check method. * * @author $Author: tdb $ - * @version $Id: ACL.java,v 1.2 2001/12/20 00:59:54 tdb Exp $ + * @version $Id: ACL.java,v 1.3 2001/12/21 16:49:18 tdb Exp $ */ public class ACL { @@ -25,7 +24,7 @@ public class ACL { /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.2 $"; + public static final String REVISION = "$Revision: 1.3 $"; /** * static to be used when adding an ALLOW rule to the ACL. @@ -87,11 +86,10 @@ public class ACL { * @return whether the address was permitted by the ACL */ public boolean check(String address) { - Iterator i = _acl.iterator(); - while(i.hasNext()) { - ACLRule item = (ACLRule) i.next(); - if(StringUtils.wildcardCheck(address, item._expression)) { - return item._allow; + for(int i=0; i < _acl.size(); i++) { + ACLRule rule = (ACLRule) _acl.get(i); + if(StringUtils.wildcardCheck(address, rule._expression)) { + return rule._allow; } } return _defaultMode; @@ -109,14 +107,13 @@ public class ACL { * @return whether the InetAddress was permitted by the ACL */ public boolean check(InetAddress address) { - Iterator i = _acl.iterator(); - while(i.hasNext()) { - ACLRule item = (ACLRule) i.next(); - if(StringUtils.wildcardCheck(address.getHostName(), item._expression)) { - return item._allow; + for(int i=0; i < _acl.size(); i++) { + ACLRule rule = (ACLRule) _acl.get(i); + if(StringUtils.wildcardCheck(address.getHostName(), rule._expression)) { + return rule._allow; } - if(StringUtils.wildcardCheck(address.getHostAddress(), item._expression)) { - return item._allow; + if(StringUtils.wildcardCheck(address.getHostAddress(), rule._expression)) { + return rule._allow; } } return _defaultMode; @@ -129,17 +126,22 @@ public class ACL { */ public String getStringACL() { String acl = ""; - Iterator i = _acl.iterator(); - while(i.hasNext()) { - ACLRule item = (ACLRule) i.next(); - if(item._allow) { - acl += "ALLOW:" + item._expression + " "; + for(int i=0; i < _acl.size(); i++) { + ACLRule rule = (ACLRule) _acl.get(i); + if(rule._allow) { + acl += "ALLOW:" + rule._expression + " "; } else { - acl += "DENY:" + item._expression + " "; + acl += "DENY:" + rule._expression + " "; } } - return acl.substring(0, acl.length()-1); + if(_defaultMode) { + acl += "DEFAULT:ALLOW"; + } + else { + acl += "DEFAULT:DENY"; + } + return acl; } /** @@ -176,11 +178,9 @@ public class ACL { private String _name = null; /** - * The ACL is stored in this LinkedList. - * This is ideal as the list is always searched - * from beginning to end in an iterative fashion. + * The ACL is stored in this ArrayList. */ - private LinkedList _acl = new LinkedList(); + private ArrayList _acl = new ArrayList(); /** * The default mode of this ACL.