mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

sin
21.19.2009 3a391aa6522c307f73f98f607aa6ff8299d5cbee
issue# 3387:Name exceptions should never been allowed if ds-cfg-allow-attribute-name-exceptions=false
3 files modified
193 ■■■■■ changed files
opends/src/messages/messages/schema.properties 36 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java 79 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/schema/ObjectClassSyntax.java 78 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/schema.properties
@@ -920,3 +920,39 @@
MILD_ERR_ATTR_SYNTAX_DN_INVALID_REQUIRES_ESCAPE_CHAR_282=The provided \
 value "%s" could not be parsed as a valid distinguished name because an \
 attribute value started with a character at position %d that needs to be escaped
MILD_ERR_ATTR_SYNTAX_ATTR_ILLEGAL_CHAR_283=The provided value "%s" could not \
 be parsed as a valid attribute type definition because character '%c' at \
 position %d is not allowed in an attribute type name
MILD_ERR_ATTR_SYNTAX_ATTR_ILLEGAL_UNDERSCORE_CHAR_284=The provided value \
 "%s" could not be parsed as a valid attribute type definition because the \
 underscore character is not allowed in an attribute type name unless the \
 %s configuration option is enabled
MILD_ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_DASH_285=The provided value "%s" \
 could not be parsed as a valid attribute type definition because the hyphen \
 character is not allowed as the first character of an attribute type name
MILD_ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_UNDERSCORE_286=The provided value \
 "%s" could not be parsed as a valid attribute type definition because the \
 underscore character is not allowed as the first character of an attribute \
 type name even if the %s configuration option is enabled
MILD_ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_DIGIT_287=The provided value "%s" \
 could not be parsed as a valid attribute type definition because the \
 digit '%c' is not allowed as the first character of an attribute type name \
 unless the name is specified as an OID or the %s configuration option is enabled
MILD_ERR_OC_SYNTAX_ATTR_ILLEGAL_CHAR_288=The provided value "%s" could not \
 be parsed as a valid object class definition because character '%c' at \
 position %d is not allowed in an object class name
MILD_ERR_OC_SYNTAX_ATTR_ILLEGAL_UNDERSCORE_CHAR_289=The provided value \
 "%s" could not be parsed as a valid object class definition because the \
 underscore character is not allowed in an object class name unless the \
 %s configuration option is enabled
MILD_ERR_OC_SYNTAX_ATTR_ILLEGAL_INITIAL_DASH_290=The provided value "%s" \
 could not be parsed as a valid object class definition because the hyphen \
 character is not allowed as the first character of an object class name
MILD_ERR_OC_SYNTAX_ATTR_ILLEGAL_INITIAL_UNDERSCORE_291=The provided value \
 "%s" could not be parsed as a valid object class definition because the \
 underscore character is not allowed as the first character of an object \
 class name even if the %s configuration option is enabled
MILD_ERR_OC_SYNTAX_ATTR_ILLEGAL_INITIAL_DIGIT_292=The provided value "%s" \
 could not be parsed as a valid object class definition because the \
 digit '%c' is not allowed as the first character of an object class name \
 unless the name is specified as an OID or the %s configuration option is enabled
opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 */
package org.opends.server.schema;
import org.opends.messages.Message;
@@ -54,6 +54,7 @@
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import static org.opends.server.config.ConfigConstants.*;
@@ -534,6 +535,82 @@
          throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       message);
        }
        //RFC 2251: A specification may also assign one or more textual names
        //for an attribute type.  These names MUST begin with a letter, and
        //only contain ASCII letters, digit characters and hyphens.
        boolean allowExceptions =
                                DirectoryServer.allowAttributeNameExceptions();
        //Iterate over all the names and throw an exception if it is invalid.
        for(String name : typeNames)
        {
          for(int index=0; index < name.length(); index++)
          {
            char ch = name.charAt(index);
            switch(ch)
            {
              case '-':
              //hyphen is allowed but not as the first byte.
                if (index==0)
                {
                  Message msg = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_DASH.
                        get(value.toString());
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                break;
              case '_':
              // This will never be allowed as the first character.  It
              // may be allowed for subsequent characters if the attribute
              // name exceptions option is enabled.
                if (index==0)
                {
                  Message msg =
                          ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_UNDERSCORE.
                        get(value.toString(),
                            ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                else if (!allowExceptions)
                {
                  Message msg = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_UNDERSCORE_CHAR.
                        get(value.toString(),
                            ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                break;
              default:
              //Only digits and ascii letters are allowed but the first byte
              //can not be a digit.
                if(index ==0 && isDigit(ch) && !allowExceptions)
                {
                  Message message = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_DIGIT.
                    get(value.toString(), ch,
                        ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                             message);
                }
                else if(!((ch>='0' && ch<='9') || (ch>='A' && ch<='Z') ||
                        (ch>='a' && ch<='z')))
                {
                  Message msg = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_CHAR.get(
                            value.toString(), ch, index);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       msg);
                }
                break;
            }
          }
        }
      }
      else if (lowerTokenName.equals("desc"))
      {
opends/src/server/org/opends/server/schema/ObjectClassSyntax.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 */
package org.opends.server.schema;
import org.opends.messages.Message;
@@ -53,6 +53,7 @@
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import static org.opends.server.config.ConfigConstants.*;
@@ -506,6 +507,81 @@
          throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       message);
        }
        //RFC 2251: A specification may also assign one or more textual names
        //for an attribute type.  These names MUST begin with a letter, and
        //only contain ASCII letters, digit characters and hyphens.
        boolean allowExceptions =
                                DirectoryServer.allowAttributeNameExceptions();
        //Iterate over all the names and throw an exception if it is invalid.
        for(String name : names)
        {
          for(int index=0; index < name.length(); index++)
          {
            char ch = name.charAt(index);
            switch(ch)
            {
              case '-':
              //hyphen is allowed but not as the first byte.
                if (index==0)
                {
                  Message msg = ERR_OC_SYNTAX_ATTR_ILLEGAL_INITIAL_DASH.
                        get(value.toString());
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                break;
              case '_':
              // This will never be allowed as the first character.  It
              // may be allowed for subsequent characters if the attribute
              // name exceptions option is enabled.
                if (index==0)
                {
                  Message msg =
                          ERR_OC_SYNTAX_ATTR_ILLEGAL_INITIAL_UNDERSCORE.
                        get(value.toString(),
                            ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                else if (!allowExceptions)
                {
                  Message msg = ERR_OC_SYNTAX_ATTR_ILLEGAL_UNDERSCORE_CHAR.
                        get(value.toString(),
                            ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                break;
              default:
              //Only digits and ascii letters are allowed but the first byte
              //can not be a digit.
                if(index ==0 && isDigit(ch) && !allowExceptions)
                {
                  Message message = ERR_OC_SYNTAX_ATTR_ILLEGAL_INITIAL_DIGIT.
                    get(value.toString(), ch,
                        ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                             message);
                }
                else if(!((ch>='0' && ch<='9') || (ch>='A' && ch<='Z') ||
                        (ch>='a' && ch<='z')))
                {
                  Message msg = ERR_OC_SYNTAX_ATTR_ILLEGAL_CHAR.get(
                            value.toString(), ch, index);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       msg);
                }
                break;
            }
          }
        }
      }
      else if (lowerTokenName.equals("desc"))
      {