From 14c5f3996a46c1281cb133de439f25492c97530a Mon Sep 17 00:00:00 2001
From: dugan <dugan@localhost>
Date: Wed, 07 Mar 2007 14:56:34 +0000
Subject: [PATCH] These changes are mostly related to restructuring the regular expression patterns to make them more readable by defining constants. 

---
 opends/src/server/org/opends/server/authorization/dseecompat/ParentInheritance.java |   60 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/opends/src/server/org/opends/server/authorization/dseecompat/ParentInheritance.java b/opends/src/server/org/opends/server/authorization/dseecompat/ParentInheritance.java
index 17e341d..eb151ea 100644
--- a/opends/src/server/org/opends/server/authorization/dseecompat/ParentInheritance.java
+++ b/opends/src/server/org/opends/server/authorization/dseecompat/ParentInheritance.java
@@ -28,8 +28,12 @@
 package org.opends.server.authorization.dseecompat;
 
 import static org.opends.server.authorization.dseecompat.AciMessages.*;
+import static org.opends.server.authorization.dseecompat.Aci.*;
 import static org.opends.server.messages.MessageHandler.getMessage;
 import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.types.AttributeType;
 
@@ -38,14 +42,31 @@
  * to determine what parent inheritance checks to make.
  */
 public class ParentInheritance {
+
     /*
      * The maximum number of parent inheritance levels supported.
-     *
      */
     private static final int MAX_LEVELS=10;
+
+    /*
+     * Pattern to match for parent inheritance.
+     */
     private String parentPat="parent[";
+
+    /*
+     * Array used to hold the level information. Each slot corresponds to a
+     * level parsed from the rule.
+     */
     private int[] levels=new int[MAX_LEVELS];
+
+    /*
+     * The number of levels parsed.
+     */
     private int numLevels;
+
+    /*
+     * The attribute type parsed from the rule.
+     */
     private AttributeType attributeType;
 
 
@@ -66,21 +87,29 @@
             //The "parent[" pattern is invalid for ROLEDN user attr keyword.
             if(pattern.startsWith(parentPat)) {
                 int msgID =
-                  MSGID_ACI_SYNTAX_INVALID_USERATTR_ROLEDN_INHERITANCE_PATTERN;
+                   MSGID_ACI_SYNTAX_INVALID_USERATTR_ROLEDN_INHERITANCE_PATTERN;
                 String message = getMessage(msgID, pattern);
                 throw new AciException(msgID, message);
             }  else {
                 pattern=pattern.trim();
-                if((this.attributeType =
-                        DirectoryServer.getAttributeType(pattern)) == null)
-                    this.attributeType =
-                            DirectoryServer.getDefaultAttributeType(pattern);
-                numLevels=1;
-                levels[0]=0;
+                Pattern pattern1=Pattern.compile(ATTR_NAME);
+                Matcher matcher=pattern1.matcher(pattern);
+               //Check if valid attribute type name.
+               if(!matcher.find() || matcher.groupCount() != 1) {
+                int msgID =
+                        MSGID_ACI_SYNTAX_INVALID_ATTRIBUTE_TYPE_NAME;
+                String message = getMessage(msgID, pattern);
+                throw new AciException(msgID, message);
+               }
+               if((this.attributeType =
+                    DirectoryServer.getAttributeType(pattern)) == null)
+                this.attributeType =
+                        DirectoryServer.getDefaultAttributeType(pattern);
+               numLevels=1;
+              levels[0]=0;
             }
-        } else
-            parse(pattern);
-    }
+    } else parse(pattern);
+}
 
     /**
      * Performs all parsing of the specified pattern string.
@@ -108,6 +137,15 @@
                 String message = getMessage(msgID, pattern);
                 throw new AciException(msgID, message);
             }
+            Pattern pattern1=Pattern.compile(ATTR_NAME);
+            Matcher matcher=pattern1.matcher(toks[1]);
+            //Check if valid attribute type name.
+            if(!matcher.find() || matcher.groupCount() != 1) {
+                int msgID =
+                    MSGID_ACI_SYNTAX_INVALID_ATTRIBUTE_TYPE_NAME;
+                String message = getMessage(msgID, toks[1]);
+                throw new AciException(msgID, message);
+            }
             if((this.attributeType =
                 DirectoryServer.getAttributeType(toks[1])) == null)
                 this.attributeType =

--
Gitblit v1.10.0