From 64721a895973f935c1adb975247770f402a88fdf Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 25 Apr 2016 15:10:24 +0000
Subject: [PATCH] ACI UCDetector and AutoRefactor code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/PatternDN.java |   75 +++----------------------------------
 1 files changed, 7 insertions(+), 68 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/PatternDN.java b/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/PatternDN.java
index 52cf514..3682a4f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/PatternDN.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/PatternDN.java
@@ -54,7 +54,6 @@
  * Multiple-Whole-RDN:  A double wildcard may be used to match one or more
  * RDN components:
  *   uid=bjensen,**,dc=example,dc=com
- *
  */
 public class PatternDN
 {
@@ -74,7 +73,6 @@
   private List<PatternRDN[]> subAnyElements;
   private PatternRDN[] subFinal;
 
-
   /**
    * When there is no initial sequence, this is used to distinguish between
    * the case where we have a suffix pattern (zero or more RDN components
@@ -84,7 +82,6 @@
    */
   private boolean isSuffix;
 
-
   /**
    * Create a DN pattern that does not include any Multiple-Whole-RDN wildcards.
    * @param equality The sequence of RDN patterns making up the DN pattern.
@@ -94,7 +91,6 @@
     this.equality = equality;
   }
 
-
   /**
    * Create a DN pattern that includes Multiple-Whole-RDN wildcards.
    * @param subInitial     The sequence of RDN patterns appearing at the
@@ -114,7 +110,6 @@
     this.subFinal = subFinal;
   }
 
-
   /**
    * Determine whether a given DN matches this pattern.
    * @param dn The DN to be matched.
@@ -167,15 +162,11 @@
       }
       pos++;
     }
-    else
+    else if (!isSuffix)
     {
-      if (!isSuffix)
-      {
-        pos++;
-      }
+      pos++;
     }
 
-
     if (subAnyElements != null && ! subAnyElements.isEmpty())
     {
       for (PatternRDN[] element : subAnyElements)
@@ -186,13 +177,11 @@
         boolean match = false;
         for (; pos < end; pos++)
         {
-          if (element[0].matchesRDN(dn.rdn(pos)))
+          if (element[0].matchesRDN(dn.rdn(pos))
+              && subMatch(dn, pos, element, anyLength))
           {
-            if (subMatch(dn, pos, element, anyLength))
-            {
-              match = true;
-              break;
-            }
+            match = true;
+            break;
           }
         }
 
@@ -204,7 +193,6 @@
       }
     }
 
-
     if (subFinal != null)
     {
       int finalLength = subFinal.length;
@@ -272,7 +260,6 @@
     return patternDN;
   }
 
-
   /**
    * Create a new DN pattern matcher from a pattern string.
    * @param dnString The DN pattern string.
@@ -297,7 +284,6 @@
       return new PatternDN();
     }
 
-
     // Iterate through the DN string.  The first thing to do is to get
     // rid of any leading spaces.
     int pos = 0;
@@ -417,7 +403,6 @@
         pos++;
       }
 
-
       // If we are at the end of the DN string, then that must mean
       // that the attribute value was empty.  This will probably never
       // happen in a real-world environment, but technically isn't
@@ -430,23 +415,19 @@
         break;
       }
 
-
       // Parse the value for this RDN component.
       List<ByteString> parsedValue = new ArrayList<>();
       pos = parseValuePattern(dnString, pos, parsedValue);
 
-
       // Create the new RDN with the provided information.
       PatternRDN rdn = new PatternRDN(name, parsedValue, dnString);
 
-
       // Skip over any spaces that might be after the attribute value.
       while (pos < length && ((c = dnString.charAt(pos)) == ' '))
       {
         pos++;
       }
 
-
       // Most likely, we will be at either the end of the RDN
       // component or the end of the DN. If so, then handle that appropriately.
       if (pos >= length)
@@ -471,7 +452,6 @@
         throw new DirectoryException(ResultCode.INVALID_DN_SYNTAX, message);
       }
 
-
       // If we have gotten here, then this must be a multi-valued RDN.
       // In that case, parse the remaining attribute/value pairs and
       // add them to the RDN that we've already created.
@@ -485,12 +465,10 @@
           pos++;
         }
 
-
         // Parse the attribute name from the DN string.
         attributeName = new StringBuilder();
         pos = parseAttributePattern(dnString, pos, attributeName);
 
-
         // Make sure that we're not at the end of the DN string
         // because that would be invalid.
         if (pos >= length)
@@ -499,7 +477,6 @@
               ERR_ATTR_SYNTAX_DN_END_WITH_ATTR_NAME.get(dnString, attributeName));
         }
 
-
         name = attributeName.toString();
 
         // Skip over any spaces between the attribute name and its
@@ -519,7 +496,6 @@
           c = dnString.charAt(pos);
         }
 
-
         // The next character must be an equal sign.  If it is not,
         // then that's an error.
         if (c == '=')
@@ -532,14 +508,12 @@
           throw new DirectoryException(ResultCode.INVALID_DN_SYNTAX, message);
         }
 
-
         // Skip over any spaces after the equal sign.
         while (pos < length && ((c = dnString.charAt(pos)) == ' '))
         {
           pos++;
         }
 
-
         // If we are at the end of the DN string, then that must mean
         // that the attribute value was empty.  This will probably
         // never happen in a real-world environment, but technically
@@ -553,23 +527,19 @@
           break;
         }
 
-
         // Parse the value for this RDN component.
         parsedValue = new ArrayList<>();
         pos = parseValuePattern(dnString, pos, parsedValue);
 
-
         // Create the new RDN with the provided information.
         rdn.addValue(name, parsedValue, dnString);
 
-
         // Skip over any spaces that might be after the attribute value.
         while (pos < length && ((c = dnString.charAt(pos)) == ' '))
         {
           pos++;
         }
 
-
         // Most likely, we will be at either the end of the RDN
         // component or the end of the DN.  If so, then handle that appropriately.
         if (pos >= length)
@@ -642,7 +612,6 @@
     return new PatternDN(subInitial, subAnyElements, subFinal);
   }
 
-
   /**
    * Parses an attribute name pattern from the provided DN pattern string
    * starting at the specified location.
@@ -660,13 +629,12 @@
    *                              valid attribute name pattern from the
    *                              provided DN pattern string.
    */
-  static int parseAttributePattern(String dnString, int pos,
+  private static int parseAttributePattern(String dnString, int pos,
                                    StringBuilder attributeName)
           throws DirectoryException
   {
     int length = dnString.length();
 
-
     // Skip over any leading spaces.
     if (pos < length)
     {
@@ -702,7 +670,6 @@
           endOfName = true;
           break;
 
-
         case '!':
         case '"':
         case '#':
@@ -716,7 +683,6 @@
           // character immediately following it.
           throw illegalCharacter(dnString, pos, c);
 
-
         case '*':
           // Wildcard character.
           attributeName.append(c);
@@ -725,7 +691,6 @@
         case '+':
           throw illegalCharacter(dnString, pos, c);
 
-
         case ',':
           // This should denote the end of the attribute name.
           endOfName = true;
@@ -742,7 +707,6 @@
           attributeName.append(c);
           break;
 
-
         case '.':
           // The period could be allowed if the attribute name is
           // actually expressed as an OID.  We'll accept it for now,
@@ -751,11 +715,9 @@
           checkForOID = true;
           break;
 
-
         case '/':
           throw illegalCharacter(dnString, pos, c);
 
-
         case '0':
         case '1':
         case '2':
@@ -774,11 +736,9 @@
           attributeName.append(c);
           break;
 
-
         case ':':
           throw illegalCharacter(dnString, pos, c);
 
-
         case ';': // NOTE:  attribute options are not allowed in a DN.
           // This should denote the end of the attribute name.
           endOfName = true;
@@ -787,19 +747,16 @@
         case '<':
           throw illegalCharacter(dnString, pos, c);
 
-
         case '=':
           // This should denote the end of the attribute name.
           endOfName = true;
           break;
 
-
         case '>':
         case '?':
         case '@':
           throw illegalCharacter(dnString, pos, c);
 
-
         case 'A':
         case 'B':
         case 'C':
@@ -830,23 +787,19 @@
           attributeName.append(c);
           break;
 
-
         case '[':
         case '\\':
         case ']':
         case '^':
           throw illegalCharacter(dnString, pos, c);
 
-
         case '_':
           attributeName.append(c);
           break;
 
-
         case '`':
           throw illegalCharacter(dnString, pos, c);
 
-
         case 'a':
         case 'b':
         case 'c':
@@ -877,14 +830,12 @@
           attributeName.append(c);
           break;
 
-
         default:
           // This is not allowed in an attribute name or any character
           // immediately following it.
           throw illegalCharacter(dnString, pos, c);
       }
 
-
       if (endOfName)
       {
         break;
@@ -893,7 +844,6 @@
       pos++;
     }
 
-
     // We should now have the full attribute name.  However, we may
     // still need to perform some validation, particularly if the
     // name contains a period or starts with a digit.  It must also
@@ -965,7 +915,6 @@
         }
       }
 
-
       if (validOID && attributeName.charAt(nameLength-1) == '.')
       {
         validOID = false;
@@ -987,7 +936,6 @@
         ERR_ATTR_SYNTAX_DN_ATTR_ILLEGAL_CHAR.get(dnString, c, pos));
   }
 
-
   /**
    * Parses the attribute value pattern from the provided DN pattern
    * string starting at the specified location.  The value is split up
@@ -1020,7 +968,6 @@
       return pos;
     }
 
-
     // Look at the first character.  If it is an octothorpe (#), then
     // that means that the value should be a hex string.
     char c = dnString.charAt(pos++);
@@ -1048,7 +995,6 @@
         }
       }
 
-
       // The rest of the value must be a multiple of two hex
       // characters.  The end of the value may be designated by the
       // end of the DN, a comma or semicolon, or a space.
@@ -1091,7 +1037,6 @@
         }
       }
 
-
       // At this point, we should have a valid hex string.  Convert it
       // to a byte array and set that as the value of the provided
       // octet string.
@@ -1109,7 +1054,6 @@
       }
     }
 
-
     // If the first character is a quotation mark, then the value
     // should continue until the corresponding closing quotation mark.
     else if (c == '"')
@@ -1158,7 +1102,6 @@
       return pos;
     }
 
-
     // Otherwise, use general parsing to find the end of the value.
     else
     {
@@ -1181,7 +1124,6 @@
         valueString.append(c);
       }
 
-
       // Keep reading until we find an unescaped comma or plus sign or the end of the DN.
       while (true)
       {
@@ -1266,7 +1208,6 @@
         }
       }
 
-
       // Strip off any unescaped spaces that may be at the end of the
       // value.
       if (pos > 2 && dnString.charAt(pos-1) == ' ' &&
@@ -1284,13 +1225,11 @@
         }
       }
 
-
       attributeValues.add(ByteString.valueOfUtf8(valueString));
       return pos;
     }
   }
 
-
   /**
    * Decodes a hexadecimal string from the provided
    * <CODE>hexChars</CODE> buffer, converts it to a byte array, and

--
Gitblit v1.10.0