--- experimental/server/ACL/ACL.java 2001/12/20 00:59:54 1.2 +++ experimental/server/ACL/ACL.java 2001/12/23 00:29:33 1.4 @@ -3,9 +3,9 @@ //---IMPORTS--- import uk.org.iscream.cms.server.util.*; -import java.util.LinkedList; -import java.util.Iterator; +import java.util.ArrayList; import java.net.InetAddress; +import java.io.Serializable; /** * Access Control List for use primarily @@ -16,16 +16,16 @@ 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.4 2001/12/23 00:29:33 tdb Exp $ */ -public class ACL { +public class ACL implements Serializable { //---FINAL ATTRIBUTES--- /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.2 $"; + public static final String REVISION = "$Revision: 1.4 $"; /** * static to be used when adding an ALLOW rule to the ACL. @@ -87,11 +87,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 +108,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 +127,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 +179,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. @@ -194,7 +195,7 @@ public class ACL { /** * Wrapper class for an ACL rule. */ - private class ACLRule { + private class ACLRule implements Serializable { /** * Construct an ACL rule.