OPENDJ-1307 Migrate server ASN1 classes to SDK
ASN1 classes logging is throwing an UnsupportedOperationException while being used in the server. This exception is thrown by OpenDJLoggerAdapter from the opendj-slf4j-adapter in use in the server.
Changed OpenDJ SDK to use LocalizedLogger instead of raw slf4j-api (at least for IO category).
More work remains to switch all OpenDJ SDK to use LocalizedLogger instead of raw slf4j-api.
StaticUtils.java, *.java:
Removed IO_LOG + replaced every uses of it by using per class LocalizedLoggers.
pom.xml:
Added a compile time dependency to 18n-slf4j.
OpenDJLoggerAdapter.java:
Removed an empty line.
| | |
| | | <artifactId>forgerock-util</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.forgerock.commons</groupId> |
| | | <artifactId>i18n-slf4j</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.forgerock</groupId> |
| | | <artifactId>forgerock-build-tools</artifactId> |
| | | <version>${forgerockBuildToolsVersion}</version> |
| | |
| | | public static final Logger SCHEMA_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".schema"); |
| | | |
| | | /** |
| | | * The logger used by the SDK for IO related features (buffers, readers, writers). |
| | | */ |
| | | public static final Logger IO_LOG = LoggerFactory.getLogger(DEFAULT_LOGGER_NAME + ".io"); |
| | | |
| | | /** |
| | | * Indicates whether the SDK is being used in debug mode. In debug mode |
| | | * components may enable certain instrumentation in order to help debug |
| | | * applications. |
| | |
| | | public static StackTraceElement[] getStackTraceIfDebugEnabled() { |
| | | if (!DEBUG_ENABLED) { |
| | | return null; |
| | | } else { |
| | | final StackTraceElement[] stack = Thread.currentThread().getStackTrace(); |
| | | return Arrays.copyOfRange(stack, 2, stack.length); |
| | | } |
| | | final StackTraceElement[] stack = Thread.currentThread().getStackTrace(); |
| | | return Arrays.copyOfRange(stack, 2, stack.length); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.io; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.LinkedList; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteSequenceReader; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | |
| | | /** |
| | | * An ASN.1 reader that reads from a {@link ByteSequenceReader}. |
| | | */ |
| | | final class ASN1ByteSequenceReader extends AbstractASN1Reader implements ASN1Reader { |
| | | final class ASN1ByteSequenceReader extends AbstractASN1Reader { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private int state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | |
| | |
| | | } |
| | | |
| | | if (reader.remaining() > 0) { |
| | | IO_LOG.debug("Ignoring {} unused trailing bytes in ASN.1 SEQUENCE", |
| | | reader.remaining()); |
| | | logger.debug(LocalizableMessage.raw( |
| | | "Ignoring %d unused trailing bytes in ASN.1 SEQUENCE", reader.remaining())); |
| | | } |
| | | |
| | | reader = readerStack.removeFirst(); |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.io; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | |
| | | import java.util.LinkedList; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | |
| | | /** |
| | | * An ASN1Reader that reads from an input stream. |
| | | */ |
| | | final class ASN1InputStreamReader extends AbstractASN1Reader implements ASN1Reader { |
| | | final class ASN1InputStreamReader extends AbstractASN1Reader { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private int state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | |
| | | private byte peekType = 0; |
| | |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | if (IO_LOG.isTraceEnabled()) { |
| | | IO_LOG.trace("READ ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, String.valueOf(readByte != 0x00)); |
| | | } |
| | | logger.trace("READ ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", peekType, peekLength, readByte != 0x00); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return readByte != 0x00; |
| | | } |
| | |
| | | // Ignore all unused trailing components. |
| | | final SizeLimitInputStream subSq = (SizeLimitInputStream) in; |
| | | if (subSq.getSizeLimit() - subSq.getBytesRead() > 0) { |
| | | if (IO_LOG.isTraceEnabled()) { |
| | | IO_LOG.trace("Ignoring {} unused trailing bytes in ASN.1 SEQUENCE", |
| | | subSq.getSizeLimit() - subSq.getBytesRead()); |
| | | } |
| | | logger.trace("Ignoring %d unused trailing bytes in ASN.1 SEQUENCE", |
| | | subSq.getSizeLimit() - subSq.getBytesRead()); |
| | | subSq.skip(subSq.getSizeLimit() - subSq.getBytesRead()); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 END SEQUENCE"); |
| | | logger.trace("READ ASN.1 END SEQUENCE"); |
| | | |
| | | in = streamStack.removeFirst(); |
| | | |
| | |
| | | intValue = (intValue << 8) | (readByte & 0xFF); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 INTEGER(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, intValue); |
| | | logger.trace("READ ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", peekType, peekLength, intValue); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return intValue; |
| | |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 NULL(type=0x{}, length={})", |
| | | byteToHex(peekType), peekLength); |
| | | logger.trace("READ ASN.1 NULL(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | } |
| | |
| | | bytesNeeded -= bytesRead; |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return ByteString.wrap(value); |
| | |
| | | bytesNeeded -= bytesRead; |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength); |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return builder; |
| | | } |
| | |
| | | throw new RuntimeException("Unable to decode ASN.1 OCTETSTRING bytes as UTF-8 string ", e); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", |
| | | byteToHex(peekType), peekLength, str); |
| | | logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d, value=%s)", peekType, peekLength, str); |
| | | |
| | | return str; |
| | | } |
| | |
| | | |
| | | final SizeLimitInputStream subStream = new SizeLimitInputStream(in, peekLength); |
| | | |
| | | IO_LOG.trace("READ ASN.1 START SEQUENCE(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | logger.trace("READ ASN.1 START SEQUENCE(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | streamStack.addFirst(in); |
| | | in = subStream; |
| | |
| | | */ |
| | | package org.forgerock.opendj.io; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_SEQUENCE_WRITE_NOT_STARTED; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | |
| | |
| | | * An ASN1Writer implementation that outputs to an outputstream. |
| | | */ |
| | | final class ASN1OutputStreamWriter extends AbstractASN1Writer { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private final OutputStream rootStream; |
| | | private OutputStream out; |
| | | private final ArrayList<ByteStringBuilder> streamStack; |
| | |
| | | writeLength(1); |
| | | out.write(booleanValue ? ASN1.BOOLEAN_VALUE_TRUE : ASN1.BOOLEAN_VALUE_FALSE); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(type), 1, String.valueOf(booleanValue)); |
| | | logger.trace("WRITE ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", type, 1, booleanValue); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(childStream.length()); |
| | | childStream.copyTo(parentStream); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 END SEQUENCE(length={})", childStream.length()); |
| | | logger.trace("WRITE ASN.1 END SEQUENCE(length=%d)", childStream.length()); |
| | | |
| | | if (childStream.capacity() > maxBufferSize) { |
| | | // garbage collect excessively large buffers |
| | |
| | | || ((intValue & 0x0000007F) == intValue)) { |
| | | writeLength(1); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFFFF8000) == 0xFFFF8000)) |
| | | || ((intValue & 0x00007FFF) == intValue)) { |
| | | writeLength(2); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFF800000) == 0xFF800000)) |
| | | || ((intValue & 0x007FFFFF) == intValue)) { |
| | | writeLength(3); |
| | | out.write((byte) ((intValue >> 16) & 0xFF)); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, intValue); |
| | | } else { |
| | | writeLength(4); |
| | | out.write((byte) ((intValue >> 24) & 0xFF)); |
| | | out.write((byte) ((intValue >> 16) & 0xFF)); |
| | | out.write((byte) ((intValue >> 8) & 0xFF)); |
| | | out.write((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, intValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | || ((longValue & 0x000000000000007FL) == longValue)) { |
| | | writeLength(1); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFFFF8000L) == 0xFFFFFFFFFFFF8000L)) |
| | | || ((longValue & 0x0000000000007FFFL) == longValue)) { |
| | | writeLength(2); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFF800000L) == 0xFFFFFFFFFF800000L)) |
| | | || ((longValue & 0x00000000007FFFFFL) == longValue)) { |
| | | writeLength(3); |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFF80000000L) == 0xFFFFFFFF80000000L)) |
| | | || ((longValue & 0x000000007FFFFFFFL) == longValue)) { |
| | | writeLength(4); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFF8000000000L) == 0xFFFFFF8000000000L)) |
| | | || ((longValue & 0x0000007FFFFFFFFFL) == longValue)) { |
| | | writeLength(5); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 5, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 5, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFF800000000000L) == 0xFFFF800000000000L)) |
| | | || ((longValue & 0x00007FFFFFFFFFFFL) == longValue)) { |
| | | writeLength(6); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 6, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 6, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFF80000000000000L) == 0xFF80000000000000L)) |
| | | || ((longValue & 0x007FFFFFFFFFFFFFL) == longValue)) { |
| | | writeLength(7); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 7, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 7, longValue); |
| | | } else { |
| | | writeLength(8); |
| | | out.write((byte) ((longValue >> 56) & 0xFF)); |
| | |
| | | out.write((byte) ((longValue >> 16) & 0xFF)); |
| | | out.write((byte) ((longValue >> 8) & 0xFF)); |
| | | out.write((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 8, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 8, longValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | out.write(type); |
| | | writeLength(0); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 NULL(type=0x{}, length={})", byteToHex(type), 0); |
| | | logger.trace("WRITE ASN.1 NULL(type=0x%x, length=%d)", type, 0); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(length); |
| | | out.write(value, offset, length); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), length); |
| | | logger.trace("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, length); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(value.length()); |
| | | value.copyTo(out); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), value.length()); |
| | | |
| | | logger.trace("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, value.length()); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(bytes.length); |
| | | out.write(bytes); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", |
| | | byteToHex(type), bytes.length, value); |
| | | logger.trace("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d, value=%s)", type, bytes.length, value); |
| | | return this; |
| | | } |
| | | |
| | |
| | | out = streamStack.get(stackDepth).asOutputStream(); |
| | | } |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 START SEQUENCE(type=0x{})", byteToHex(type)); |
| | | logger.trace("WRITE ASN.1 START SEQUENCE(type=0x%x)", type); |
| | | return this; |
| | | } |
| | | |
| | |
| | | |
| | | package org.forgerock.opendj.io; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_MODIFICATION_DECODE_INVALID_MOD_TYPE; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_SEARCH_REQUEST_DECODE_INVALID_DEREF; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_SEARCH_REQUEST_DECODE_INVALID_SCOPE; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.Attribute; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | * The type of ASN.1 reader used for decoding elements. |
| | | */ |
| | | public final class LDAPReader<R extends ASN1Reader> { |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private final DecodeOptions options; |
| | | private final R reader; |
| | | |
| | |
| | | final int msgToAbandon = (int) reader.readInteger(LDAP.OP_TYPE_ABANDON_REQUEST); |
| | | final AbandonRequest message = Requests.newAbandonRequest(msgToAbandon); |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP ABANDON REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP ABANDON REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.abandonRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | final Entry entry = LDAP.readEntry(reader, LDAP.OP_TYPE_ADD_REQUEST, options); |
| | | final AddRequest message = Requests.newAddRequest(entry); |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP ADD REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP ADD REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.addRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP ADD RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP ADD RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.addResult(messageID, message); |
| | | } |
| | | |
| | |
| | | final GenericBindRequest request = |
| | | Requests.newGenericBindRequest(authName, authType, authBytes); |
| | | readControls(request); |
| | | IO_LOG.trace("DECODE LDAP BIND REQUEST(messageID={}, auth=0x{}, request={})", |
| | | messageID, byteToHex(request.getAuthenticationType()), request); |
| | | logger.trace("DECODE LDAP BIND REQUEST(messageID=%d, auth=0x%x, request=%s)", |
| | | messageID, request.getAuthenticationType(), request); |
| | | |
| | | handler.bindRequest(messageID, protocolVersion, request); |
| | | } finally { |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP BIND RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP BIND RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.bindResult(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP COMPARE REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP COMPARE REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.compareRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP COMPARE RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP COMPARE RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.compareResult(messageID, message); |
| | | } |
| | | |
| | |
| | | final DN dn = LDAP.readDN(dnString, schema); |
| | | final DeleteRequest message = Requests.newDeleteRequest(dn); |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP DELETE REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP DELETE REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.deleteRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP DELETE RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP DELETE RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.deleteResult(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP EXTENDED REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP EXTENDED REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.extendedRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP EXTENDED RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP EXTENDED RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.extendedResult(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP INTERMEDIATE RESPONSE(messageID={}, response={})", messageID, |
| | | message); |
| | | logger.trace("DECODE LDAP INTERMEDIATE RESPONSE(messageID=%d, response=%s)", messageID, message); |
| | | handler.intermediateResponse(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP MODIFY DN REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP MODIFY DN REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.modifyDNRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE MODIFY DN RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP MODIFY DN RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.modifyDNResult(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP MODIFY REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP MODIFY REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.modifyRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP MODIFY RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP MODIFY RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.modifyResult(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP SEARCH REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP SEARCH REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.searchRequest(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP SEARCH RESULT(messageID={}, result={})", messageID, message); |
| | | logger.trace("DECODE LDAP SEARCH RESULT(messageID=%d, result=%s)", messageID, message); |
| | | handler.searchResult(messageID, message); |
| | | } |
| | | |
| | |
| | | final Entry entry = LDAP.readEntry(reader, LDAP.OP_TYPE_SEARCH_RESULT_ENTRY, options); |
| | | final SearchResultEntry message = Responses.newSearchResultEntry(entry); |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP SEARCH RESULT ENTRY(messageID={}, entry={})", messageID, message); |
| | | logger.trace("DECODE LDAP SEARCH RESULT ENTRY(messageID=%d, entry=%s)", messageID, message); |
| | | handler.searchResultEntry(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readEndSequence(); |
| | | } |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP SEARCH RESULT REFERENCE(messageID={}, result={})", messageID, |
| | | message); |
| | | logger.trace("DECODE LDAP SEARCH RESULT REFERENCE(messageID=%d, reference=%s)", messageID, message); |
| | | handler.searchResultReference(messageID, message); |
| | | } |
| | | |
| | |
| | | reader.readNull(LDAP.OP_TYPE_UNBIND_REQUEST); |
| | | final UnbindRequest message = Requests.newUnbindRequest(); |
| | | readControls(message); |
| | | IO_LOG.trace("DECODE LDAP UNBIND REQUEST(messageID={}, request={})", messageID, message); |
| | | logger.trace("DECODE LDAP UNBIND REQUEST(messageID=%d, request=%s)", messageID, message); |
| | | handler.unbindRequest(messageID, message); |
| | | } |
| | | } |
| | |
| | | |
| | | package org.forgerock.opendj.io; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * Writes LDAP messages to an underlying ASN.1 writer. |
| | | * <p> |
| | |
| | | public final class LDAPWriter<W extends ASN1Writer> { |
| | | // @Checkstyle:ignore AvoidNestedBlocks |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | private final W writer; |
| | | |
| | | LDAPWriter(final W asn1Writer) { |
| | |
| | | */ |
| | | public void writeAbandonRequest(final int messageID, final AbandonRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP ABANDON REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP ABANDON REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeInteger(LDAP.OP_TYPE_ABANDON_REQUEST, request.getRequestID()); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeAddRequest(final int messageID, final AddRequest request) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP ADD REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP ADD REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | LDAP.writeEntry(writer, LDAP.OP_TYPE_ADD_REQUEST, request); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeAddResult(final int messageID, final Result result) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP ADD RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP ADD RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_ADD_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeBindRequest(final int messageID, final int version, |
| | | final GenericBindRequest request) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP BIND REQUEST(messageID={}, auth=0x{}, request={})", messageID, |
| | | byteToHex(request.getAuthenticationType()), request); |
| | | logger.trace("ENCODE LDAP BIND REQUEST(messageID=%d, auth=0x%x, request=%s)", |
| | | messageID, request.getAuthenticationType(), request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_BIND_REQUEST); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeBindResult(final int messageID, final BindResult result) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP BIND RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP BIND RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_BIND_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeCompareRequest(final int messageID, final CompareRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP COMPARE REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP COMPARE REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_COMPARE_REQUEST); |
| | |
| | | */ |
| | | public void writeCompareResult(final int messageID, final CompareResult result) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP COMPARE RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP COMPARE RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_COMPARE_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeDeleteRequest(final int messageID, final DeleteRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP DELETE REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP DELETE REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeOctetString(LDAP.OP_TYPE_DELETE_REQUEST, request.getName().toString()); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeDeleteResult(final int messageID, final Result result) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP DELETE RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP DELETE RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_DELETE_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeExtendedRequest(final int messageID, final ExtendedRequest<?> request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP EXTENDED REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP EXTENDED REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_EXTENDED_REQUEST); |
| | |
| | | */ |
| | | public void writeExtendedResult(final int messageID, final ExtendedResult result) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP EXTENDED RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP EXTENDED RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_EXTENDED_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeIntermediateResponse(final int messageID, final IntermediateResponse response) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP INTERMEDIATE RESPONSE(messageID={}, response={})", messageID, |
| | | response); |
| | | logger.trace("ENCODE LDAP INTERMEDIATE RESPONSE(messageID=%d, response=%s)", messageID, response); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_INTERMEDIATE_RESPONSE); |
| | |
| | | */ |
| | | public void writeModifyDNRequest(final int messageID, final ModifyDNRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP MODIFY DN REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP MODIFY DN REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_MODIFY_DN_REQUEST); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeModifyDNResult(final int messageID, final Result result) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP MODIFY DN RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP MODIFY DN RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_MODIFY_DN_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeModifyRequest(final int messageID, final ModifyRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP MODIFY REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP MODIFY REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_MODIFY_REQUEST); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeModifyResult(final int messageID, final Result result) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP MODIFY RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP MODIFY RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_MODIFY_RESPONSE, result); |
| | |
| | | */ |
| | | public void writeSearchRequest(final int messageID, final SearchRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP SEARCH REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP SEARCH REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_SEARCH_REQUEST); |
| | |
| | | * If an unexpected IO error occurred. |
| | | */ |
| | | public void writeSearchResult(final int messageID, final Result result) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP SEARCH RESULT(messageID={}, result={})", messageID, result); |
| | | logger.trace("ENCODE LDAP SEARCH RESULT(messageID=%d, result=%s)", messageID, result); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writeResultHeader(LDAP.OP_TYPE_SEARCH_RESULT_DONE, result); |
| | |
| | | */ |
| | | public void writeSearchResultEntry(final int messageID, final SearchResultEntry entry) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP SEARCH RESULT ENTRY(messageID={}, entry={})", messageID, entry); |
| | | logger.trace("ENCODE LDAP SEARCH RESULT ENTRY(messageID=%d, entry=%s)", messageID, entry); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | LDAP.writeEntry(writer, LDAP.OP_TYPE_SEARCH_RESULT_ENTRY, entry); |
| | |
| | | */ |
| | | public void writeSearchResultReference(final int messageID, |
| | | final SearchResultReference reference) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP SEARCH RESULT REFERENCE(messageID={}, reference={})", messageID, |
| | | reference); |
| | | logger.trace("ENCODE LDAP SEARCH RESULT REFERENCE(messageID=%d, reference=%s)", messageID, reference); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeStartSequence(LDAP.OP_TYPE_SEARCH_RESULT_REFERENCE); |
| | |
| | | */ |
| | | public void writeUnbindRequest(final int messageID, final UnbindRequest request) |
| | | throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP UNBIND REQUEST(messageID={}, request={})", messageID, request); |
| | | logger.trace("ENCODE LDAP UNBIND REQUEST(messageID=%d, request=%s)", messageID, request); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeNull(LDAP.OP_TYPE_UNBIND_REQUEST); |
| | |
| | | */ |
| | | public void writeUnrecognizedMessage(final int messageID, final byte messageTag, |
| | | final ByteString messageBytes) throws IOException { |
| | | IO_LOG.trace("ENCODE LDAP UNKNOWN MESSAGE(messageID={}, messageTag={}, messageBytes={})", |
| | | messageID, StaticUtils.byteToHex(messageTag), messageBytes); |
| | | logger.trace("ENCODE LDAP UNKNOWN MESSAGE(messageID=%d, messageTag=%x, messageBytes=%s)", |
| | | messageID, messageTag, messageBytes); |
| | | writeMessageHeader(messageID); |
| | | { |
| | | writer.writeOctetString(messageTag, messageBytes); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_BOOLEAN_INVALID_LENGTH; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_INTEGER_INVALID_LENGTH; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_INVALID_NUM_LENGTH_BYTES; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_NULL_INVALID_LENGTH; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_SEQUENCE_READ_NOT_STARTED; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_TRUNCATED_LENGTH_BYTE; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_LDAP_CLIENT_DECODE_MAX_REQUEST_SIZE_EXCEEDED; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.io.ASN1; |
| | | import org.forgerock.opendj.io.ASN1Reader; |
| | | import org.forgerock.opendj.io.AbstractASN1Reader; |
| | |
| | | public SequenceLimiter endSequence() throws IOException { |
| | | parent.checkLimit(remaining()); |
| | | if (remaining() > 0) { |
| | | IO_LOG.debug("Ignoring {} unused trailing bytes in ASN.1 SEQUENCE", remaining()); |
| | | logger.debug(LocalizableMessage.raw( |
| | | "Ignoring %d unused trailing bytes in ASN.1 SEQUENCE", remaining())); |
| | | } |
| | | for (int i = 0; i < remaining(); i++) { |
| | | buffer.get(); |
| | |
| | | public SequenceLimiter startSequence(int readLimit); |
| | | } |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private static final int MAX_STRING_BUFFER_SIZE = 1024; |
| | | private int state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | private byte peekType = 0; |
| | |
| | | readLimiter.checkLimit(peekLength); |
| | | final byte readByte = buffer.get(); |
| | | |
| | | IO_LOG.trace("READ ASN.1 BOOLEAN(type=0x{}, length={}, value={})", byteToHex(peekType), |
| | | peekLength, String.valueOf(readByte != 0x00)); |
| | | logger.trace("READ ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", peekType, peekLength, readByte != 0x00); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return readByte != 0x00; |
| | |
| | | public void readEndSequence() throws IOException { |
| | | readLimiter = readLimiter.endSequence(); |
| | | |
| | | IO_LOG.debug("READ ASN.1 END SEQUENCE"); |
| | | logger.trace("READ ASN.1 END SEQUENCE"); |
| | | |
| | | // Reset the state |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | |
| | | intValue = (intValue << 8) | (readByte & 0xFF); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(peekType), |
| | | peekLength, intValue); |
| | | logger.trace("READ ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", peekType, peekLength, intValue); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return intValue; |
| | |
| | | throw DecodeException.fatalError(message); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 NULL(type=0x{}, length={})", byteToHex(peekType), peekLength); |
| | | logger.trace("READ ASN.1 NULL(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | } |
| | |
| | | final byte[] value = new byte[peekLength]; |
| | | buffer.get(value); |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), |
| | | peekLength); |
| | | logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return ByteString.wrap(value); |
| | |
| | | builder.append(buffer.get()); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(peekType), |
| | | peekLength); |
| | | logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | | return builder; |
| | |
| | | str = new String(readBuffer, 0, peekLength, "UTF-8"); |
| | | } catch (final Exception e) { |
| | | // TODO: I18N |
| | | IO_LOG.warn("Unable to decode ASN.1 OCTETSTRING bytes as UTF-8 string", e); |
| | | logger.warn(LocalizableMessage.raw("Unable to decode ASN.1 OCTETSTRING bytes as UTF-8 string: %s", e)); |
| | | |
| | | str = new String(stringBuffer, 0, peekLength); |
| | | } |
| | | |
| | | IO_LOG.trace("READ ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", byteToHex(peekType), |
| | | peekLength, str); |
| | | logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d, value=%s)", peekType, peekLength, str); |
| | | |
| | | return str; |
| | | } |
| | |
| | | |
| | | readLimiter = readLimiter.startSequence(peekLength); |
| | | |
| | | IO_LOG.trace("READ ASN.1 START SEQUENCE(type=0x{}, length={})", byteToHex(peekType), |
| | | peekLength); |
| | | logger.trace("READ ASN.1 START SEQUENCE(type=0x%x, length=%d)", peekType, peekLength); |
| | | |
| | | // Reset the state |
| | | state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_ASN1_SEQUENCE_WRITE_NOT_STARTED; |
| | | import static com.forgerock.opendj.util.StaticUtils.IO_LOG; |
| | | import static com.forgerock.opendj.util.StaticUtils.byteToHex; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.nio.ByteBuffer; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.io.ASN1; |
| | | import org.forgerock.opendj.io.ASN1Writer; |
| | | import org.forgerock.opendj.io.AbstractASN1Writer; |
| | |
| | | writeLength(parent, buffer.length()); |
| | | parent.writeByteArray(buffer.getBackingArray(), 0, buffer.length()); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 END SEQUENCE(length={})", buffer.length()); |
| | | logger.trace("WRITE ASN.1 END SEQUENCE(length=%d)", buffer.length()); |
| | | |
| | | return parent; |
| | | } |
| | |
| | | public void writeByteArray(byte[] bs, int offset, int length) throws IOException; |
| | | } |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private static final int BUFFER_INIT_SIZE = 1024; |
| | | |
| | | /** |
| | |
| | | writeLength(sequenceBuffer, 1); |
| | | sequenceBuffer.writeByte(booleanValue ? ASN1.BOOLEAN_VALUE_TRUE : ASN1.BOOLEAN_VALUE_FALSE); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 BOOLEAN(type=0x{}, length={}, value={})", |
| | | byteToHex(type), 1, String.valueOf(booleanValue)); |
| | | |
| | | logger.trace("WRITE ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", type, 1, booleanValue); |
| | | return this; |
| | | } |
| | | |
| | |
| | | || ((intValue & 0x0000007F) == intValue)) { |
| | | writeLength(sequenceBuffer, 1); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFFFF8000) == 0xFFFF8000)) |
| | | || ((intValue & 0x00007FFF) == intValue)) { |
| | | writeLength(sequenceBuffer, 2); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, intValue); |
| | | } else if (((intValue < 0) && ((intValue & 0xFF800000) == 0xFF800000)) |
| | | || ((intValue & 0x007FFFFF) == intValue)) { |
| | | writeLength(sequenceBuffer, 3); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, intValue); |
| | | } else { |
| | | writeLength(sequenceBuffer, 4); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 24) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (intValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, intValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, intValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | || ((longValue & 0x000000000000007FL) == longValue)) { |
| | | writeLength(sequenceBuffer, 1); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 1, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFFFF8000L) == 0xFFFFFFFFFFFF8000L)) |
| | | || ((longValue & 0x0000000000007FFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 2); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 2, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFF800000L) == 0xFFFFFFFFFF800000L)) |
| | | || ((longValue & 0x00000000007FFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 3); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 3, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFFFF80000000L) == 0xFFFFFFFF80000000L)) |
| | | || ((longValue & 0x000000007FFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 4); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 4, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFFFF8000000000L) == 0xFFFFFF8000000000L)) |
| | | || ((longValue & 0x0000007FFFFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 5); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 5, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 5, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFFFF800000000000L) == 0xFFFF800000000000L)) |
| | | || ((longValue & 0x00007FFFFFFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 6); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 6, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 6, longValue); |
| | | } else if (((longValue < 0) && ((longValue & 0xFF80000000000000L) == 0xFF80000000000000L)) |
| | | || ((longValue & 0x007FFFFFFFFFFFFFL) == longValue)) { |
| | | writeLength(sequenceBuffer, 7); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 7, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 7, longValue); |
| | | } else { |
| | | writeLength(sequenceBuffer, 8); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 56) & 0xFF)); |
| | |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF)); |
| | | sequenceBuffer.writeByte((byte) (longValue & 0xFF)); |
| | | IO_LOG.trace("WRITE ASN.1 INTEGER(type=0x{}, length={}, value={})", byteToHex(type), 8, longValue); |
| | | logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 8, longValue); |
| | | } |
| | | return this; |
| | | } |
| | |
| | | sequenceBuffer.writeByte(type); |
| | | writeLength(sequenceBuffer, 0); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 NULL(type=0x{}, length={})", byteToHex(type), 0); |
| | | |
| | | logger.trace("WRITE ASN.1 NULL(type=0x%x, length=%d)", type, 0); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(sequenceBuffer, length); |
| | | sequenceBuffer.writeByteArray(value, offset, length); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), length); |
| | | logger.trace("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, length); |
| | | return this; |
| | | } |
| | | |
| | |
| | | sequenceBuffer.writeByte(value.byteAt(i)); |
| | | } |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={})", byteToHex(type), value.length()); |
| | | logger.trace("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d)", type, value.length()); |
| | | return this; |
| | | } |
| | | |
| | |
| | | writeLength(sequenceBuffer, bytes.length); |
| | | sequenceBuffer.writeByteArray(bytes, 0, bytes.length); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 OCTETSTRING(type=0x{}, length={}, value={})", byteToHex(type), |
| | | bytes.length, value); |
| | | logger.trace("WRITE ASN.1 OCTETSTRING(type=0x%x, length=%d, value=%s)", type, bytes.length, value); |
| | | return this; |
| | | } |
| | | |
| | |
| | | // Get a child sequence buffer |
| | | sequenceBuffer = sequenceBuffer.startSequence(type); |
| | | |
| | | IO_LOG.trace("WRITE ASN.1 START SEQUENCE(type=0x{})", byteToHex(type)); |
| | | logger.trace("WRITE ASN.1 START SEQUENCE(type=0x%x)", type); |
| | | return this; |
| | | } |
| | | |
| | |
| | | /** Trace with message only. */ |
| | | private void logTraceMessage(String msg) { |
| | | tracer.trace(msg); |
| | | |
| | | } |
| | | |
| | | /** Trace with message and exception. */ |