ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/ACL.java
(Generate patch)

Comparing projects/cms/source/util/uk/org/iscream/cms/util/ACL.java (file contents):
Revision 1.3 by tdb, Tue Mar 19 12:18:22 2002 UTC vs.
Revision 1.5 by tdb, Sat May 18 18:16:03 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21   package uk.org.iscream.cms.server.util;
22  
# Line 36 | Line 55 | public class ACL implements Serializable {
55       * static to be used when adding a DENY rule to the ACL.
56       */
57      public static final boolean DENY = false;
58 +    
59 +    /**
60 +     * default setting for the default mode for a new ACL.
61 +     */
62 +    public static final boolean DEFMODE = ACL.ALLOW;
63  
64   //---STATIC METHODS---
65  
# Line 47 | Line 71 | public class ACL implements Serializable {
71       * blocked by a rule.
72       */
73      public ACL() {
74 <        // default to ACL.ALLOW
75 <        this(ACL.ALLOW);
74 >        // default to DEFMODE
75 >        this(DEFMODE);
76      }
77      
78      /**
# Line 59 | Line 83 | public class ACL implements Serializable {
83       * @param defaultMode the default mode for non-matched checks
84       */
85      public ACL(boolean defaultMode) {
86 <        _defaultMode = defaultMode;
86 >        setDefaultMode(defaultMode);
87      }
88  
89      /**
# Line 73 | Line 97 | public class ACL implements Serializable {
97       * rule (what should happen if no expression is matched
98       * when performing a check).
99       * The default mode is set to ALLOW if one is not
100 <     * specified.
100 >     * specified in the String.
101       *
102       * @param acl a String representation of the ACL.
103       */
104      public ACL(String acl) {
105 <        // default to ALLOW
106 <        _defaultMode = ACL.ALLOW;
105 >        setDefaultMode(DEFMODE);
106 >        add(acl);
107 >    }
108 >
109 > //---PUBLIC METHODS---
110 >
111 >    /**
112 >     * Add a new rule to the ACL immediately after the
113 >     * previous rule. The rule can either be an ACL.ALLOW
114 >     * rule, or an ACL.DENY rule. The expression can
115 >     * contain a wildcard (a * only). Rules can only be
116 >     * added to the end of the list.
117 >     *
118 >     * param allow whether this is an ALLOW or DENY rule
119 >     * param expression what this rule matches using wildcards
120 >     */
121 >    public void add(boolean allow, String expression) {
122 >        // try and convert the expression into an IP address
123 >        short[] ipaddr = ipStringToShort(expression);
124 >        // a result of null means it's not an IP address
125 >        // add either a name rule or an IP rule
126 >        if(ipaddr != null) {
127 >            _acl.add(new ACLRule(allow, expression, ipaddr, true));
128 >        }
129 >        else {
130 >            _acl.add(new ACLRule(allow, expression, ipaddr, false));
131 >        }
132 >    }
133 >    
134 >    /**
135 >     * Add some new rules to the Access Control List in
136 >     * the form of a String. The String should be of the
137 >     * following format:
138 >     *     expression:rule;expression:rule;expression:rule...
139 >     * Where expression is a wildcard to match against, and
140 >     * rule is either 'ALLOW' or 'DENY'. There is a special
141 >     * expression of 'DEFAULT' which represents the default
142 >     * rule (what should happen if no expression is matched
143 >     * when performing a check).
144 >     *
145 >     * @param acl a String representation of the ACL.
146 >     */
147 >    public void add(String acl) {
148          if(acl != null) {
149              // split the String into expression:rule parts
150              StringTokenizer st1 = new StringTokenizer(acl, ";");
# Line 109 | Line 174 | public class ACL implements Serializable {
174                      if(rule.equals("ALLOW")) {
175                          // case for special 'DEFAULT' expression
176                          if(expression.equals("DEFAULT")) {
177 <                            _defaultMode = ACL.ALLOW;
177 >                            setDefaultMode(ACL.ALLOW);
178                          }
179                          else {
180                              add(ACL.ALLOW, expression);
# Line 118 | Line 183 | public class ACL implements Serializable {
183                      else if(rule.equals("DENY")) {
184                          // case for special 'DEFAULT' expression
185                          if(expression.equals("DEFAULT")) {
186 <                            _defaultMode = ACL.DENY;
186 >                            setDefaultMode(ACL.DENY);
187                          }
188                          else {
189                              add(ACL.DENY, expression);
# Line 130 | Line 195 | public class ACL implements Serializable {
195              }
196          }
197      }
133
134 //---PUBLIC METHODS---
135
136    /**
137     * Add a new rule to the ACL immediately after the
138     * previous rule. The rule can either be an ACL.ALLOW
139     * rule, or an ACL.DENY rule. The expression can
140     * contain a wildcard (a * only). Rules can only be
141     * added to the end of the list.
142     *
143     * param allow whether this is an ALLOW or DENY rule
144     * param expression what this rule matches using wildcards
145     */
146    public void add(boolean allow, String expression) {
147        // try and convert the expression into an IP address
148        short[] ipaddr = ipStringToShort(expression);
149        // a result of null means it's not an IP address
150        // add either a name rule or an IP rule
151        if(ipaddr != null) {
152            _acl.add(new ACLRule(allow, expression, ipaddr, true));
153        }
154        else {
155            _acl.add(new ACLRule(allow, expression, ipaddr, false));
156        }
157    }
198      
199      /**
200       * Check to see if a string is permitted by the
# Line 213 | Line 253 | public class ACL implements Serializable {
253      }
254      
255      /**
256 +     * Clears the ACL and resets the default mode.
257 +     */
258 +    public void clear() {
259 +        // just clear out our underlying ArrayList
260 +        // containing our ACL objects
261 +        _acl.clear();
262 +        // and reset the default mode to the default
263 +        setDefaultMode(DEFMODE);
264 +    }
265 +    
266 +    /**
267 +     * Changes the default mode of the ACL. This is what
268 +     * the check will return if it does not find an explict
269 +     * rule to match against.
270 +     *
271 +     * @param defaultMode the new default mode
272 +     */
273 +    public void setDefaultMode(boolean defaultMode) {
274 +        _defaultMode = defaultMode;
275 +    }
276 +    
277 +    /**
278       * Gives a String representation of this ACL.
279       *
280       * @return A String representation of this ACL.
# Line 350 | Line 412 | public class ACL implements Serializable {
412      /**
413       * The default mode of this ACL.
414       */
415 <    private boolean _defaultMode;
415 >    private boolean _defaultMode = DEFMODE;
416  
417   //---STATIC ATTRIBUTES---
418  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines