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

Nicolas Capponi
30.48.2014 fd3f8d8954cd4cc70c7b2670db5ef2d5443519e9
OPENDJ-1591 Modify UniqueMemberEqualityMatchingRuleImpl  to normalized DN
in the same way than DistinguishedNameEqualityMatchingRuleImpl and add
the optional uid if present
1 files modified
32 ■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java 32 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java
@@ -26,17 +26,41 @@
 */
package org.forgerock.opendj.ldap.schema;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.DecodeException;
/**
 * This class implements the uniqueMemberMatch matching rule defined in X.520
 * and referenced in RFC 2252. It is based on the name and optional UID syntax,
 * and will compare values with a distinguished name and optional bit string
 * and referenced in RFC 4517. It is based on the name and optional UID syntax,
 * and will compare values with a distinguished name and optional bit string (uid)
 * suffix.
 */
final class UniqueMemberEqualityMatchingRuleImpl extends AbstractEqualityMatchingRuleImpl {
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
        return value.toByteString();
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) throws DecodeException {
        // Separate value into normalized DN and "optional uid" portion.
        final String stringValue = value.toString().trim();
        int dnEndPosition = stringValue.length();
        String optionalUid = "";
        int sharpPosition = -1;
        if (stringValue.endsWith("'B") || stringValue.endsWith("'b")) {
            sharpPosition = stringValue.lastIndexOf("#'");
            if (sharpPosition > 0) {
                dnEndPosition = sharpPosition;
                optionalUid = stringValue.substring(sharpPosition);
            }
        }
        try {
            DN dn = DN.valueOf(stringValue.substring(0, dnEndPosition), schema.asNonStrictSchema());
            return new ByteStringBuilder()
                .append(dn.toIrreversibleNormalizedByteString())
                .append(optionalUid).toByteString();
        } catch (final LocalizedIllegalArgumentException e) {
            throw DecodeException.error(e.getMessageObject());
        }
    }
}