From 3cf6f51cc3c2a9b247f62a84c0d40cfe32ddd97b Mon Sep 17 00:00:00 2001
From: dugan <dugan@localhost>
Date: Thu, 12 Jul 2007 01:22:53 +0000
Subject: [PATCH] Re-commit for issue 1457 incorporating Neil's comments:
---
opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AttributeTypeDescriptionAttributeSyntaxConfiguration.xml | 4 +-
opendj-sdk/opends/resource/config/config.ldif | 1
opendj-sdk/opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java | 40 ++++++++++----------
opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java | 45 +++++++++++++++++++++-
4 files changed, 65 insertions(+), 25 deletions(-)
diff --git a/opendj-sdk/opends/resource/config/config.ldif b/opendj-sdk/opends/resource/config/config.ldif
index 7d1a76c..0fc4998 100644
--- a/opendj-sdk/opends/resource/config/config.ldif
+++ b/opendj-sdk/opends/resource/config/config.ldif
@@ -1442,6 +1442,7 @@
cn: Attribute Type Description
ds-cfg-syntax-class: org.opends.server.schema.AttributeTypeSyntax
ds-cfg-syntax-enabled: true
+ds-cfg-strip-syntax-minimum-upper-bound: false
dn: cn=Authentication Password,cn=Syntaxes,cn=config
objectClass: top
diff --git a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AttributeTypeDescriptionAttributeSyntaxConfiguration.xml b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AttributeTypeDescriptionAttributeSyntaxConfiguration.xml
index 6665ab1..1d98303 100644
--- a/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AttributeTypeDescriptionAttributeSyntaxConfiguration.xml
+++ b/opendj-sdk/opends/src/admin/defn/org/opends/server/admin/std/AttributeTypeDescriptionAttributeSyntaxConfiguration.xml
@@ -49,9 +49,9 @@
<adm:synopsis>
Indicate whether the suggested minimum upper bound appended
to an attribute's syntax OID in it's schema definition Attribute Type
- Description is stripped off. When retrieving the server's schema, some API's
+ Description is stripped off. When retrieving the server's schema, some APIs
(JNDI) fail in their syntax lookup methods because they don't parse this value
- correctly. This configuration option allows the server to be configured to
+ correctly. This configuration option allows the server to be configured to
provide schema definitions these APIs can parse correctly.
</adm:synopsis>
<adm:default-behavior>
diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
index d56040e..768c5ae 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -127,6 +127,7 @@
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.Configuration;
import static org.opends.server.messages.ConfigMessages.*;
+import org.opends.server.protocols.asn1.ASN1OctetString;
/**
@@ -238,7 +239,10 @@
// The time that the schema was last modified.
private long modifyTime;
+ //Regular expression used to strip minimum upper bound value from
+ //syntax Attribute Type Description. The value looks like: {count}.
+ private String stripMinUpperBoundRegEx = "\\{\\d+\\}";
/**
* Creates a new backend with the provided information. All backend
@@ -709,8 +713,13 @@
// Add the "attributeTypes" attribute.
LinkedHashSet<AttributeValue> valueSet =
DirectoryServer.getAttributeTypeSet();
- Attribute attr = new Attribute(attributeTypesType, ATTR_ATTRIBUTE_TYPES,
- valueSet);
+
+ Attribute attr;
+ if(AttributeTypeSyntax.isStripSyntaxMinimumUpperBound())
+ attr = stripMinUpperBoundValues(valueSet);
+ else
+ attr = new Attribute(attributeTypesType, ATTR_ATTRIBUTE_TYPES,
+ valueSet);
ArrayList<Attribute> attrList = new ArrayList<Attribute>(1);
attrList.add(attr);
if (attributeTypesType.isOperational() && (! showAllAttributes))
@@ -5446,7 +5455,37 @@
return alerts;
}
+ /**
+ * Returns an attribute that has the minimum upper bound value removed from
+ * all of its attribute values.
+ *
+ * @param valueSet The original valueset containing the
+ * attribute type definitions.
+ *
+ * @return Attribute that with all of the minimum upper bound values removed
+ * from its attribute values.
+ */
+ private Attribute
+ stripMinUpperBoundValues(LinkedHashSet<AttributeValue> valueSet) {
-
+ LinkedHashSet<AttributeValue> valueSetCopy =
+ new LinkedHashSet<AttributeValue>();
+ for(AttributeValue v : valueSet) {
+ //If it exists, strip the minimum upper bound value from the
+ //attribute value.
+ if(v.toString().indexOf('{') != -1) {
+ //Create an attribute value from the stripped string and add it to the
+ //valueset.
+ String strippedStr=
+ v.toString().replaceFirst(stripMinUpperBoundRegEx, "");
+ ASN1OctetString s=new ASN1OctetString(strippedStr);
+ AttributeValue strippedVal=new AttributeValue(s,s);
+ valueSetCopy.add(strippedVal);
+ } else
+ valueSetCopy.add(v);
+ }
+ return
+ new Attribute(attributeTypesType, ATTR_ATTRIBUTE_TYPES, valueSetCopy);
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java b/opendj-sdk/opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java
index 1f24b3f..4b79b57 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/schema/AttributeTypeSyntax.java
@@ -61,20 +61,23 @@
* syntax is defined in RFC 2252.
*/
public class AttributeTypeSyntax
- extends AttributeSyntax<AttributeTypeDescriptionAttributeSyntaxCfg>
- implements
+ extends AttributeSyntax<AttributeTypeDescriptionAttributeSyntaxCfg>
+ implements
ConfigurationChangeListener<AttributeTypeDescriptionAttributeSyntaxCfg> {
+
/**
* The tracer object for the debug logger.
*/
private static final DebugTracer TRACER = getTracer();
+
// The reference to the configuration for this attribute type description
// syntax.
private AttributeTypeDescriptionAttributeSyntaxCfg currentConfig;
+
// The default equality matching rule for this syntax.
private EqualityMatchingRule defaultEqualityMatchingRule;
@@ -87,6 +90,7 @@
// If true strip the suggested minimum upper bound from the syntax OID.
private static boolean stripMinimumUpperBound=false;
+
/**
* Creates a new instance of this syntax. Note that the only thing that
* should be done here is to invoke the default constructor for the
@@ -669,13 +673,13 @@
// of characters that should be allowed in values of that type. This
// implementation will ignore any such length because it does not
// impose any practical limit on the length of attribute values.
+ boolean inBrace = false;
boolean lastWasPeriod = false;
- int leftBracePos=0;
StringBuilder oidBuffer = new StringBuilder();
while (pos < length)
{
c = lowerStr.charAt(pos++);
- if (leftBracePos != 0)
+ if (inBrace)
{
// The only thing we'll allow here will be numeric digits and the
// closing curly brace.
@@ -691,18 +695,7 @@
ResultCode.INVALID_ATTRIBUTE_SYNTAX, message,
msgID);
}
- //If option ds-cfg-strip-syntax-minimum-upper-bound is true,
- //remove minimum number specification (including braces) because
- //it breaks some syntax retrieval APIs such as JNDI's
- //getAttributeSyntaxDefinition().
- if(stripMinimumUpperBound) {
- String firstPart=
- value.stringValue().substring(0,leftBracePos-1);
- String secPart=value.stringValue().substring(pos);
- StringBuilder tmpBuffer=
- new StringBuilder(firstPart).append(secPart);
- value.setValue(tmpBuffer.toString().getBytes());
- }
+
break;
}
else if (! isDigit(c))
@@ -740,10 +733,8 @@
}
else if (c == '{')
{
- // It's the start of the length specification. Keep an index
- //to this character because the specification will need to be
- //removed.
- leftBracePos=pos;
+ // It's the start of the length specification.
+ inBrace = true;
}
else if (c == ' ')
{
@@ -1491,6 +1482,15 @@
return true;
}
+ /**
+ * Boolean that indicates that the minimum upper bound value should be
+ * stripped from the Attrbute Type Syntax Description.
+ *
+ * @return True if the minimum upper bound value should be stripped.
+ */
+ public static boolean isStripSyntaxMinimumUpperBound() {
+ return stripMinimumUpperBound;
+ }
}
--
Gitblit v1.10.0