OPENDJ-1802 Make ByteString methods more intentional
ByteString.java:
Renamed:
- valueOf(byte[]) to valueOfBytes(byte[])
- valueOf(byte[], int, int) to valueOfBytes(byte[], int, int)
- valueOf(char[]) to valueOfUtf8(char[])
- valueOf(CharSequence) to valueOfUtf8(CharSequence)
- valueOf(Object) to valueOfObject(Object)
- valueOf(int) to valueOfInt(int)
- valueOf(long) to valueOfLong(long)
| | |
| | | <method>%regex[(\w|\.)+ get\w*\([^)]*\)]</method> |
| | | <justification>OPENDJ-1802 ByteSequenceReader.get*() => readByte(), readBytes() and read*()</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/ByteString</className> |
| | | <differenceType>7002</differenceType> |
| | | <method>%regex[org\.forgerock\.opendj\.ldap\.ByteString valueOf\([^)]+\)]</method> |
| | | <justification>OPENDJ-1802 ByteString.valueOf() => valueOfInt(), valueOfLong(), valueOfUtf8(), valueOfBytes(), valueOfObject()</justification> |
| | | </difference> |
| | | </differences> |
| | |
| | | } |
| | | |
| | | private void setBooleanProperty(PasswordPolicyStateOperationType property, final boolean state) { |
| | | operations.add(new MultiValueOperation(property, ByteString.valueOf(String.valueOf(state)))); |
| | | operations.add(new MultiValueOperation(property, ByteString.valueOfUtf8(String.valueOf(state)))); |
| | | } |
| | | |
| | | private void setDateProperty(PasswordPolicyStateOperationType property, final Date date) { |
| | |
| | | } |
| | | |
| | | private ByteString toByteString(final Date date) { |
| | | return ByteString.valueOf(formatAsGeneralizedTime(date)); |
| | | return ByteString.valueOfUtf8(formatAsGeneralizedTime(date)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | reader.reset(); |
| | | // Return what we have got here so far. |
| | | appendHexChars(reader, valueBuffer, hexBuffer); |
| | | return ByteString.valueOf(valueBuffer); |
| | | return ByteString.valueOfUtf8(valueBuffer); |
| | | } |
| | | // It is definitely not a delimiter at this point. |
| | | appendHexChars(reader, valueBuffer, hexBuffer); |
| | |
| | | } |
| | | |
| | | reader.reset(); |
| | | return ByteString.valueOf(valueBuffer); |
| | | return ByteString.valueOfUtf8(valueBuffer); |
| | | } |
| | | |
| | | private static AttributeType readAttributeName(final SubstringReader reader, final Schema schema) { |
| | |
| | | length++; |
| | | } |
| | | reader.reset(); |
| | | final ByteString retString = ByteString.valueOf(reader.read(length)); |
| | | final ByteString retString = ByteString.valueOfUtf8(reader.read(length)); |
| | | reader.read(); |
| | | return retString; |
| | | } else { |
| | |
| | | * attribute type and value. |
| | | * <p> |
| | | * If {@code attributeValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type. |
| | |
| | | Reject.ifNull(attributeType, attributeValue); |
| | | |
| | | this.attributeType = attributeType; |
| | | this.attributeValue = ByteString.valueOf(attributeValue); |
| | | this.attributeValue = ByteString.valueOfObject(attributeValue); |
| | | } |
| | | |
| | | /** |
| | |
| | | * attribute type and value decoded using the default schema. |
| | | * <p> |
| | | * If {@code attributeValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type. |
| | |
| | | Reject.ifNull(attributeType, attributeValue); |
| | | |
| | | this.attributeType = Schema.getDefaultSchema().getAttributeType(attributeType); |
| | | this.attributeValue = ByteString.valueOf(attributeValue); |
| | | this.attributeValue = ByteString.valueOfObject(attributeValue); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | Reject.ifNull(values); |
| | | boolean modified = false; |
| | | for (final Object value : values) { |
| | | modified |= add(ByteString.valueOf(value)); |
| | | modified |= add(ByteString.valueOfObject(value)); |
| | | } |
| | | return modified; |
| | | } |
| | |
| | | |
| | | final Map<ByteString, T> valuesToRetain = new HashMap<>(values.size()); |
| | | for (final T value : values) { |
| | | valuesToRetain.put(normalizeValue(this, ByteString.valueOf(value)), value); |
| | | valuesToRetain.put(normalizeValue(this, ByteString.valueOfObject(value)), value); |
| | | } |
| | | |
| | | boolean modified = false; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * <p> |
| | | * Any methods which accept {@code Object} based attribute values convert the |
| | | * attribute values to instances of {@code ByteString} using |
| | | * {@link ByteString#valueOf(Object)}. |
| | | * {@link ByteString#valueOfObject(Object)}. |
| | | */ |
| | | public interface Attribute extends Set<ByteString> { |
| | | // TODO: matching against attribute value assertions. |
| | |
| | | * not already present (optional operation). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param values |
| | | * The attribute values to be added to this attribute. |
| | |
| | | * {@code duplicateValues} if specified. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param <T> |
| | | * The type of the attribute value objects being added. |
| | |
| | | * Returns {@code true} if this attribute contains {@code value}. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param value |
| | | * The attribute value whose presence in this attribute is to be |
| | |
| | | * values contained in {@code values}. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param values |
| | | * The attribute values whose presence in this attribute is to be |
| | |
| | | * leaves the attribute unchanged and returns {@code false}. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param value |
| | | * The attribute value to be removed from this attribute. |
| | |
| | | * attribute if they are present (optional operation). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * An invocation of this method is equivalent to: |
| | | * |
| | |
| | | * specified. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param <T> |
| | | * The type of the attribute value objects being removed. |
| | |
| | | * in {@code values} (optional operation). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * An invocation of this method is equivalent to: |
| | | * |
| | |
| | | * not already present will be added to {@code missingValues} if specified. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param <T> |
| | | * The type of the attribute value objects being retained. |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS. |
| | | * Portions copyright 2011-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | private SingletonAttribute(final AttributeDescription attributeDescription, |
| | | final Object value) { |
| | | this.attributeDescription = attributeDescription; |
| | | this.value = ByteString.valueOf(value); |
| | | this.value = ByteString.valueOfObject(value); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public boolean contains(final Object value) { |
| | | final ByteString normalizedValue = normalizeValue(this, ByteString.valueOf(value)); |
| | | final ByteString normalizedValue = normalizeValue(this, ByteString.valueOfObject(value)); |
| | | return normalizedSingleValue().equals(normalizedValue); |
| | | } |
| | | |
| | |
| | | * {@code UnsupportedOperationException}. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | * {@code UnsupportedOperationException}. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | * @return The byte string containing the big-endian encoded bytes of the |
| | | * provided integer. |
| | | */ |
| | | public static ByteString valueOf(int i) { |
| | | public static ByteString valueOfInt(int i) { |
| | | final byte[] bytes = new byte[4]; |
| | | for (int j = 3; j >= 0; j--) { |
| | | bytes[j] = (byte) (i & 0xFF); |
| | | bytes[j] = (byte) i; |
| | | i >>>= 8; |
| | | } |
| | | return wrap(bytes); |
| | |
| | | * @return The byte string containing the big-endian encoded bytes of the |
| | | * provided long. |
| | | */ |
| | | public static ByteString valueOf(long l) { |
| | | public static ByteString valueOfLong(long l) { |
| | | final byte[] bytes = new byte[8]; |
| | | for (int i = 7; i >= 0; i--) { |
| | | bytes[i] = (byte) (l & 0xFF); |
| | | bytes[i] = (byte) l; |
| | | l >>>= 8; |
| | | } |
| | | return wrap(bytes); |
| | |
| | | * <li>if the object is an instance of {@code ByteSequence} then this method |
| | | * is equivalent to calling {@code o.toByteString()} |
| | | * <li>if the object is a {@code byte[]} then this method is equivalent to |
| | | * calling {@link #valueOf(byte[])} |
| | | * calling {@link #valueOfBytes(byte[])} |
| | | * <li>if the object is a {@code char[]} then this method is equivalent to |
| | | * calling {@link #valueOf(char[])} |
| | | * calling {@link #valueOfUtf8(char[])} |
| | | * <li>for all other types of object this method is equivalent to calling |
| | | * {@link #valueOf(String)} with the {@code toString()} representation of |
| | | * {@link #valueOfUtf8(CharSequence)} with the {@code toString()} representation of |
| | | * the provided object. |
| | | * </ul> |
| | | * <b>Note:</b> this method treats {@code Long} and {@code Integer} objects |
| | |
| | | * The object to use. |
| | | * @return The byte string containing the provided object. |
| | | */ |
| | | public static ByteString valueOf(final Object o) { |
| | | public static ByteString valueOfObject(final Object o) { |
| | | if (o instanceof ByteSequence) { |
| | | return ((ByteSequence) o).toByteString(); |
| | | } else if (o instanceof byte[]) { |
| | | return valueOf((byte[]) o); |
| | | return valueOfBytes((byte[]) o); |
| | | } else if (o instanceof char[]) { |
| | | return valueOf((char[]) o); |
| | | return valueOfUtf8((char[]) o); |
| | | } else { |
| | | return valueOf(o.toString()); |
| | | return valueOfUtf8(o.toString()); |
| | | } |
| | | } |
| | | |
| | |
| | | * The char sequence to use. |
| | | * @return The byte string with the encoded bytes of the provided string. |
| | | */ |
| | | public static ByteString valueOf(final CharSequence s) { |
| | | public static ByteString valueOfUtf8(final CharSequence s) { |
| | | if (s.length() == 0) { |
| | | return EMPTY; |
| | | } |
| | |
| | | for (int i = 0; i < arrayLength; i++) { |
| | | bytes[i] = hexToByte(hexString, hexString.charAt(i * 2), hexString.charAt(i * 2 + 1)); |
| | | } |
| | | return valueOf(bytes); |
| | | return valueOfBytes(bytes); |
| | | } |
| | | |
| | | /** |
| | |
| | | * The byte array to use. |
| | | * @return A byte string containing a copy of the provided byte array. |
| | | */ |
| | | public static ByteString valueOf(final byte[] bytes) { |
| | | public static ByteString valueOfBytes(final byte[] bytes) { |
| | | if (bytes.length == 0) { |
| | | return EMPTY; |
| | | } |
| | |
| | | * @return A byte string containing a copy of the subsequence of the |
| | | * provided byte array. |
| | | */ |
| | | public static ByteString valueOf(final byte[] bytes, final int offset, final int length) { |
| | | public static ByteString valueOfBytes(final byte[] bytes, final int offset, final int length) { |
| | | checkArrayBounds(bytes, offset, length); |
| | | if (offset == length) { |
| | | return EMPTY; |
| | |
| | | * @return A byte string containing the UTF-8 encoded bytes of the provided |
| | | * char array. |
| | | */ |
| | | public static ByteString valueOf(final char[] chars) { |
| | | public static ByteString valueOfUtf8(final char[] chars) { |
| | | if (chars.length == 0) { |
| | | return EMPTY; |
| | | } |
| | |
| | | * schema. |
| | | * <p> |
| | | * If {@code attributeValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type. |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * with this entry (usually the default schema). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * <b>NOTE:</b> When {@code attribute} is non-empty, this method implements |
| | | * LDAP Modify add semantics. |
| | |
| | | * with this entry (usually the default schema). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The name of the attribute whose presence in this entry is to |
| | |
| | | * with this entry (usually the default schema). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * <b>NOTE:</b> This method implements LDAP Modify delete semantics. |
| | | * |
| | |
| | | * with this entry (usually the default schema). |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * <b>NOTE:</b> This method implements LDAP Modify replace semantics as |
| | | * described in <a href="http://tools.ietf.org/html/rfc4511#section-4.6" |
| | |
| | | * attribute description and assertion value. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | public static Filter approx(final String attributeDescription, final Object assertionValue) { |
| | | Reject.ifNull(attributeDescription, assertionValue); |
| | | return new Filter(new ApproxMatchImpl(attributeDescription, ByteString |
| | | .valueOf(assertionValue))); |
| | | .valueOfObject(assertionValue))); |
| | | } |
| | | |
| | | /** |
| | |
| | | * description and assertion value. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | public static Filter equality(final String attributeDescription, final Object assertionValue) { |
| | | Reject.ifNull(attributeDescription, assertionValue); |
| | | return new Filter(new EqualityMatchImpl(attributeDescription, ByteString |
| | | .valueOf(assertionValue))); |
| | | .valueOfObject(assertionValue))); |
| | | } |
| | | |
| | | /** |
| | |
| | | * </pre> |
| | | * |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * <b>Note:</b> assertion values do not and should not be escaped before |
| | | * passing them to constructors like {@link #equality(String, Object)}. |
| | |
| | | */ |
| | | public static String escapeAssertionValue(final Object assertionValue) { |
| | | Reject.ifNull(assertionValue); |
| | | final ByteString bytes = ByteString.valueOf(assertionValue); |
| | | final ByteString bytes = ByteString.valueOfObject(assertionValue); |
| | | final StringBuilder builder = new StringBuilder(bytes.length()); |
| | | valueToFilterString(builder, bytes); |
| | | return builder.toString(); |
| | |
| | | * Creates a new {@code extensible match} filter. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param matchingRule |
| | | * The matching rule name, may be {@code null} if |
| | |
| | | "matchingRule and/or attributeDescription must not be null"); |
| | | Reject.ifNull(assertionValue); |
| | | return new Filter(new ExtensibleMatchImpl(matchingRule, attributeDescription, ByteString |
| | | .valueOf(assertionValue), dnAttributes)); |
| | | .valueOfObject(assertionValue), dnAttributes)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * attribute description and assertion value. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | final Object assertionValue) { |
| | | Reject.ifNull(attributeDescription, assertionValue); |
| | | return new Filter(new GreaterOrEqualImpl(attributeDescription, ByteString |
| | | .valueOf(assertionValue))); |
| | | .valueOfObject(assertionValue))); |
| | | } |
| | | |
| | | /** |
| | |
| | | * description and assertion value. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * <b>NOTE:</b> since LDAP does not support {@code greater than} |
| | | * comparisons, this method returns a filter of the form |
| | |
| | | * description and assertion value. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | public static Filter lessOrEqual(final String attributeDescription, final Object assertionValue) { |
| | | Reject.ifNull(attributeDescription, assertionValue); |
| | | return new Filter(new LessOrEqualImpl(attributeDescription, ByteString |
| | | .valueOf(assertionValue))); |
| | | .valueOfObject(assertionValue))); |
| | | } |
| | | |
| | | /** |
| | |
| | | * description and assertion value. |
| | | * <p> |
| | | * If {@code assertionValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * <p> |
| | | * <b>NOTE:</b> since LDAP does not support {@code less than} comparisons, |
| | | * this method returns a filter of the form |
| | |
| | | * description, {@code initial}, {@code final}, and {@code any} sub-strings. |
| | | * <p> |
| | | * Any substrings which are not instances of {@code ByteString} will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | } else if (anySubstrings.size() == 1) { |
| | | final Object anySubstring = anySubstrings.iterator().next(); |
| | | Reject.ifNull(anySubstring); |
| | | anySubstringList = Collections.singletonList(ByteString.valueOf(anySubstring)); |
| | | anySubstringList = Collections.singletonList(ByteString.valueOfObject(anySubstring)); |
| | | } else { |
| | | anySubstringList = new ArrayList<>(anySubstrings.size()); |
| | | for (final Object anySubstring : anySubstrings) { |
| | | Reject.ifNull(anySubstring); |
| | | |
| | | anySubstringList.add(ByteString.valueOf(anySubstring)); |
| | | anySubstringList.add(ByteString.valueOfObject(anySubstring)); |
| | | } |
| | | anySubstringList = Collections.unmodifiableList(anySubstringList); |
| | | } |
| | | |
| | | return new Filter(new SubstringsImpl(attributeDescription, |
| | | initialSubstring != null ? ByteString.valueOf(initialSubstring) : null, |
| | | anySubstringList, finalSubstring != null ? ByteString.valueOf(finalSubstring) |
| | | initialSubstring != null ? ByteString.valueOfObject(initialSubstring) : null, |
| | | anySubstringList, finalSubstring != null ? ByteString.valueOfObject(finalSubstring) |
| | | : null)); |
| | | } |
| | | |
| | |
| | | * </pre> |
| | | * |
| | | * Any assertion values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param template |
| | | * The filter template. |
| | |
| | | private static final Function<Object, ByteString, NeverThrowsException> OBJECT_TO_BYTESTRING = |
| | | new Function<Object, ByteString, NeverThrowsException>() { |
| | | public ByteString apply(final Object value) { |
| | | return ByteString.valueOf(value); |
| | | return ByteString.valueOfObject(value); |
| | | } |
| | | }; |
| | | |
| | |
| | | |
| | | /** |
| | | * Returns a function which converts an {@code Object} to a |
| | | * {@code ByteString} using the {@link ByteString#valueOf(Object)} method. |
| | | * {@code ByteString} using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @return A function which converts an {@code Object} to a |
| | | * {@code ByteString} . |
| | |
| | | // TODO: could optimize if objects is a LinkedAttribute having the |
| | | // same equality matching rule. |
| | | for (final Object value : values) { |
| | | if (!contains(attribute, ByteString.valueOf(value))) { |
| | | if (!contains(attribute, ByteString.valueOfObject(value))) { |
| | | return false; |
| | | } |
| | | } |
| | |
| | | |
| | | final Map<ByteString, T> valuesToRetain = new HashMap<>(values.size()); |
| | | for (final T value : values) { |
| | | valuesToRetain.put(normalizeValue(attribute, ByteString.valueOf(value)), value); |
| | | valuesToRetain.put(normalizeValue(attribute, ByteString.valueOfObject(value)), value); |
| | | } |
| | | |
| | | boolean modified = false; |
| | |
| | | boolean retained = false; |
| | | for (final T value : values) { |
| | | final ByteString normalizedValue = |
| | | normalizeValue(attribute, ByteString.valueOf(value)); |
| | | normalizeValue(attribute, ByteString.valueOfObject(value)); |
| | | if (normalizedSingleValue.equals(normalizedValue)) { |
| | | if (missingValues == null) { |
| | | // We can stop now. |
| | |
| | | * single attribute value. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | * attribute values. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | * attribute values. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | * default schema. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | * the default schema. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | */ |
| | | public LinkedAttribute(final String attributeDescription, final Object value) { |
| | | this(attributeDescription); |
| | | add(ByteString.valueOf(value)); |
| | | add(ByteString.valueOfObject(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * default schema. |
| | | * <p> |
| | | * Any attribute values which are not instances of {@code ByteString} will |
| | | * be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeDescription |
| | | * The attribute description. |
| | |
| | | @Override |
| | | public boolean contains(final Object value) { |
| | | Reject.ifNull(value); |
| | | return pimpl.contains(this, ByteString.valueOf(value)); |
| | | return pimpl.contains(this, ByteString.valueOfObject(value)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | @Override |
| | | public boolean remove(final Object value) { |
| | | Reject.ifNull(value); |
| | | return pimpl.remove(this, ByteString.valueOf(value)); |
| | | return pimpl.remove(this, ByteString.valueOfObject(value)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | } |
| | | final Result result = newResult(ResultCode.SUCCESS); |
| | | if (pageSize > 0) { |
| | | final ByteString cookie = numberOfResults == pageSize ? ByteString.valueOf(String.valueOf(position)) |
| | | final ByteString cookie = numberOfResults == pageSize ? ByteString.valueOfUtf8(String.valueOf(position)) |
| | | : ByteString.empty(); |
| | | result.addControl(SimplePagedResultsControl.newControl(true, 0, cookie)); |
| | | } |
| | |
| | | * Creates a new RDN using the provided attribute type and value. |
| | | * <p> |
| | | * If {@code attributeValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type. |
| | |
| | | * using the default schema. |
| | | * <p> |
| | | * If {@code attributeValue} is not an instance of {@code ByteString} then |
| | | * it will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * it will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param attributeType |
| | | * The attribute type. |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | public ByteString getValue() { |
| | | return ByteString.valueOf(authorizationID); |
| | | return ByteString.valueOfUtf8(authorizationID); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * Creates a new control having the provided OID, criticality, and value. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param oid |
| | | * The numeric OID associated with this control. |
| | |
| | | public static GenericControl newControl(final String oid, final boolean isCritical, |
| | | final Object value) { |
| | | return new GenericControl(oid, isCritical, (value == null) ? null : ByteString |
| | | .valueOf(value)); |
| | | .valueOfObject(value)); |
| | | } |
| | | |
| | | private final String oid; |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | * Portions Copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | } |
| | | }; |
| | | |
| | | private static final ByteString CONTROL_VALUE = ByteString.valueOf("0"); |
| | | private static final ByteString CONTROL_VALUE = ByteString.valueOfUtf8("0"); |
| | | |
| | | /** |
| | | * Creates a new Netscape password expired response control. |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2013-2014 ForgeRock AS |
| | | * Portions copyright 2013-2015 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | public ByteString getValue() { |
| | | return ByteString.valueOf(String.valueOf(secondsUntilExpiration)); |
| | | return ByteString.valueOfUtf8(String.valueOf(secondsUntilExpiration)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | public ByteString getValue() { |
| | | return ByteString.valueOf(authorizationID); |
| | | return ByteString.valueOfUtf8(authorizationID); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | private Client(final AnonymousSASLBindRequestImpl initialBindRequest, |
| | | final String serverName) { |
| | | super(initialBindRequest); |
| | | setNextSASLCredentials(ByteString.valueOf(initialBindRequest.getTraceString())); |
| | | setNextSASLCredentials(ByteString.valueOfUtf8(initialBindRequest.getTraceString())); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | * Sets the assertion value to be compared. |
| | | * <p> |
| | | * If the assertion value is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param value |
| | | * The assertion value to be compared. |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | @Override |
| | | public CompareRequest setAssertionValue(final Object value) { |
| | | Reject.ifNull(value); |
| | | this.assertionValue = ByteString.valueOf(value); |
| | | this.assertionValue = ByteString.valueOfObject(value); |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | * is defined by the specification of this extended request. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param value |
| | | * TThe value associated with this extended request, or |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | @Override |
| | | public GenericExtendedRequest setValue(final Object value) { |
| | | this.requestValue = value != null ? ByteString.valueOf(value) : null; |
| | | this.requestValue = value != null ? ByteString.valueOfObject(value) : null; |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | * with this modify request. |
| | | * <p> |
| | | * If the attribute value is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param type |
| | | * The type of modification to be performed. |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | * identity may or may not be a distinguished name. |
| | | * <p> |
| | | * If {@code userIdentity} is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param userIdentity |
| | | * The identity of the user whose password is to be modified, or |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | @Override |
| | | public PasswordModifyExtendedRequest setUserIdentity(final Object userIdentity) { |
| | | this.userIdentity = (userIdentity != null) ? ByteString.valueOf(userIdentity) : null; |
| | | this.userIdentity = (userIdentity != null) ? ByteString.valueOfObject(userIdentity) : null; |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions copyright 2011-2015 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | * attribute name, and assertion value. |
| | | * <p> |
| | | * If the assertion value is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param name |
| | | * The distinguished name of the entry to be compared. |
| | |
| | | final AttributeDescription attributeDescription, final Object assertionValue) { |
| | | Reject.ifNull(name, attributeDescription, assertionValue); |
| | | return new CompareRequestImpl(name, attributeDescription, ByteString |
| | | .valueOf(assertionValue)); |
| | | .valueOfObject(assertionValue)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * attribute name, and assertion value decoded using the default schema. |
| | | * <p> |
| | | * If the assertion value is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param name |
| | | * The distinguished name of the entry to be compared. |
| | |
| | | final String attributeDescription, final Object assertionValue) { |
| | | Reject.ifNull(name, attributeDescription, assertionValue); |
| | | return new CompareRequestImpl(DN.valueOf(name), AttributeDescription |
| | | .valueOf(attributeDescription), ByteString.valueOf(assertionValue)); |
| | | .valueOf(attributeDescription), ByteString.valueOfObject(assertionValue)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * optional value. |
| | | * <p> |
| | | * If the request value is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param requestName |
| | | * The dotted-decimal representation of the unique OID |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | * is defined by the specification of this extended result. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param value |
| | | * The value associated with this extended result, or |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | |
| | | @Override |
| | | public GenericExtendedResult setValue(final Object value) { |
| | | this.responseValue = value != null ? ByteString.valueOf(value) : null; |
| | | this.responseValue = value != null ? ByteString.valueOfObject(value) : null; |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | * format is defined by the specification of this intermediate response. |
| | | * <p> |
| | | * If {@code value} is not an instance of {@code ByteString} then it will be |
| | | * converted using the {@link ByteString#valueOf(Object)} method. |
| | | * converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param value |
| | | * The value associated with this intermediate response, or |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | |
| | | @Override |
| | | public GenericIntermediateResponse setValue(final Object value) { |
| | | this.responseValue = value != null ? ByteString.valueOf(value) : null; |
| | | this.responseValue = value != null ? ByteString.valueOfObject(value) : null; |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | builder.append(getReferralURIs()); |
| | | if (password != null) { |
| | | builder.append(", genPassword="); |
| | | builder.append(ByteString.valueOf(password)); |
| | | builder.append(ByteString.valueOfBytes(password)); |
| | | } |
| | | builder.append(", controls="); |
| | | builder.append(getControls()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | * name and value. |
| | | * <p> |
| | | * If the response value is not an instance of {@code ByteString} then it |
| | | * will be converted using the {@link ByteString#valueOf(Object)} method. |
| | | * will be converted using the {@link ByteString#valueOfObject(Object)} method. |
| | | * |
| | | * @param responseName |
| | | * The dotted-decimal representation of the unique OID |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | |
| | | |
| | | @Override |
| | | public ByteString getValue() { |
| | | return (authorizationID != null) ? ByteString.valueOf(authorizationID) : null; |
| | | return (authorizationID != null) ? ByteString.valueOfUtf8(authorizationID) : null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | return valueBuffer.toByteString(); |
| | | } |
| | | if (length > 0) { |
| | | return ByteString.valueOf(reader.read(length)); |
| | | return ByteString.valueOfUtf8(reader.read(length)); |
| | | } |
| | | return ByteString.empty(); |
| | | } |
| | |
| | | normalizedValue.append('$'); |
| | | normalizedValue.append(authPWComponents[2]); |
| | | |
| | | return ByteString.valueOf(normalizedValue); |
| | | return ByteString.valueOfUtf8(normalizedValue); |
| | | } |
| | | } |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_ATTR_SYNTAX_BIT_STRING_TOO_SHORT; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.*; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | final String valueString = value.toString().toUpperCase(); |
| | | |
| | | final int length = valueString.length(); |
| | | if (length < 3) { |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_BIT_STRING_TOO_SHORT.get(value.toString()); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_BIT_STRING_TOO_SHORT.get(value)); |
| | | } |
| | | |
| | | if (valueString.charAt(0) != '\'' || valueString.charAt(length - 2) != '\'' |
| | | || valueString.charAt(length - 1) != 'B') { |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_BIT_STRING_NOT_QUOTED.get(value.toString()); |
| | | throw DecodeException.error(message); |
| | | if (valueString.charAt(0) != '\'' |
| | | || valueString.charAt(length - 1) != 'B' |
| | | || valueString.charAt(length - 2) != '\'') { |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_BIT_STRING_NOT_QUOTED.get(value)); |
| | | } |
| | | |
| | | for (int i = 1; i < length - 2; i++) { |
| | |
| | | // These characters are fine. |
| | | break; |
| | | default: |
| | | final LocalizableMessage message = |
| | | WARN_ATTR_SYNTAX_BIT_STRING_INVALID_BIT.get(value.toString(), String |
| | | .valueOf(valueString.charAt(i))); |
| | | throw DecodeException.error(message); |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_BIT_STRING_INVALID_BIT.get(value, valueString.charAt(i))); |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(valueString); |
| | | return ByteString.valueOfUtf8(valueString); |
| | | } |
| | | } |
| | |
| | | final String string = SchemaUtils.readQuotedString(reader); |
| | | |
| | | // Grab the substring between the start pos and the current pos |
| | | return ByteString.valueOf(string); |
| | | return ByteString.valueOfUtf8(string); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(metaphone); |
| | | return ByteString.valueOfUtf8(metaphone); |
| | | } |
| | | |
| | | /** |
| | |
| | | throw DecodeException.error(WARN_ATTR_SYNTAX_LDAPSYNTAX_ENUM_INVALID_VALUE.get(value |
| | | .toString(), syntax.getName())); |
| | | } |
| | | return ByteString.valueOf(index); |
| | | return ByteString.valueOfInt(index); |
| | | } |
| | | |
| | | } |
| | |
| | | final List<String> entryStrings = new ArrayList<>(entries.size()); |
| | | |
| | | for (final String entry : entries) { |
| | | final String normalized = normalize(ByteString.valueOf(entry)); |
| | | final String normalized = normalize(ByteString.valueOfUtf8(entry)); |
| | | if (!entryStrings.contains(normalized)) { |
| | | entryStrings.add(normalized); |
| | | } |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | try { |
| | | return ByteString.valueOf(GeneralizedTime.valueOf(value.toString()).getTimeInMillis()); |
| | | return ByteString.valueOfLong(GeneralizedTime.valueOf(value.toString()).getTimeInMillis()); |
| | | } catch (LocalizedIllegalArgumentException e) { |
| | | throw DecodeException.error(e.getMessageObject()); |
| | | } |
| | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | | try { |
| | | return ByteString.valueOf(GeneralizedTime.valueOf(value.toString()).getTimeInMillis()); |
| | | return ByteString.valueOfLong(GeneralizedTime.valueOf(value.toString()).getTimeInMillis()); |
| | | } catch (LocalizedIllegalArgumentException e) { |
| | | throw DecodeException.error(e.getMessageObject()); |
| | | } |
| | |
| | | final String definition = assertionValue.toString(); |
| | | final SubstringReader reader = new SubstringReader(definition); |
| | | final int intValue = SchemaUtils.readRuleID(reader); |
| | | return defaultAssertion(ByteString.valueOf(intValue)); |
| | | return defaultAssertion(ByteString.valueOfInt(intValue)); |
| | | } catch (final Exception e) { |
| | | logger.debug(LocalizableMessage.raw("%s", e)); |
| | | |
| | |
| | | reader.skipWhitespaces(); |
| | | |
| | | // The next set of characters must be the OID. |
| | | return ByteString.valueOf(SchemaUtils.readRuleID(reader)); |
| | | return ByteString.valueOfObject(SchemaUtils.readRuleID(reader)); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) { |
| | | return ByteString.valueOf(normalize(value)); |
| | | return ByteString.valueOfUtf8(normalize(value)); |
| | | } |
| | | |
| | | private String normalize(final ByteSequence value) { |
| | |
| | | final String definition = value.toString(); |
| | | final SubstringReader reader = new SubstringReader(definition); |
| | | final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS)); |
| | | return ByteString.valueOf(resolveNames(schema, oid)); |
| | | return ByteString.valueOfUtf8(resolveNames(schema, oid)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | // The next set of characters must be the OID. |
| | | final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS)); |
| | | return ByteString.valueOf(resolveNames(schema, oid)); |
| | | return ByteString.valueOfUtf8(resolveNames(schema, oid)); |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 Manuel Gaupp |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | /** |
| | | * The value representing just one space character. |
| | | */ |
| | | public static final ByteString SINGLE_SPACE_VALUE = ByteString.valueOf(" "); |
| | | public static final ByteString SINGLE_SPACE_VALUE = ByteString.valueOfUtf8(" "); |
| | | |
| | | /** |
| | | * The normalized true value. |
| | | */ |
| | | public static final ByteString TRUE_VALUE = ByteString.valueOf("TRUE"); |
| | | public static final ByteString TRUE_VALUE = ByteString.valueOfUtf8("TRUE"); |
| | | |
| | | /** |
| | | * The normalized false value. |
| | | */ |
| | | public static final ByteString FALSE_VALUE = ByteString.valueOf("FALSE"); |
| | | public static final ByteString FALSE_VALUE = ByteString.valueOfUtf8("FALSE"); |
| | | |
| | | /** |
| | | * The name of the time zone for universal coordinated time (UTC). |
| | |
| | | return singleSpaceOrEmpty(value); |
| | | } |
| | | trimUnnecessarySpacesInStringList(buffer); |
| | | return ByteString.valueOf(buffer); |
| | | return ByteString.valueOfUtf8(buffer); |
| | | } |
| | | |
| | | private static void trimUnnecessarySpacesInStringList(StringBuilder buffer) { |
| | |
| | | if (buffer.length() == 0) { |
| | | return singleSpaceOrEmpty(value); |
| | | } |
| | | return ByteString.valueOf(buffer); |
| | | return ByteString.valueOfUtf8(buffer); |
| | | } |
| | | |
| | | static ByteString normalizeIA5StringAttributeValue(final ByteSequence value, boolean trim, boolean foldCase) |
| | |
| | | return singleSpaceOrEmpty(value); |
| | | } |
| | | throwIfIA5IllegalCharacter(buffer, value); |
| | | return ByteString.valueOf(buffer); |
| | | return ByteString.valueOfUtf8(buffer); |
| | | } |
| | | |
| | | static void throwDecodeException(LocalizedLogger logger, LocalizableMessage message) throws DecodeException { |
| | |
| | | if (buffer.length() == 0) { |
| | | return ByteString.empty(); |
| | | } |
| | | return ByteString.valueOf(buffer); |
| | | return ByteString.valueOfUtf8(buffer); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer); |
| | | return ByteString.valueOfUtf8(buffer); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | return ByteString.valueOf(buffer); |
| | | return ByteString.valueOfUtf8(buffer); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public final ByteString normalizeAttributeValue(Schema schema, ByteSequence value) throws DecodeException { |
| | | try { |
| | | return ByteString.valueOf(GeneralizedTime.valueOf(value.toString()).getTimeInMillis()); |
| | | return ByteString.valueOfLong(GeneralizedTime.valueOf(value.toString()).getTimeInMillis()); |
| | | } catch (final LocalizedIllegalArgumentException e) { |
| | | throw error(e.getMessageObject()); |
| | | } |
| | |
| | | |
| | | long delta = (second + minute * 60 + hour * 3600 + day * 24 * 3600 + week * 7 * 24 * 3600) * 1000; |
| | | long now = timeService.now(); |
| | | return ByteString.valueOf(signed ? now - delta : now + delta); |
| | | return ByteString.valueOfLong(signed ? now - delta : now + delta); |
| | | } |
| | | |
| | | } |
| | |
| | | final long uuidLow64 = uuid128Bytes.readLong(); |
| | | final long uuid64 = uuidHigh64 ^ uuidLow64; |
| | | final int hash32 = ((int) (uuid64 >> 32)) ^ (int) uuid64; |
| | | return ByteString.valueOf(hash32); |
| | | return ByteString.valueOfInt(hash32); |
| | | } |
| | | } |
| | |
| | | final ByteSequence seq2 = value.subSequence(closingBracePos + 1, value.length()); |
| | | StaticUtils.toLowerCase(seq1, builder); |
| | | builder.append(seq2); |
| | | return ByteString.valueOf(builder); |
| | | return ByteString.valueOfUtf8(builder); |
| | | } else { |
| | | return value.toByteString(); |
| | | } |
| | |
| | | pos++; |
| | | } |
| | | |
| | | value = ByteString.valueOf(ldifLine.substring(pos)); |
| | | value = ByteString.valueOfUtf8(ldifLine.substring(pos)); |
| | | } |
| | | } |
| | | return value; |
| | |
| | | |
| | | final void writeKeyAndValue(final CharSequence key, final CharSequence value) |
| | | throws IOException { |
| | | writeKeyAndValue(key, ByteString.valueOf(value)); |
| | | writeKeyAndValue(key, ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | final void writeLine(final CharSequence line) throws IOException { |
| | |
| | | */ |
| | | private static final Comparator<byte[]> DN_ORDER = new Comparator<byte[]>() { |
| | | public int compare(byte[] b1, byte[] b2) { |
| | | final ByteString bs = ByteString.valueOf(b1); |
| | | final ByteString bs2 = ByteString.valueOf(b2); |
| | | final ByteString bs = ByteString.valueOfBytes(b1); |
| | | final ByteString bs2 = ByteString.valueOfBytes(b2); |
| | | return bs.compareTo(bs2); |
| | | } |
| | | }; |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package com.forgerock.opendj.util; |
| | |
| | | final ConditionResult result) throws Exception { |
| | | // Take any caseExact matching rule. |
| | | final MatchingRule rule = Schema.getCoreSchema().getMatchingRule("2.5.13.5"); |
| | | final Assertion assertion = rule.getAssertion(ByteString.valueOf(value1)); |
| | | final Assertion assertion = rule.getAssertion(ByteString.valueOfUtf8(value1)); |
| | | final ByteString normalizedValue2 = |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value2)); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value2)); |
| | | final ConditionResult liveResult = assertion.matches(normalizedValue2); |
| | | assertEquals(result, liveResult); |
| | | } |
| | |
| | | final ConditionResult result) throws Exception { |
| | | // Take any caseExact matching rule. |
| | | final MatchingRule rule = Schema.getCoreSchema().getMatchingRule("2.5.13.2"); |
| | | final Assertion assertion = rule.getAssertion(ByteString.valueOf(value1)); |
| | | final Assertion assertion = rule.getAssertion(ByteString.valueOfUtf8(value1)); |
| | | final ByteString normalizedValue2 = |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value2)); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value2)); |
| | | final ConditionResult liveResult = assertion.matches(normalizedValue2); |
| | | assertEquals(result, liveResult); |
| | | } |
| | |
| | | public void intermediateResponse(int messageID, IntermediateResponse response) |
| | | throws DecodeException, IOException { |
| | | assertThat(response.getOID()).isEqualTo(oid); |
| | | assertThat(response.getValue()).isEqualTo(ByteString.valueOf(responseValue)); |
| | | assertThat(response.getValue()).isEqualTo(ByteString.valueOfUtf8(responseValue)); |
| | | } |
| | | } }; |
| | | } |
| | |
| | | |
| | | Object[] unrecognizedMessage() { |
| | | final byte messageTag = 0x01; |
| | | final ByteString messageBytes = ByteString.valueOf("message"); |
| | | final ByteString messageBytes = ByteString.valueOfUtf8("message"); |
| | | return new Object[] { new LDAPWrite() { |
| | | @Override |
| | | public void perform(LDAPWriter<? extends ASN1Writer> writer) throws IOException { |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2012 ForgeRock AS. |
| | | * Copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | @Test |
| | | public void testAsByteString() { |
| | | Entry e = new LinkedHashMapEntry("dn: cn=test", "objectClass: test", "type: cn"); |
| | | assertThat(e.parseAttribute("type").asByteString()).isEqualTo(ByteString.valueOf("cn")); |
| | | assertThat(e.parseAttribute("type").asByteString()).isEqualTo(ByteString.valueOfUtf8("cn")); |
| | | } |
| | | |
| | | @Test |
| | | public void testAsByteStringDefault() { |
| | | Entry e = new LinkedHashMapEntry("dn: cn=test", "objectClass: test", "type: cn"); |
| | | assertThat(e.parseAttribute("type").asByteString(ByteString.valueOf("sn"))).isEqualTo( |
| | | ByteString.valueOf("cn")); |
| | | assertThat(e.parseAttribute("type").asByteString(ByteString.valueOfUtf8("sn"))).isEqualTo( |
| | | ByteString.valueOfUtf8("cn")); |
| | | } |
| | | |
| | | @Test |
| | |
| | | @Test |
| | | public void testAsByteStringMissingDefault() { |
| | | Entry e = new LinkedHashMapEntry("dn: cn=test", "objectClass: test"); |
| | | assertThat(e.parseAttribute("type").asByteString(ByteString.valueOf("sn"))).isEqualTo( |
| | | ByteString.valueOf("sn")); |
| | | assertThat(e.parseAttribute("type").asByteString(ByteString.valueOfUtf8("sn"))).isEqualTo( |
| | | ByteString.valueOfUtf8("sn")); |
| | | } |
| | | |
| | | @Test(expectedExceptions = { NoSuchElementException.class }) |
| | |
| | | |
| | | @Test |
| | | public void testByteStringBuilderCompareTo() { |
| | | final ByteString orig = ByteString.valueOf("this is a ByteString"); |
| | | final ByteString orig = ByteString.valueOfUtf8("this is a ByteString"); |
| | | final ByteStringBuilder builder = new ByteStringBuilder(orig); |
| | | Assert.assertEquals(builder.compareTo(builder), 0); |
| | | Assert.assertEquals(builder.compareTo(orig), 0); |
| | |
| | | |
| | | @Test |
| | | public void testSubSequenceCompareTo() { |
| | | final ByteString orig = ByteString.valueOf("this is a ByteString"); |
| | | final ByteString orig = ByteString.valueOfUtf8("this is a ByteString"); |
| | | final ByteStringBuilder builder = new ByteStringBuilder(orig); |
| | | final ByteSequence subSequence = builder.subSequence(0, 4); |
| | | Assert.assertEquals(subSequence.compareTo(subSequence), 0); |
| | |
| | | |
| | | @Test |
| | | public void testSubSequenceEqualsAndHashCode() { |
| | | final ByteString orig = ByteString.valueOf("this is a ByteString"); |
| | | final ByteString orig = ByteString.valueOfUtf8("this is a ByteString"); |
| | | final ByteStringBuilder builder = new ByteStringBuilder(orig); |
| | | final ByteSequence subSequence = builder.subSequence(0, builder.length()); |
| | | final ByteSequence subSequence2 = builder.subSequence(0, builder.length()); |
| | |
| | | { ByteString.valueOfBase64("AAA="), new byte[] { 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64("AAAA"), new byte[] { 0x00, 0x00, 0x00 }}, |
| | | { ByteString.valueOfBase64("AAAAAA=="), new byte[] { 0x00, 0x00, 0x00, 0x00 }}, |
| | | { ByteString.valueOf(1), |
| | | { ByteString.valueOfInt(1), |
| | | new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 } }, |
| | | { ByteString.valueOf(Integer.MAX_VALUE), |
| | | { ByteString.valueOfInt(Integer.MAX_VALUE), |
| | | new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF } }, |
| | | { ByteString.valueOf(Integer.MIN_VALUE), |
| | | { ByteString.valueOfInt(Integer.MIN_VALUE), |
| | | new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00 } }, |
| | | { |
| | | ByteString.valueOf(Long.MAX_VALUE), |
| | | ByteString.valueOfLong(Long.MAX_VALUE), |
| | | new byte[] { (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, |
| | | (byte) 0xFF, (byte) 0xFF, (byte) 0xFF } }, |
| | | { |
| | | ByteString.valueOf(Long.MIN_VALUE), |
| | | ByteString.valueOfLong(Long.MIN_VALUE), |
| | | new byte[] { (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, |
| | | (byte) 0x00, (byte) 0x00, (byte) 0x00 } }, |
| | | { ByteString.valueOf("cn=testvalue"), "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOf((Object) "cn=testvalue"), "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOf("cn=testvalue".toCharArray()), "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOf((Object) "cn=testvalue".toCharArray()), |
| | | { ByteString.valueOfUtf8("cn=testvalue"), "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOfObject((Object) "cn=testvalue"), "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOfUtf8("cn=testvalue".toCharArray()), "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOfObject((Object) "cn=testvalue".toCharArray()), |
| | | "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.valueOf(new byte[0]), new byte[0] }, |
| | | { ByteString.valueOf(testBytes), testBytes }, |
| | | { ByteString.valueOf((Object) testBytes), testBytes }, |
| | | { ByteString.valueOf(ByteString.valueOf("cn=testvalue")), |
| | | { ByteString.valueOfBytes(new byte[0]), new byte[0] }, |
| | | { ByteString.valueOfBytes(testBytes), testBytes }, |
| | | { ByteString.valueOfObject((Object) testBytes), testBytes }, |
| | | { ByteString.valueOfObject(ByteString.valueOfUtf8("cn=testvalue")), |
| | | "cn=testvalue".getBytes("UTF-8") }, |
| | | { ByteString.wrap(new byte[0]), new byte[0] }, |
| | | { |
| | |
| | | |
| | | @DataProvider(name = "byteStringIntegerProvider") |
| | | public Object[][] byteStringIntegerProvider() { |
| | | return new Object[][] { { ByteString.valueOf(0), 0 }, { ByteString.valueOf(1), 1 }, |
| | | { ByteString.valueOf(Integer.MAX_VALUE), Integer.MAX_VALUE }, |
| | | { ByteString.valueOf(Integer.MIN_VALUE), Integer.MIN_VALUE }, }; |
| | | return new Object[][] { { ByteString.valueOfInt(0), 0 }, { ByteString.valueOfInt(1), 1 }, |
| | | { ByteString.valueOfInt(Integer.MAX_VALUE), Integer.MAX_VALUE }, |
| | | { ByteString.valueOfInt(Integer.MIN_VALUE), Integer.MIN_VALUE }, }; |
| | | } |
| | | |
| | | @DataProvider(name = "byteStringLongProvider") |
| | | public Object[][] byteStringLongProvider() { |
| | | return new Object[][] { { ByteString.valueOf(0L), 0L }, { ByteString.valueOf(1L), 1L }, |
| | | { ByteString.valueOf(Long.MAX_VALUE), Long.MAX_VALUE }, |
| | | { ByteString.valueOf(Long.MIN_VALUE), Long.MIN_VALUE } }; |
| | | return new Object[][] { { ByteString.valueOfLong(0L), 0L }, { ByteString.valueOfLong(1L), 1L }, |
| | | { ByteString.valueOfLong(Long.MAX_VALUE), Long.MAX_VALUE }, |
| | | { ByteString.valueOfLong(Long.MIN_VALUE), Long.MIN_VALUE } }; |
| | | } |
| | | |
| | | @DataProvider(name = "byteStringCharArrayProvider") |
| | |
| | | |
| | | @Test(dataProvider = "byteStringCharArrayProvider") |
| | | public void testFromStringToCharArray(final String s) { |
| | | ByteString bs = ByteString.valueOf(s); |
| | | ByteString bs = ByteString.valueOfUtf8(s); |
| | | Assert.assertTrue(Arrays.equals(bs.toCharArray(), s.toCharArray())); |
| | | } |
| | | |
| | | @Test(dataProvider = "byteStringCharArrayProvider") |
| | | public void testFromCharArrayToCharArray(final String s) { |
| | | final char[] chars = s.toCharArray(); |
| | | ByteString bs = ByteString.valueOf(chars); |
| | | ByteString bs = ByteString.valueOfUtf8(chars); |
| | | Assert.assertTrue(Arrays.equals(bs.toCharArray(), chars)); |
| | | } |
| | | |
| | | @Test(dataProvider = "byteStringCharArrayProvider") |
| | | public void testValueOfCharArray(final String s) { |
| | | ByteString bs = ByteString.valueOf(s.toCharArray()); |
| | | ByteString bs = ByteString.valueOfUtf8(s.toCharArray()); |
| | | Assert.assertEquals(bs.toString(), s); |
| | | } |
| | | |
| | |
| | | } |
| | | result[len++] = new Object[] { ByteString.empty(), new byte[0], 0 }; |
| | | result[len++] = new Object[] { ByteString.empty(), "bla".getBytes("UTF8"), -3 }; |
| | | result[len++] = new Object[] { ByteString.valueOf("bla"), new byte[0], 3 }; |
| | | result[len++] = new Object[] { ByteString.valueOf("bla"), "bla".getBytes("UTF8"), 0 }; |
| | | result[len++] = new Object[] { ByteString.valueOfUtf8("bla"), new byte[0], 3 }; |
| | | result[len++] = new Object[] { ByteString.valueOfUtf8("bla"), "bla".getBytes("UTF8"), 0 }; |
| | | return result; |
| | | } |
| | | |
| | |
| | | .isFalse(); |
| | | assertThat(entry.getAttribute(AD_CN)).hasSize(1); |
| | | assertThat(duplicateValues).hasSize(1); |
| | | assertThat(duplicateValues).contains(ByteString.valueOf("test")); |
| | | assertThat(duplicateValues).contains(ByteString.valueOfUtf8("test")); |
| | | } |
| | | |
| | | @Test(dataProvider = "EntryFactory") |
| | |
| | | @DataProvider(name = "filterstrings") |
| | | public Object[][] getFilterStrings() throws Exception { |
| | | final Filter equal = |
| | | Filter.equality("objectClass", ByteString.valueOf("\\test*(Value)")); |
| | | final Filter equal2 = Filter.equality("objectClass", ByteString.valueOf("")); |
| | | Filter.equality("objectClass", ByteString.valueOfUtf8("\\test*(Value)")); |
| | | final Filter equal2 = Filter.equality("objectClass", ByteString.valueOfUtf8("")); |
| | | final Filter approx = |
| | | Filter.approx("sn", ByteString.valueOf("\\test*(Value)")); |
| | | Filter.approx("sn", ByteString.valueOfUtf8("\\test*(Value)")); |
| | | final Filter greater = |
| | | Filter.greaterOrEqual("employeeNumber", ByteString |
| | | .valueOf("\\test*(Value)")); |
| | | .valueOfUtf8("\\test*(Value)")); |
| | | final Filter less = |
| | | Filter.lessOrEqual("dob", ByteString.valueOf("\\test*(Value)")); |
| | | Filter.lessOrEqual("dob", ByteString.valueOfUtf8("\\test*(Value)")); |
| | | final Filter presense = Filter.present("login"); |
| | | |
| | | final ArrayList<ByteString> any = new ArrayList<>(0); |
| | | final ArrayList<ByteString> multiAny = new ArrayList<>(1); |
| | | multiAny.add(ByteString.valueOf("\\wid*(get)")); |
| | | multiAny.add(ByteString.valueOf("*")); |
| | | multiAny.add(ByteString.valueOfUtf8("\\wid*(get)")); |
| | | multiAny.add(ByteString.valueOfUtf8("*")); |
| | | |
| | | final Filter substring1 = |
| | | Filter.substrings("givenName", ByteString.valueOf("\\Jo*()"), any, |
| | | ByteString.valueOf("\\n*()")); |
| | | Filter.substrings("givenName", ByteString.valueOfUtf8("\\Jo*()"), any, |
| | | ByteString.valueOfUtf8("\\n*()")); |
| | | final Filter substring2 = |
| | | Filter.substrings("givenName", ByteString.valueOf("\\Jo*()"), multiAny, |
| | | ByteString.valueOf("\\n*()")); |
| | | Filter.substrings("givenName", ByteString.valueOfUtf8("\\Jo*()"), multiAny, |
| | | ByteString.valueOfUtf8("\\n*()")); |
| | | final Filter substring3 = |
| | | Filter.substrings("givenName", ByteString.valueOf(""), any, ByteString |
| | | .valueOf("\\n*()")); |
| | | Filter.substrings("givenName", ByteString.valueOfUtf8(""), any, ByteString |
| | | .valueOfUtf8("\\n*()")); |
| | | final Filter substring4 = |
| | | Filter.substrings("givenName", ByteString.valueOf("\\Jo*()"), any, |
| | | ByteString.valueOf("")); |
| | | Filter.substrings("givenName", ByteString.valueOfUtf8("\\Jo*()"), any, |
| | | ByteString.valueOfUtf8("")); |
| | | final Filter substring5 = |
| | | Filter.substrings("givenName", ByteString.valueOf(""), multiAny, |
| | | ByteString.valueOf("")); |
| | | Filter.substrings("givenName", ByteString.valueOfUtf8(""), multiAny, |
| | | ByteString.valueOfUtf8("")); |
| | | final Filter extensible1 = |
| | | Filter.extensible("2.4.6.8.19", "cn", ByteString |
| | | .valueOf("\\John* (Doe)"), false); |
| | | .valueOfUtf8("\\John* (Doe)"), false); |
| | | final Filter extensible2 = |
| | | Filter.extensible("2.4.6.8.19", "cn", ByteString |
| | | .valueOf("\\John* (Doe)"), true); |
| | | .valueOfUtf8("\\John* (Doe)"), true); |
| | | final Filter extensible3 = |
| | | Filter.extensible("2.4.6.8.19", null, ByteString |
| | | .valueOf("\\John* (Doe)"), true); |
| | | .valueOfUtf8("\\John* (Doe)"), true); |
| | | final Filter extensible4 = |
| | | Filter.extensible(null, "cn", ByteString.valueOf("\\John* (Doe)"), |
| | | Filter.extensible(null, "cn", ByteString.valueOfUtf8("\\John* (Doe)"), |
| | | true); |
| | | final Filter extensible5 = |
| | | Filter.extensible("2.4.6.8.19", null, ByteString |
| | | .valueOf("\\John* (Doe)"), false); |
| | | .valueOfUtf8("\\John* (Doe)"), false); |
| | | |
| | | final ArrayList<Filter> list1 = new ArrayList<>(); |
| | | list1.add(equal); |
| | |
| | | @Test |
| | | public void testMatcher() throws Exception { |
| | | final Filter equal = |
| | | Filter.equality("cn", ByteString.valueOf("\\test*(Value)")); |
| | | Filter.equality("cn", ByteString.valueOfUtf8("\\test*(Value)")); |
| | | final LinkedHashMapEntry entry = |
| | | new LinkedHashMapEntry(DN.valueOf("cn=\\test*(Value),dc=org")); |
| | | entry.addAttribute("cn", "\\test*(Value)"); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | |
| | | attribute.add(1); |
| | | attribute.add("a value"); |
| | | attribute.add(ByteString.valueOf("another value")); |
| | | attribute.add(ByteString.valueOfUtf8("another value")); |
| | | |
| | | Assert.assertTrue(attribute.contains(1)); |
| | | Assert.assertTrue(attribute.contains("a value")); |
| | | Assert.assertTrue(attribute.contains(ByteString.valueOf("another value"))); |
| | | Assert.assertTrue(attribute.contains(ByteString.valueOfUtf8("another value"))); |
| | | |
| | | Assert.assertEquals(attribute.size(), 3); |
| | | Assert.assertTrue(attribute.remove(1)); |
| | |
| | | Assert.assertEquals(attribute.size(), 2); |
| | | Assert.assertTrue(attribute.remove("a value")); |
| | | Assert.assertEquals(attribute.size(), 1); |
| | | Assert.assertTrue(attribute.remove(ByteString.valueOf("another value"))); |
| | | Assert.assertTrue(attribute.remove(ByteString.valueOfUtf8("another value"))); |
| | | Assert.assertEquals(attribute.size(), 0); |
| | | } |
| | | |
| | | @Test |
| | | public void testAdd() { |
| | | Attribute a = new LinkedAttribute("test"); |
| | | Assert.assertTrue(a.add(ByteString.valueOf("value1"))); |
| | | Assert.assertFalse(a.add(ByteString.valueOf("value1"))); |
| | | Assert.assertTrue(a.add(ByteString.valueOf("value2"))); |
| | | Assert.assertFalse(a.add(ByteString.valueOf("value2"))); |
| | | Assert.assertTrue(a.add(ByteString.valueOf("value3"))); |
| | | Assert.assertFalse(a.add(ByteString.valueOf("value3"))); |
| | | Assert.assertTrue(a.add(ByteString.valueOfUtf8("value1"))); |
| | | Assert.assertFalse(a.add(ByteString.valueOfUtf8("value1"))); |
| | | Assert.assertTrue(a.add(ByteString.valueOfUtf8("value2"))); |
| | | Assert.assertFalse(a.add(ByteString.valueOfUtf8("value2"))); |
| | | Assert.assertTrue(a.add(ByteString.valueOfUtf8("value3"))); |
| | | Assert.assertFalse(a.add(ByteString.valueOfUtf8("value3"))); |
| | | Assert.assertEquals(a.size(), 3); |
| | | Iterator<ByteString> i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | } |
| | | |
| | |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test"); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOf("value1")), null)); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOfUtf8("value1")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test"); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")), null)); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | // addAll to a single-valued attribute. |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(a.addAll(Collections.<ByteString> emptyList(), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOf("value2")), null)); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOfUtf8("value2")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOf("value2"), ByteString |
| | | .valueOf("value3")), null)); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOfUtf8("value2"), ByteString |
| | | .valueOfUtf8("value3")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | // addAll to a multi-valued attribute. |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString.valueOf("value2")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(a.addAll(Collections.<ByteString> emptyList(), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString.valueOf("value2")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOf("value3")), null)); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOfUtf8("value3")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString.valueOf("value2")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")), null)); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertTrue(a.addAll(Arrays.asList(ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value4")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value4")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | } |
| | | |
| | |
| | | Assert.assertTrue(a.isEmpty()); |
| | | Assert.assertEquals(a.size(), 0); |
| | | |
| | | a.add(ByteString.valueOf("value1")); |
| | | a.add(ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(a.isEmpty()); |
| | | Assert.assertEquals(a.size(), 1); |
| | | a.clear(); |
| | | Assert.assertTrue(a.isEmpty()); |
| | | Assert.assertEquals(a.size(), 0); |
| | | |
| | | a.add(ByteString.valueOf("value1")); |
| | | a.add(ByteString.valueOf("value2")); |
| | | a.add(ByteString.valueOfUtf8("value1")); |
| | | a.add(ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(a.isEmpty()); |
| | | Assert.assertEquals(a.size(), 2); |
| | | a.clear(); |
| | | Assert.assertTrue(a.isEmpty()); |
| | | Assert.assertEquals(a.size(), 0); |
| | | |
| | | a.add(ByteString.valueOf("value1")); |
| | | a.add(ByteString.valueOf("value2")); |
| | | a.add(ByteString.valueOf("value3")); |
| | | a.add(ByteString.valueOfUtf8("value1")); |
| | | a.add(ByteString.valueOfUtf8("value2")); |
| | | a.add(ByteString.valueOfUtf8("value3")); |
| | | Assert.assertFalse(a.isEmpty()); |
| | | Assert.assertEquals(a.size(), 3); |
| | | a.clear(); |
| | |
| | | @Test |
| | | public void testContains() { |
| | | Attribute a = new LinkedAttribute("test"); |
| | | Assert.assertFalse(a.contains(ByteString.valueOf("value4"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOfUtf8("value4"))); |
| | | |
| | | a.add(ByteString.valueOf("value1")); |
| | | Assert.assertTrue(a.contains(ByteString.valueOf("value1"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOf("value4"))); |
| | | a.add(ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(a.contains(ByteString.valueOfUtf8("value1"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOfUtf8("value4"))); |
| | | |
| | | a.add(ByteString.valueOf("value2")); |
| | | Assert.assertTrue(a.contains(ByteString.valueOf("value1"))); |
| | | Assert.assertTrue(a.contains(ByteString.valueOf("value2"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOf("value4"))); |
| | | a.add(ByteString.valueOfUtf8("value2")); |
| | | Assert.assertTrue(a.contains(ByteString.valueOfUtf8("value1"))); |
| | | Assert.assertTrue(a.contains(ByteString.valueOfUtf8("value2"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOfUtf8("value4"))); |
| | | |
| | | a.add(ByteString.valueOf("value3")); |
| | | Assert.assertTrue(a.contains(ByteString.valueOf("value1"))); |
| | | Assert.assertTrue(a.contains(ByteString.valueOf("value2"))); |
| | | Assert.assertTrue(a.contains(ByteString.valueOf("value3"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOf("value4"))); |
| | | a.add(ByteString.valueOfUtf8("value3")); |
| | | Assert.assertTrue(a.contains(ByteString.valueOfUtf8("value1"))); |
| | | Assert.assertTrue(a.contains(ByteString.valueOfUtf8("value2"))); |
| | | Assert.assertTrue(a.contains(ByteString.valueOfUtf8("value3"))); |
| | | Assert.assertFalse(a.contains(ByteString.valueOfUtf8("value4"))); |
| | | } |
| | | |
| | | @Test |
| | | public void testContainsAll() { |
| | | Attribute a = new LinkedAttribute("test"); |
| | | Assert.assertTrue(a.containsAll(Collections.<ByteString> emptyList())); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOf("value1")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3")))); |
| | | |
| | | a.add(ByteString.valueOf("value1")); |
| | | a.add(ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(a.containsAll(Collections.<ByteString> emptyList())); |
| | | Assert.assertTrue(a.containsAll(Arrays.asList(ByteString.valueOf("value1")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3")))); |
| | | Assert.assertTrue(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3")))); |
| | | |
| | | a.add(ByteString.valueOf("value2")); |
| | | a.add(ByteString.valueOfUtf8("value2")); |
| | | Assert.assertTrue(a.containsAll(Collections.<ByteString> emptyList())); |
| | | Assert.assertTrue(a.containsAll(Arrays.asList(ByteString.valueOf("value1")))); |
| | | Assert.assertTrue(a.containsAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3")))); |
| | | Assert.assertTrue(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1")))); |
| | | Assert.assertTrue(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")))); |
| | | Assert.assertFalse(a.containsAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3")))); |
| | | } |
| | | |
| | | @Test |
| | |
| | | // Expected. |
| | | } |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | Assert.assertEquals(a.firstValue(), ByteString.valueOf("value1")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(a.firstValue(), ByteString.valueOfUtf8("value1")); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(a.firstValue(), ByteString.valueOf("value1")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(a.firstValue(), ByteString.valueOfUtf8("value1")); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value2"), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(a.firstValue(), ByteString.valueOf("value2")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value2"), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(a.firstValue(), ByteString.valueOfUtf8("value2")); |
| | | } |
| | | |
| | | @Test |
| | |
| | | Iterator<ByteString> i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString.valueOf("value2")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString.valueOfUtf8("value2")); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | } |
| | | |
| | | @Test |
| | | public void testRemove() { |
| | | Attribute a = new LinkedAttribute("test"); |
| | | Assert.assertFalse(a.remove(ByteString.valueOf("value1"))); |
| | | Assert.assertFalse(a.remove(ByteString.valueOfUtf8("value1"))); |
| | | Iterator<ByteString> i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | Assert.assertFalse(a.remove(ByteString.valueOf("value2"))); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(a.remove(ByteString.valueOfUtf8("value2"))); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | Assert.assertTrue(a.remove(ByteString.valueOf("value1"))); |
| | | Assert.assertTrue(a.remove(ByteString.valueOfUtf8("value1"))); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString.valueOf("value2")); |
| | | Assert.assertFalse(a.remove(ByteString.valueOf("value3"))); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(a.remove(ByteString.valueOfUtf8("value3"))); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | Assert.assertTrue(a.remove(ByteString.valueOf("value1"))); |
| | | Assert.assertTrue(a.remove(ByteString.valueOfUtf8("value1"))); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | Assert.assertTrue(a.remove(ByteString.valueOf("value2"))); |
| | | Assert.assertTrue(a.remove(ByteString.valueOfUtf8("value2"))); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | } |
| | |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test"); |
| | | Assert.assertFalse(a.removeAll(Arrays.asList(ByteString.valueOf("value1")), null)); |
| | | Assert.assertFalse(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test"); |
| | | Assert.assertFalse(a.removeAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")))); |
| | | Assert.assertFalse(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")))); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | // removeAll from single-valued attribute. |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(a.removeAll(Collections.<ByteString> emptyList(), null)); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1")), null)); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = new LinkedAttribute("test", ByteString.valueOf("value1")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")))); |
| | | a = new LinkedAttribute("test", ByteString.valueOfUtf8("value1")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")))); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | // removeAll from multi-valued attribute. |
| | | a = |
| | | new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")); |
| | | new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")); |
| | | Assert.assertFalse(a.removeAll(Collections.<ByteString> emptyList(), null)); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value4")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value1")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value4")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = |
| | | new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1")), null)); |
| | | new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value4")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value2")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value4")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = |
| | | new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2")), null)); |
| | | new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value4")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value3")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value4")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = |
| | | new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3")), null)); |
| | | new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertTrue(i.hasNext()); |
| | | Assert.assertEquals(i.next(), ByteString.valueOf("value4")); |
| | | Assert.assertEquals(i.next(), ByteString.valueOfUtf8("value4")); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = |
| | | new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString.valueOf("value4")), |
| | | new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString.valueOfUtf8("value4")), |
| | | null)); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | |
| | | a = |
| | | new LinkedAttribute("test", ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString |
| | | .valueOf("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOf("value1"), ByteString |
| | | .valueOf("value2"), ByteString.valueOf("value3"), ByteString.valueOf("value4"), |
| | | ByteString.valueOf("value5")), null)); |
| | | new LinkedAttribute("test", ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString |
| | | .valueOfUtf8("value4")); |
| | | Assert.assertTrue(a.removeAll(Arrays.asList(ByteString.valueOfUtf8("value1"), ByteString |
| | | .valueOfUtf8("value2"), ByteString.valueOfUtf8("value3"), ByteString.valueOfUtf8("value4"), |
| | | ByteString.valueOfUtf8("value5")), null)); |
| | | i = a.iterator(); |
| | | Assert.assertFalse(i.hasNext()); |
| | | } |
| | |
| | | ATTR_TYPE_DC = Schema.getCoreSchema().getAttributeType("dc"); |
| | | ATTR_TYPE_CN = Schema.getCoreSchema().getAttributeType("cn"); |
| | | // Set the avas. |
| | | ATTR_VALUE_DC_ORG = new AVA(ATTR_TYPE_DC, ByteString.valueOf("org")); |
| | | ATTR_VALUE_DC_ORG = new AVA(ATTR_TYPE_DC, ByteString.valueOfUtf8("org")); |
| | | } |
| | | |
| | | /** "org" bytestring. */ |
| | | private static final ByteString ORG = ByteString.valueOf("org"); |
| | | private static final ByteString ORG = ByteString.valueOfUtf8("org"); |
| | | |
| | | /** |
| | | * RDN test data provider. |
| | |
| | | */ |
| | | @Test |
| | | public void testEscaping() { |
| | | RDN rdn = new RDN(ATTR_TYPE_DC, ByteString.valueOf(" ")); |
| | | RDN rdn = new RDN(ATTR_TYPE_DC, ByteString.valueOfUtf8(" ")); |
| | | assertEquals(rdn.toString(), "dc=\\ "); |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS |
| | | * Copyright 2013-2015 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | GenericExtendedRequest decoded = GenericExtendedRequest.DECODER.decodeExtendedRequest(copy, |
| | | new DecodeOptions()); |
| | | assertThat(decoded.getOID()).isEqualTo(oid); |
| | | assertThat(decoded.getValue()).isEqualTo(ByteString.valueOf(value)); |
| | | assertThat(decoded.getValue()).isEqualTo(ByteString.valueOfUtf8(value)); |
| | | assertThat(decoded.getControls().contains(control)).isTrue(); |
| | | } catch (DecodeException e) { |
| | | throw e; |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | final PasswordModifyExtendedRequest copy = (PasswordModifyExtendedRequest) copyOf(original); |
| | | copy.setNewPassword(password.toCharArray()); |
| | | copy.setOldPassword(oldPassword.toCharArray()); |
| | | copy.setUserIdentity(ByteString.valueOf(userIdentity)); |
| | | copy.setUserIdentity(ByteString.valueOfUtf8(userIdentity)); |
| | | |
| | | assertThat(copy.getNewPassword()).isEqualTo(password.getBytes()); |
| | | assertThat(original.getNewPassword()).isNull(); |
| | |
| | | new DecodeOptions()); |
| | | assertThat(decoded.getNewPassword()).isEqualTo(password.getBytes()); |
| | | assertThat(decoded.getOldPassword()).isEqualTo(oldPassword.getBytes()); |
| | | assertThat(decoded.getUserIdentity()).isEqualTo(ByteString.valueOf(userIdentity)); |
| | | assertThat(decoded.getUserIdentity()).isEqualTo(ByteString.valueOfUtf8(userIdentity)); |
| | | assertThat(decoded.getControls().contains(control)).isTrue(); |
| | | } catch (DecodeException e) { |
| | | throw e; |
| | |
| | | |
| | | @Test(dataProvider = "invalidAssertions", expectedExceptions = { DecodeException.class }) |
| | | public void testInvalidAssertion(String assertionValue) throws Exception { |
| | | getRule().getAssertion(null, valueOf(assertionValue)); |
| | | getRule().getAssertion(null, valueOfUtf8(assertionValue)); |
| | | } |
| | | |
| | | @DataProvider |
| | |
| | | public void testValidAssertions(String attrValue, String assertionValue, ConditionResult expected) |
| | | throws Exception { |
| | | final MatchingRuleImpl rule = getRule(); |
| | | final ByteString normValue = rule.normalizeAttributeValue(null, valueOf(attrValue)); |
| | | Assertion assertion = rule.getAssertion(null, valueOf(assertionValue)); |
| | | final ByteString normValue = rule.normalizeAttributeValue(null, valueOfUtf8(attrValue)); |
| | | Assertion assertion = rule.getAssertion(null, valueOfUtf8(assertionValue)); |
| | | assertEquals(assertion.matches(normValue), expected); |
| | | } |
| | | |
| | |
| | | @SuppressWarnings("unchecked") |
| | | public void testSubstringCreateIndexQueryForFinalWithMultipleSubqueries() throws Exception { |
| | | Assertion assertion = getRule().getSubstringAssertion( |
| | | null, null, Collections.EMPTY_LIST, valueOf("this")); |
| | | null, null, Collections.EMPTY_LIST, valueOfUtf8("this")); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | |
| | | @Test |
| | | public void testSubstringCreateIndexQueryForAllNoSubqueries() throws Exception { |
| | | Assertion assertion = getRule().getSubstringAssertion( |
| | | null, valueOf("abc"), Arrays.asList(toByteStrings("def", "ghi")), valueOf("jkl")); |
| | | null, valueOfUtf8("abc"), Arrays.asList(toByteStrings("def", "ghi")), valueOfUtf8("jkl")); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | |
| | | @SuppressWarnings("unchecked") |
| | | public void testSubstringCreateIndexQueryWithInitial() throws Exception { |
| | | Assertion assertion = getRule().getSubstringAssertion( |
| | | null, valueOf("aa"), Collections.EMPTY_LIST, null); |
| | | null, valueOfUtf8("aa"), Collections.EMPTY_LIST, null); |
| | | |
| | | assertEquals( |
| | | assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions())), |
| | |
| | | Assertions.assertThat(indexer.getIndexID()).isEqualTo(SMR_CASE_EXACT_OID + ":" + options.substringKeySize()); |
| | | |
| | | final TreeSet<ByteString> keys = new TreeSet<>(); |
| | | indexer.createKeys(Schema.getCoreSchema(), valueOf("ABCDE"), keys); |
| | | indexer.createKeys(Schema.getCoreSchema(), valueOfUtf8("ABCDE"), keys); |
| | | Assertions.assertThat(keys).containsOnly((Object[]) toByteStrings("ABC", "BCD", "CDE", "DE", "E")); |
| | | } |
| | | |
| | | private ByteString[] toByteStrings(String... strings) { |
| | | final ByteString[] results = new ByteString[strings.length]; |
| | | for (int i = 0; i < strings.length; i++) { |
| | | results[i] = valueOf(strings[i]); |
| | | results[i] = valueOfUtf8(strings[i]); |
| | | } |
| | | return results; |
| | | } |
| | |
| | | final Syntax syntax = getRule(); |
| | | |
| | | final LocalizableMessageBuilder reason = new LocalizableMessageBuilder(); |
| | | final Boolean liveResult = syntax.valueIsAcceptable(ByteString.valueOf(value), reason); |
| | | final Boolean liveResult = syntax.valueIsAcceptable(ByteString.valueOfUtf8(value), reason); |
| | | assertEquals(liveResult, result, |
| | | syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | final String value2, final ConditionResult result) throws Exception { |
| | | // normalize the 2 provided values |
| | | final ByteString normalizedValue1 = |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value1)); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value1)); |
| | | |
| | | // check that the approximatelyMatch return the expected result. |
| | | final ConditionResult liveResult = |
| | | rule.getAssertion(ByteString.valueOf(value2)).matches(normalizedValue1); |
| | | rule.getAssertion(ByteString.valueOfUtf8(value2)).matches(normalizedValue1); |
| | | assertEquals(result, liveResult); |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2014 Manuel Gaupp |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | + "CN=Babs Jensen,OU=Product Development,L=Cupertione,C=US\" }"; |
| | | |
| | | return new Object[][]{ |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOf(assertion), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOf(assertionWithSpaces), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOf(assertionDNencoded), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOf(assertionWrong), ConditionResult.FALSE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOfUtf8(assertion), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOfUtf8(assertionWithSpaces), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOfUtf8(assertionDNencoded), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOfUtf8(assertionWrong), ConditionResult.FALSE}, |
| | | {ByteString.valueOfBase64(incompleteCert), ByteString.valueOfBase64(incompleteCert), ConditionResult.TRUE}, |
| | | {ByteString.valueOfBase64(validcert1), ByteString.valueOfBase64(validcert1), ConditionResult.TRUE} |
| | | }; |
| | |
| | | MatchingRule rule = getRule(); |
| | | |
| | | // normalize the provided assertion values |
| | | rule.getAssertion(ByteString.valueOf(value)); |
| | | rule.getAssertion(ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | MatchingRule rule = getRule(); |
| | | |
| | | // normalize the provided assertion value |
| | | rule.getAssertion(ByteString.valueOf(value)); |
| | | rule.getAssertion(ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS. |
| | | * Portions copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014 Manuel Gaupp |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | |
| | | return new Object[][]{ |
| | | {ByteString.valueOfBase64(validcert1), true}, |
| | | {ByteString.valueOf(validcert1), false}, |
| | | {ByteString.valueOfUtf8(validcert1), false}, |
| | | {ByteString.valueOfBase64(invalidcert1), false}, |
| | | {ByteString.valueOfBase64(brokencert1), false}, |
| | | {ByteString.valueOf("invalid"), false} |
| | | {ByteString.valueOfUtf8("invalid"), false} |
| | | }; |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | ByteString value = ByteString.valueOf("abc"); |
| | | ByteString value = ByteString.valueOfUtf8("abc"); |
| | | MatchingRule matchingRule = getRule(); |
| | | Assertion assertion = matchingRule.getAssertion(value); |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | ByteString value = ByteString.valueOf("abc"); |
| | | ByteString value = ByteString.valueOfUtf8("abc"); |
| | | MatchingRule matchingRule = getRule(); |
| | | Assertion assertion = matchingRule.getAssertion(value); |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | ByteString value = ByteString.valueOf("abc"); |
| | | ByteString value = ByteString.valueOfUtf8("abc"); |
| | | MatchingRule matchingRule = getRule(); |
| | | Assertion assertion = matchingRule.getAssertion(value); |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | ByteString value = ByteString.valueOf("abc"); |
| | | ByteString value = ByteString.valueOfUtf8("abc"); |
| | | MatchingRule matchingRule = getRule(); |
| | | Assertion assertion = matchingRule.getAssertion(value); |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | ByteString value = ByteString.valueOf("abc"); |
| | | ByteString value = ByteString.valueOfUtf8("abc"); |
| | | MatchingRule matchingRule = getRule(); |
| | | Assertion assertion = matchingRule.getAssertion(value); |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | ByteString value = ByteString.valueOf("a*c"); |
| | | ByteString value = ByteString.valueOfUtf8("a*c"); |
| | | MatchingRule matchingRule = getRule(); |
| | | Assertion assertion = matchingRule.getAssertion(value); |
| | | |
| | | String indexQuery = assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(), false)); |
| | | |
| | | ByteString binit = matchingRule.normalizeAttributeValue(ByteString.valueOf("a")); |
| | | ByteString bfinal = matchingRule.normalizeAttributeValue(ByteString.valueOf("c")); |
| | | ByteString binit = matchingRule.normalizeAttributeValue(ByteString.valueOfUtf8("a")); |
| | | ByteString bfinal = matchingRule.normalizeAttributeValue(ByteString.valueOfUtf8("c")); |
| | | assertEquals(indexQuery, |
| | | "intersect[" |
| | | + "rangeMatch(fr.shared, '" + binit.toHexString() + "' <= value < '00 54'), " |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | public void testNormalization(final String value1, final String value2) throws Exception { |
| | | final MatchingRule rule = getRule(); |
| | | final ByteString normalizedValue1 = |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value1)); |
| | | final ByteString expectedValue = ByteString.valueOf(value2); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value1)); |
| | | final ByteString expectedValue = ByteString.valueOfUtf8(value2); |
| | | assertEquals(normalizedValue1, expectedValue); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS. |
| | | * Portions copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | final Schema schema = builder.toSchema(); |
| | | final Syntax syntax = schema.getSyntax("3.3.3"); |
| | | final MatchingRule rule = syntax.getOrderingMatchingRule(); |
| | | final ByteString monday = ByteString.valueOf("monday"); |
| | | final ByteString monday = ByteString.valueOfUtf8("monday"); |
| | | final ByteString normMonday = rule.normalizeAttributeValue(monday); |
| | | final ByteString tuesday = ByteString.valueOf("tuesday"); |
| | | final ByteString tuesday = ByteString.valueOfUtf8("tuesday"); |
| | | final ByteString normTuesday = rule.normalizeAttributeValue(tuesday); |
| | | final ByteString normThursday = rule.normalizeAttributeValue(ByteString.valueOf("thursday")); |
| | | final ByteString normThursday = rule.normalizeAttributeValue(ByteString.valueOfUtf8("thursday")); |
| | | assertEquals(rule.getGreaterOrEqualAssertion(monday).matches(normThursday), TRUE); |
| | | assertEquals(rule.getLessOrEqualAssertion(monday).matches(normThursday), FALSE); |
| | | assertEquals(rule.getGreaterOrEqualAssertion(tuesday).matches(normMonday), FALSE); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | final ByteString normalizedValue1 = |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value1)); |
| | | final Assertion assertion = rule.getAssertion(ByteString.valueOf(value2)); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value1)); |
| | | final Assertion assertion = rule.getAssertion(ByteString.valueOfUtf8(value2)); |
| | | |
| | | final ConditionResult liveResult = assertion.matches(normalizedValue1); |
| | | assertEquals(result, liveResult); |
| | |
| | | // Get the instance of the rule to be tested. |
| | | final MatchingRule rule = getRule(); |
| | | |
| | | rule.getAssertion(ByteString.valueOf(value)); |
| | | rule.getAssertion(ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | // Get the instance of the rule to be tested. |
| | | final MatchingRule rule = getRule(); |
| | | |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | final MatchingRule ruleInstance = getRule(); |
| | | |
| | | final ByteString normalizedValue1 = |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOf(value1)); |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOfUtf8(value1)); |
| | | final ByteString normalizedValue2 = |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOf(value2)); |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOfUtf8(value2)); |
| | | |
| | | // Test the comparator |
| | | final int comp = normalizedValue1.compareTo(normalizedValue2); |
| | |
| | | Assert.assertTrue(result < 0); |
| | | } |
| | | |
| | | Assertion a = ruleInstance.getGreaterOrEqualAssertion(ByteString.valueOf(value2)); |
| | | Assertion a = ruleInstance.getGreaterOrEqualAssertion(ByteString.valueOfUtf8(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result >= 0)); |
| | | |
| | | a = ruleInstance.getLessOrEqualAssertion(ByteString.valueOf(value2)); |
| | | a = ruleInstance.getLessOrEqualAssertion(ByteString.valueOfUtf8(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result <= 0)); |
| | | |
| | | a = ruleInstance.getAssertion(ByteString.valueOf(value2)); |
| | | a = ruleInstance.getAssertion(ByteString.valueOfUtf8(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), ConditionResult.valueOf(result < 0)); |
| | | } |
| | | |
| | |
| | | final MatchingRule ruleInstance = getRule(); |
| | | |
| | | // normalize the 2 provided values |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | Assertion assertion = getRule().getAssertion(ByteString.valueOf("2012Y")); |
| | | Assertion assertion = getRule().getAssertion(ByteString.valueOfUtf8("2012Y")); |
| | | |
| | | String indexQuery = assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(), false)); |
| | | assertThat(indexQuery).matches( |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | Assertion assertion = getRule().getAssertion(ByteString.valueOf("+5m")); |
| | | Assertion assertion = getRule().getAssertion(ByteString.valueOfUtf8("+5m")); |
| | | |
| | | String indexQuery = assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(), false)); |
| | | assertThat(indexQuery).startsWith("rangeMatch(" + EMR_GENERALIZED_TIME_NAME + ", '") |
| | |
| | | |
| | | @Test |
| | | public void testCreateIndexQuery() throws Exception { |
| | | Assertion assertion = getRule().getAssertion(ByteString.valueOf("+5m")); |
| | | Assertion assertion = getRule().getAssertion(ByteString.valueOfUtf8("+5m")); |
| | | |
| | | String indexQuery = assertion.createIndexQuery(new FakeIndexQueryFactory(newIndexingOptions(), false)); |
| | | assertThat(indexQuery).startsWith("rangeMatch(" + EMR_GENERALIZED_TIME_NAME + ", '' < value < '"); |
| | |
| | | CoreSchema.getOctetStringSyntax().toString(), false).toSchema(); |
| | | |
| | | // Ensure that the substituted syntax is usable. |
| | | assertThat(schema.getSyntax("9.9.9").valueIsAcceptable(ByteString.valueOf("test"), null)) |
| | | assertThat(schema.getSyntax("9.9.9").valueIsAcceptable(ByteString.valueOfUtf8("test"), null)) |
| | | .isTrue(); |
| | | } |
| | | |
| | |
| | | |
| | | // Ensure that the substituted rule is usable: was triggering a NPE with OPENDJ-1252. |
| | | assertThat( |
| | | schema.getMatchingRule("9.9.9").normalizeAttributeValue(ByteString.valueOf("test"))) |
| | | .isEqualTo(ByteString.valueOf("test")); |
| | | schema.getMatchingRule("9.9.9").normalizeAttributeValue(ByteString.valueOfUtf8("test"))) |
| | | .isEqualTo(ByteString.valueOfUtf8("test")); |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2015 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | @Test(dataProvider = "stringProvider") |
| | | public void testNormalizeStringProvider(String value, boolean trim, boolean foldCase, String expected) |
| | | throws Exception { |
| | | ByteString val = ByteString.valueOf(value); |
| | | ByteString val = ByteString.valueOfUtf8(value); |
| | | ByteString normValue = SchemaUtils.normalizeStringAttributeValue(val, trim, foldCase); |
| | | Assertions.assertThat(normValue.toString()).isEqualTo(expected); |
| | | } |
| | |
| | | @Test(dataProvider = "stringProvider") |
| | | public void testNormalizeIA5String(String value, boolean trim, boolean foldCase, String expected) |
| | | throws Exception { |
| | | ByteString val = ByteString.valueOf(value); |
| | | ByteString val = ByteString.valueOfUtf8(value); |
| | | ByteString normValue = SchemaUtils.normalizeIA5StringAttributeValue(val, trim, foldCase); |
| | | Assertions.assertThat(normValue.toString()).isEqualTo(expected); |
| | | } |
| | |
| | | @Test(dataProvider = "stringProvider") |
| | | public void testNormalizeStringList(String value, boolean trim, boolean foldCase, String expected) |
| | | throws Exception { |
| | | ByteString val = ByteString.valueOf(value); |
| | | ByteString val = ByteString.valueOfUtf8(value); |
| | | ByteString normValue = SchemaUtils.normalizeStringListAttributeValue(val, trim, foldCase); |
| | | Assertions.assertThat(normValue.toString()).isEqualTo(expected); |
| | | } |
| | |
| | | |
| | | @Test(dataProvider = "numericStringProvider") |
| | | public void testNormalizeNumericString(String value, String expected) throws Exception { |
| | | ByteString val = ByteString.valueOf(value); |
| | | ByteString val = ByteString.valueOfUtf8(value); |
| | | ByteString normValue = SchemaUtils.normalizeNumericStringAttributeValue(val); |
| | | Assertions.assertThat(normValue.toString()).isEqualTo(expected); |
| | | } |
| | |
| | | final MatchingRule rule = getRule(); |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOfUtf8(value)); |
| | | |
| | | final ConditionResult substringAssertionMatches = |
| | | rule.getSubstringAssertion(null, null, ByteString.valueOf(finalValue)).matches(normalizedValue); |
| | | rule.getSubstringAssertion(null, null, ByteString.valueOfUtf8(finalValue)).matches(normalizedValue); |
| | | final ConditionResult assertionMatches = |
| | | rule.getAssertion(ByteString.valueOf("*" + finalValue)).matches(normalizedValue); |
| | | rule.getAssertion(ByteString.valueOfUtf8("*" + finalValue)).matches(normalizedValue); |
| | | final String message = getMessage("final", rule, value, finalValue); |
| | | assertEquals(substringAssertionMatches, result, message); |
| | | assertEquals(assertionMatches, result, message); |
| | |
| | | final MatchingRule rule = getRule(); |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOfUtf8(value)); |
| | | |
| | | final ConditionResult substringAssertionMatches = |
| | | rule.getSubstringAssertion(ByteString.valueOf(initial), null, null).matches(normalizedValue); |
| | | rule.getSubstringAssertion(ByteString.valueOfUtf8(initial), null, null).matches(normalizedValue); |
| | | final ConditionResult assertionMatches = |
| | | rule.getAssertion(ByteString.valueOf(initial + "*")).matches(normalizedValue); |
| | | rule.getAssertion(ByteString.valueOfUtf8(initial + "*")).matches(normalizedValue); |
| | | final String message = getMessage("initial", rule, value, initial); |
| | | assertEquals(substringAssertionMatches, result, message); |
| | | assertEquals(assertionMatches, result, message); |
| | |
| | | |
| | | final List<ByteSequence> anyList = new ArrayList<>(anys.length); |
| | | for (final String middleSub : anys) { |
| | | anyList.add(ByteString.valueOf(middleSub)); |
| | | anyList.add(ByteString.valueOfUtf8(middleSub)); |
| | | } |
| | | rule.getSubstringAssertion(subInitial == null ? null : ByteString.valueOf(subInitial), anyList, |
| | | subFinal == null ? null : ByteString.valueOf(subFinal)); |
| | | rule.getSubstringAssertion(subInitial == null ? null : ByteString.valueOfUtf8(subInitial), anyList, |
| | | subFinal == null ? null : ByteString.valueOfUtf8(subFinal)); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (subFinal != null) { |
| | | assertionString.append(subFinal); |
| | | } |
| | | rule.getAssertion(ByteString.valueOf(assertionString.toString())); |
| | | rule.getAssertion(ByteString.valueOfUtf8(assertionString.toString())); |
| | | } |
| | | |
| | | /** |
| | |
| | | final MatchingRule rule = getRule(); |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOfUtf8(value)); |
| | | |
| | | final StringBuilder printableMiddleSubs = new StringBuilder(); |
| | | final List<ByteSequence> middleList = new ArrayList<>(middleSubs.length); |
| | |
| | | for (final String middleSub : middleSubs) { |
| | | printableMiddleSubs.append(middleSub); |
| | | printableMiddleSubs.append("*"); |
| | | middleList.add(ByteString.valueOf(middleSub)); |
| | | middleList.add(ByteString.valueOfUtf8(middleSub)); |
| | | } |
| | | |
| | | final ConditionResult substringAssertionMatches = |
| | | rule.getSubstringAssertion(null, middleList, null).matches(normalizedValue); |
| | | final ConditionResult assertionMatches = |
| | | rule.getAssertion(ByteString.valueOf(printableMiddleSubs)).matches(normalizedValue); |
| | | rule.getAssertion(ByteString.valueOfUtf8(printableMiddleSubs)).matches(normalizedValue); |
| | | final String message = getMessage("middle", rule, value, printableMiddleSubs.toString()); |
| | | assertEquals(substringAssertionMatches, result, message); |
| | | assertEquals(assertionMatches, result, message); |
| | |
| | | // Get the instance of the rule to be tested. |
| | | final MatchingRule rule = getRule(); |
| | | |
| | | rule.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | rule.normalizeAttributeValue(ByteString.valueOfUtf8(value)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | * Copyright 2012-2015 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | .addControl( |
| | | VirtualListViewRequestControl.newAssertionControl( |
| | | true, |
| | | ByteString.valueOf("Jensen"), |
| | | ByteString.valueOfUtf8("Jensen"), |
| | | 2, 2, contextID)); |
| | | |
| | | final SearchResultHandler resultHandler = new MySearchResultHandler(); |
| | |
| | | return ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue(); |
| | | } |
| | | } else { |
| | | attributeVal = ByteString.valueOf(remainder); |
| | | attributeVal = ByteString.valueOfUtf8(remainder); |
| | | } |
| | | } else { |
| | | attributeVal = ByteString.valueOf(remainder); |
| | | attributeVal = ByteString.valueOfUtf8(remainder); |
| | | } |
| | | |
| | | final CompareRequest compare = Requests.newCompareRequest("", attributeType, attributeVal); |
| | |
| | | } |
| | | |
| | | if (result.getGeneratedPassword() != null) { |
| | | println(INFO_LDAPPWMOD_GENERATED_PASSWORD.get(ByteString.valueOf( |
| | | println(INFO_LDAPPWMOD_GENERATED_PASSWORD.get(ByteString.valueOfBytes( |
| | | result.getGeneratedPassword()).toString())); |
| | | } |
| | | |
| | |
| | | try { |
| | | final int beforeCount = Integer.parseInt(tokenizer.nextToken()); |
| | | final int afterCount = Integer.parseInt(tokenizer.nextToken()); |
| | | final ByteString assertionValue = ByteString.valueOf(tokenizer.nextToken()); |
| | | final ByteString assertionValue = ByteString.valueOfUtf8(tokenizer.nextToken()); |
| | | search.addControl(VirtualListViewRequestControl.newAssertionControl(true, |
| | | assertionValue, beforeCount, afterCount, null)); |
| | | } catch (final Exception e) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS |
| | | * Portions copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | |
| | | final String valString = remainder.substring(idx + 1, remainder.length()); |
| | | if (valString.charAt(0) == ':') { |
| | | controlValue = ByteString.valueOf(valString.substring(1, valString.length())); |
| | | controlValue = ByteString.valueOfUtf8(valString.substring(1, valString.length())); |
| | | } else if (valString.charAt(0) == '<') { |
| | | // Read data from the file. |
| | | final String filePath = valString.substring(1, valString.length()); |
| | |
| | | return null; |
| | | } |
| | | } else { |
| | | controlValue = ByteString.valueOf(valString); |
| | | controlValue = ByteString.valueOfUtf8(valString); |
| | | } |
| | | |
| | | return GenericControl.newControl(controlOID, controlCriticality, controlValue); |
| | |
| | | + "client provided resource ID"); |
| | | } |
| | | } else { |
| | | entry.addAttribute(new LinkedAttribute(idAttribute, ByteString.valueOf(resourceId))); |
| | | entry.addAttribute(new LinkedAttribute(idAttribute, ByteString.valueOfUtf8(resourceId))); |
| | | } |
| | | final String rdnValue = entry.parseAttribute(dnAttribute).asString(); |
| | | final RDN rdn = new RDN(dnAttribute.getAttributeType(), rdnValue); |
| | |
| | | final Entry entry) throws ResourceException { |
| | | if (resourceId != null) { |
| | | entry.setName(baseDN.child(rdn(resourceId))); |
| | | entry.addAttribute(new LinkedAttribute(attribute, ByteString.valueOf(resourceId))); |
| | | entry.addAttribute(new LinkedAttribute(attribute, ByteString.valueOfUtf8(resourceId))); |
| | | } else if (entry.getAttribute(attribute) != null) { |
| | | entry.setName(baseDN.child(rdn(entry.parseAttribute(attribute).asString()))); |
| | | } else { |
| | |
| | | if (isJSONPrimitive(value)) { |
| | | final Syntax syntax = ad.getAttributeType().getSyntax(); |
| | | if (syntax.equals(getGeneralizedTimeSyntax())) { |
| | | return ByteString.valueOf(GeneralizedTime.valueOf(parseDateTime(value.toString()))); |
| | | return ByteString.valueOfObject(GeneralizedTime.valueOf(parseDateTime(value.toString()))); |
| | | } else { |
| | | return ByteString.valueOf(value); |
| | | return ByteString.valueOfObject(value); |
| | | } |
| | | } else { |
| | | throw new IllegalArgumentException("Unrecognized type of JSON value: " |