ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/ACL/ACL.java
(Generate patch)

Comparing experimental/server/ACL/ACL.java (file contents):
Revision 1.2 by tdb, Thu Dec 20 00:59:54 2001 UTC vs.
Revision 1.6 by tdb, Mon Dec 24 04:17:29 2001 UTC

# Line 3 | Line 3
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
# Line 18 | Line 18 | import java.net.InetAddress;
18   * @author  $Author$
19   * @version $Id$
20   */
21 < public class ACL {
21 > public class ACL implements Serializable {
22  
23   //---FINAL ATTRIBUTES---
24  
# Line 87 | Line 87 | public class ACL {
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;
# Line 109 | Line 108 | public class ACL {
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;
121      }
122      
123      /**
124 <     * Gets the ACL as a String for debugging.
124 >     * Gives a String representation of this ACL.
125       *
126       * @return A String representation of this ACL.
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 + " ";
137 <            }
138 <            else {
139 <                acl += "DENY:" + item._expression + " ";
140 <            }
128 >    public String toString() {
129 >        StringBuffer acl = new StringBuffer();
130 >        acl.append("{");
131 >        for(int i=0; i < _acl.size(); i++) {
132 >            acl.append((ACLRule) _acl.get(i));
133 >            acl.append(",");
134          }
135 <        return acl.substring(0, acl.length()-1);
135 >        if(_defaultMode) {
136 >            acl.append("DEFAULT=ALLOW");
137 >        }
138 >        else {
139 >            acl.append("DEFAULT=DENY");
140 >        }
141 >        acl.append("}");
142 >        return acl.toString();
143      }
144    
145    /**
146     * Overrides the {@link java.lang.Object#toString() Object.toString()}
147     * method to provide clean logging (every class should have this).
148     *
149     * This uses the uk.org.iscream.cms.server.util.FormatName class
150     * to format the toString()
151     *
152     * @return the name of this class and its CVS revision
153     */
154    public String toString() {
155        return FormatName.getName(
156            _name,
157            getClass().getName(),
158            REVISION);
159    }
144  
145   //---PRIVATE METHODS---
146  
# Line 176 | Line 160 | public class ACL {
160      private String _name = null;
161      
162      /**
163 <     * 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.
163 >     * The ACL is stored in this ArrayList.
164       */
165 <    private LinkedList _acl = new LinkedList();
165 >    private ArrayList _acl = new ArrayList();
166      
167      /**
168       * The default mode of this ACL.
# Line 194 | Line 176 | public class ACL {
176      /**
177       * Wrapper class for an ACL rule.
178       */
179 <    private class ACLRule {
179 >    private class ACLRule implements Serializable {
180          
181          /**
182           * Construct an ACL rule.
# Line 205 | Line 187 | public class ACL {
187          private ACLRule(boolean allow, String expression) {
188              _allow = allow;
189              _expression = expression;
190 +        }
191 +        
192 +        /**
193 +         * Returns a String representation of this rule.
194 +         *
195 +         * @return A String representation of this rule.
196 +         */
197 +        public String toString() {
198 +            if(_allow) {
199 +                return _expression + "=ALLOW";
200 +            }
201 +            else {
202 +                return _expression + "=DENY";
203 +            }
204          }
205          
206          /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines