--- experimental/server/ACL/ACL.java 2001/12/20 00:59:54 1.2 +++ experimental/server/ACL/ACL.java 2001/12/23 01:05:35 1.5 @@ -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.5 2001/12/23 01:05:35 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.5 $"; /** * 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,54 +108,45 @@ 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; } /** - * Gets the ACL as a String for debugging. + * Gives a String representation of this ACL. * * @return A String representation of this 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 + " "; + public String toString() { + StringBuffer acl = new StringBuffer(); + acl.append("{"); + for(int i=0; i < _acl.size(); i++) { + ACLRule rule = (ACLRule) _acl.get(i); + if(rule._allow) { + acl.append(rule._expression + "=ALLOW"); } else { - acl += "DENY:" + item._expression + " "; + acl.append(rule._expression + "=DENY"); } + acl.append(","); } - return acl.substring(0, acl.length()-1); + if(_defaultMode) { + acl.append("DEFAULT=ALLOW"); + } + else { + acl.append("DEFAULT=DENY"); + } + acl.append("}"); + return acl.toString(); } - - /** - * Overrides the {@link java.lang.Object#toString() Object.toString()} - * method to provide clean logging (every class should have this). - * - * This uses the uk.org.iscream.cms.server.util.FormatName class - * to format the toString() - * - * @return the name of this class and its CVS revision - */ - public String toString() { - return FormatName.getName( - _name, - getClass().getName(), - REVISION); - } //---PRIVATE METHODS--- @@ -176,11 +166,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 +182,7 @@ public class ACL { /** * Wrapper class for an ACL rule. */ - private class ACLRule { + private class ACLRule implements Serializable { /** * Construct an ACL rule.