From f91a480df0a08c9286dcb508e1adb78602d02114 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 31 Mar 2016 09:08:34 +0000
Subject: [PATCH] Remove dead code InternalLDAP*
---
/dev/null | 598 -----------------------------------------------------------
1 files changed, 0 insertions(+), 598 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPInputStream.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPInputStream.java
deleted file mode 100644
index 071d980..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPInputStream.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
- */
-package org.opends.server.protocols.internal;
-
-
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.concurrent.ArrayBlockingQueue;
-
-import org.forgerock.opendj.io.ASN1;
-import org.forgerock.opendj.io.ASN1Writer;
-import org.opends.server.protocols.ldap.LDAPMessage;
-import org.forgerock.opendj.ldap.ByteSequenceReader;
-import org.forgerock.opendj.ldap.ByteStringBuilder;
-
-
-/**
- * This class provides an implementation of a
- * {@code java.io.InputStream} that can be used to facilitate internal
- * communication with the Directory Server. On the backend, this
- * input stream will be populated by ASN.1 elements encoded from LDAP
- * messages created from internal operation responses.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=true)
-public final class InternalLDAPInputStream
- extends InputStream
-{
- /**
- * The queue of LDAP messages providing the data to be made
- * available to the client.
- */
- private final ArrayBlockingQueue<LDAPMessage> messageQueue;
-
- /** Indicates whether this stream has been closed. */
- private boolean closed;
-
- /** The byte buffer with partial data to be written to the client. */
- private final ByteStringBuilder messageBuffer;
-
- /** The byte buffer reader. */
- private final ByteSequenceReader messageReader;
-
- /** The byte buffer writer. */
- private final ASN1Writer writer;
-
- /** The internal LDAP socket serviced by this input stream. */
- private final InternalLDAPSocket socket;
-
-
-
- /**
- * Creates a new internal LDAP input stream that will service the
- * provided internal LDAP socket.
- *
- * @param socket The internal LDAP socket serviced by this
- * internal LDAP input stream.
- */
- public InternalLDAPInputStream(InternalLDAPSocket socket)
- {
- this.socket = socket;
- this.messageQueue = new ArrayBlockingQueue<>(10);
- this.messageBuffer = new ByteStringBuilder();
- this.messageReader = messageBuffer.asReader();
- this.writer = ASN1.getWriter(messageBuffer);
- this.closed = false;
- }
-
-
-
- /**
- * Adds the provided LDAP message to the set of messages to be
- * returned to the client. Note that this may block if there is
- * already a significant backlog of messages to be returned.
- *
- * @param message The message to add to the set of messages to be
- * returned to the client.
- */
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- void addLDAPMessage(LDAPMessage message)
- {
- // If the stream is closed, then simply drop the message.
- if (closed)
- {
- return;
- }
-
- try
- {
- messageQueue.put(message);
- return;
- }
- catch (Exception e)
- {
- // This shouldn't happen, but if it does then try three more
- // times before giving up and dropping the message.
- for (int i=0; i < 3; i++)
- {
- try
- {
- messageQueue.put(message);
- break;
- } catch (Exception e2) {}
- }
-
- return;
- }
- }
-
-
-
- /**
- * Retrieves the number of bytes that can be read (or skipped over)
- * from this input stream without blocking.
- *
- * @return The number of bytes that can be read (or skipped over)
- * from this input stream without blocking.
- * @throws IOException if an I/O error occurs.
- */
- @Override
- public synchronized int available() throws IOException
- {
- if (messageReader.remaining() < 1)
- {
- LDAPMessage message = messageQueue.poll();
- if (message == null || message instanceof NullLDAPMessage)
- {
- if (message != null)
- {
- messageQueue.clear();
- closed = true;
- }
-
- return 0;
- }
- else
- {
- messageBuffer.clear();
- messageReader.rewind();
- message.write(writer);
- }
- }
-
- return messageReader.remaining();
- }
-
-
-
- /**
- * Closes this input stream. This will add a special marker
- * element to the message queue indicating that the end of the
- * stream has been reached. If the queue is full, then it will be
- * cleared before adding the marker element.
- */
- @Override
- public void close()
- {
- socket.close();
- }
-
-
-
- /**
- * Closes this input stream through an internal mechanism that will
- * not cause an infinite recursion loop by trying to also close the
- * input stream.
- */
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- void closeInternal()
- {
- if (closed)
- {
- return;
- }
-
- closed = true;
- NullLDAPMessage nullMessage = new NullLDAPMessage();
-
- while (! messageQueue.offer(nullMessage))
- {
- messageQueue.clear();
- }
- }
-
-
-
- /**
- * Marks the current position in the input stream. This will not
- * have any effect, as this input stream implementation does not
- * support marking.
- *
- * @param readLimit The maximum limit of bytes that can be read
- * before the mark position becomes invalid.
- */
- @Override
- public void mark(int readLimit)
- {
- // No implementation is required.
- }
-
-
-
- /**
- * Indicates whether this input stream implementation supports the
- * use of the {@code mark} and {@code reset} methods. This
- * implementation does not support that functionality.
- *
- * @return {@code false} because this implementation does not
- * support the use of the {@code mark} and {@code reset}
- * methods.
- */
- @Override
- public boolean markSupported()
- {
- return false;
- }
-
-
-
- /**
- * Reads the next byte of data from the input stream, blocking if
- * necessary until there is data available.
- *
- * @return The next byte of data read from the input stream, or -1
- * if the end of the input stream has been reached.
- *
- * @throws IOException If a problem occurs while trying to read
- * data from the stream.
- */
- @Override
- public synchronized int read()
- throws IOException
- {
- if (messageReader.remaining() < 1)
- {
- LDAPMessage message;
- try
- {
- message = messageQueue.take();
- }
- catch(InterruptedException ie)
- {
- // Probably because a shutdown was started. EOF
- message = new NullLDAPMessage();
- }
-
- if (message == null || message instanceof NullLDAPMessage)
- {
- if (message instanceof NullLDAPMessage)
- {
- messageQueue.clear();
- closed = true;
- return -1;
- }
-
- return 0;
- }
- else
- {
- messageBuffer.clear();
- messageReader.rewind();
- message.write(writer);
- }
- }
-
- return 0xFF & messageReader.readByte();
- }
-
-
-
- /**
- * Reads some number of bytes from the input stream, blocking if
- * necessary until there is data available, and adds them to the
- * provided array starting at position 0.
- *
- * @param b The array to which the data is to be written.
- *
- * @return The number of bytes actually written into the
- * provided array, or -1 if the end of the stream has been
- * reached.
- *
- * @throws IOException If a problem occurs while trying to read
- * data from the stream.
- */
- @Override
- public int read(byte[] b)
- throws IOException
- {
- return read(b, 0, b.length);
- }
-
-
-
- /**
- * Reads some number of bytes from the input stream, blocking if
- * necessary until there is data available, and adds them to the
- * provided array starting at the specified position.
- *
- * @param b The array to which the data is to be written.
- * @param off The offset in the array at which to start writing
- * data.
- * @param len The maximum number of bytes that may be added to the
- * array.
- *
- * @return The number of bytes actually written into the
- * provided array, or -1 if the end of the stream has been
- * reached.
- *
- * @throws IOException If a problem occurs while trying to read
- * data from the stream.
- */
- @Override
- public synchronized int read(byte[] b, int off, int len)
- throws IOException
- {
- if (messageReader.remaining() < 1)
- {
- LDAPMessage message;
- try
- {
- message = messageQueue.take();
- }
- catch(InterruptedException ie)
- {
- // Probably because a shutdown was started. EOF
- message = new NullLDAPMessage();
- }
-
- if (message == null || message instanceof NullLDAPMessage)
- {
- if (message instanceof NullLDAPMessage)
- {
- messageQueue.clear();
- closed = true;
- return -1;
- }
-
- return 0;
- }
- else
- {
- messageBuffer.clear();
- messageReader.rewind();
- message.write(writer);
- }
- }
-
- int actualLen = Math.min(len, messageReader.remaining());
- messageReader.readBytes(b, off, actualLen);
- return actualLen;
- }
-
-
-
- /**
- * Repositions this stream to the position at the time that the
- * {@code mark} method was called on this stream. This will not
- * have any effect, as this input stream implementation does not
- * support marking.
- */
- @Override
- public void reset()
- {
- // No implementation is required.
- }
-
-
-
- /**
- * Skips over and discards up to the specified number of bytes of
- * data from this input stream. This implementation will always
- * skip the requested number of bytes unless the end of the stream
- * is reached.
- *
- * @param n The maximum number of bytes to skip.
- *
- * @return The number of bytes actually skipped.
- *
- * @throws IOException If a problem occurs while trying to read
- * data from the input stream.
- */
- @Override
- public synchronized long skip(long n)
- throws IOException
- {
- byte[] b;
- if (n > 8192)
- {
- b = new byte[8192];
- }
- else
- {
- b = new byte[(int) n];
- }
-
- long totalBytesRead = 0L;
- while (totalBytesRead < n)
- {
- int maxLen = (int) Math.min((n - totalBytesRead), b.length);
-
- int bytesRead = read(b, 0, maxLen);
- if (bytesRead < 0)
- {
- if (totalBytesRead > 0)
- {
- return totalBytesRead;
- }
- else
- {
- return bytesRead;
- }
- }
- else
- {
- totalBytesRead += bytesRead;
- }
- }
-
- return totalBytesRead;
- }
-
-
-
- /**
- * Retrieves a string representation of this internal LDAP socket.
- *
- * @return A string representation of this internal LDAP socket.
- */
- @Override
- public String toString()
- {
- return getClass().getSimpleName();
- }
-}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPOutputStream.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPOutputStream.java
deleted file mode 100644
index 599ecdc..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPOutputStream.java
+++ /dev/null
@@ -1,828 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2009 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.protocols.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.io.ASN1;
-import org.forgerock.opendj.io.ASN1Reader;
-import org.forgerock.opendj.ldap.ByteSequenceReader;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ByteStringBuilder;
-import org.forgerock.opendj.ldap.DN;
-import org.opends.server.core.*;
-import org.opends.server.protocols.ldap.*;
-import org.opends.server.types.*;
-
-import static org.forgerock.opendj.ldap.DecodeException.*;
-import static org.opends.messages.ProtocolMessages.*;
-import static org.opends.server.protocols.internal.InternalClientConnection.*;
-import static org.opends.server.protocols.internal.Requests.*;
-import static org.opends.server.protocols.ldap.LDAPConstants.*;
-import static org.opends.server.util.ServerConstants.*;
-
-/**
- * This class provides an implementation of a
- * {@code java.io.OutputStream} that can be used to facilitate
- * internal communication with the Directory Server. On the backend,
- * data written to this output stream will be first decoded as an
- * ASN.1 element and then as an LDAP message. That LDAP message will
- * be converted to an internal operation which will then be processed
- * and the result returned to the client via the input stream on the
- * other side of the associated internal LDAP socket.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=true)
-public final class InternalLDAPOutputStream
- extends OutputStream
- implements InternalSearchListener
-{
- /** Indicates whether this stream has been closed. */
- private boolean closed;
-
- private final ASN1Reader reader;
-
- /** The internal LDAP socket with which this output stream is associated. */
- private final InternalLDAPSocket socket;
-
- /** The immediate data being written. */
- private ByteSequenceReader byteBuffer;
-
- /**
- * The save buffer used to store any unprocessed data waiting
- * to be read as ASN.1 elements. (Usually due to writing incomplete
- * ASN.1 elements.)
- */
- private final ByteStringBuilder saveBuffer;
-
- private final ByteSequenceReader saveBufferReader;
-
- /**
- * An adaptor class for reading from a save buffer and the bytes
- * being written sequentially using the InputStream interface.
- *
- * Since the bytes being written are only available duing the write
- * call, any unused data will be appended to the save buffer before
- * returning from the write method. This reader will always read the
- * save buffer first before the actual bytes being written to ensure
- * bytes are read in the same order as they are written.
- */
- private class CombinedBufferInputStream extends InputStream
- {
- /** {@inheritDoc} */
- @Override
- public int available()
- {
- // The number of available bytes is the sum of the save buffer
- // and the last read data in the NIO ByteStringBuilder.
- return saveBufferReader.remaining() + byteBuffer.remaining();
- }
-
- /** {@inheritDoc} */
- @Override
- public int read()
- {
- if(saveBufferReader.remaining() > 0)
- {
- // Try saved buffer first
- return 0xFF & saveBufferReader.readByte();
- }
- if(byteBuffer.remaining() > 0)
- {
- // Must still be on the channel buffer
- return 0xFF & byteBuffer.readByte();
- }
-
- return -1;
- }
-
- /** {@inheritDoc} */
- @Override
- public int read(byte[] bytes)
- {
- return read(bytes, 0, bytes.length);
- }
-
- /** {@inheritDoc} */
- @Override
- public int read(byte[] value, int off, int length)
- {
- int bytesCopied=0;
- int len;
- if(saveBufferReader.remaining() > 0)
- {
- // Copy out of the last saved buffer first
- len = Math.min(saveBufferReader.remaining(), length);
- saveBufferReader.readBytes(value, off, len);
- bytesCopied += len;
- }
- if(bytesCopied < length && byteBuffer.remaining() > 0)
- {
- // Copy out of the channel buffer if we haven't got
- // everything we needed.
- len = Math.min(byteBuffer.remaining(), length - bytesCopied);
- byteBuffer.readBytes(value, off + bytesCopied, len);
- bytesCopied += len;
- }
- return bytesCopied;
- }
-
- /** {@inheritDoc} */
- @Override
- public long skip(long length)
- {
- int bytesSkipped=0;
- int len;
- if(saveBufferReader.remaining() > 0)
- {
- // Skip in the last saved buffer first
- len = Math.min(saveBufferReader.remaining(), (int)length);
- saveBufferReader.position(saveBufferReader.position() + len);
- bytesSkipped += len;
- }
- if(bytesSkipped < length && byteBuffer.remaining() > 0)
- {
- //Skip in the channel buffer if we haven't skipped enough.
- len = Math.min(byteBuffer.remaining(),
- (int)length - bytesSkipped);
- byteBuffer.position(byteBuffer.position() + len);
- bytesSkipped += len;
- }
- return bytesSkipped;
- }
- }
-
- /**
- * Creates a new instance of an internal LDAP output stream that is
- * associated with the provided internal LDAP socket.
- *
- * @param socket The internal LDAP socket that will be serviced by
- * this internal LDAP output stream.
- */
- public InternalLDAPOutputStream(InternalLDAPSocket socket)
- {
- this.socket = socket;
- this.closed = false;
- this.saveBuffer = new ByteStringBuilder();
- this.saveBufferReader = saveBuffer.asReader();
-
- CombinedBufferInputStream bufferStream =
- new CombinedBufferInputStream();
- this.reader = ASN1.getReader(bufferStream);
- }
-
-
-
- /**
- * Closes this output stream, its associated socket, and the
- * socket's associated input stream.
- */
- @Override
- public void close()
- {
- socket.close();
- }
-
-
-
- /**
- * Closes this output stream through an internal mechanism that will
- * not cause an infinite recursion loop by trying to also close the
- * output stream.
- */
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- void closeInternal()
- {
- closed = true;
- }
-
-
-
- /**
- * Flushes this output stream and forces any buffered data to be
- * written out. This will have no effect, since this output
- * stream implementation does not use buffering.
- */
- @Override
- public void flush()
- {
- // No implementation is required.
- }
-
-
-
- /**
- * Writes the contents of the provided byte array to this output
- * stream.
- *
- * @param b The byte array to be written.
- *
- * @throws IOException If the output stream is closed, or if there
- * is a problem with the data being written.
- */
- @Override
- public void write(byte[] b)
- throws IOException
- {
- write(b, 0, b.length);
- }
-
-
-
- /**
- * Writes the specified portion of the data in the provided byte
- * array to this output stream. Any data written will be
- * accumulated until a complete ASN.1 element is available, at which
- * point it will be decoded as an LDAP message and converted to an
- * internal operation that will be processed.
- *
- * @param b The byte array containing the data to be read.
- * @param off The position in the array at which to start reading
- * data.
- * @param len The number of bytes to read from the array.
- *
- * @throws IOException If the output stream is closed, or if there
- * is a problem with the data being written.
- */
- @Override
- public synchronized void write(byte[] b, int off, int len)
- throws IOException
- {
- if (closed)
- {
- LocalizableMessage m = ERR_INTERNALOS_CLOSED.get();
- throw new IOException(m.toString());
- }
-
- byteBuffer = ByteString.wrap(b, off, len).asReader();
-
- try
- {
- while(reader.elementAvailable())
- {
- LDAPMessage msg = LDAPReader.readMessage(reader);
- processMessage(msg);
- }
- }
- catch(Exception e)
- {
- throw new IOException(e.getMessage());
- }
-
- // Clear the save buffer if we have read all of it
- if(saveBufferReader.remaining() == 0)
- {
- saveBuffer.clear();
- saveBufferReader.rewind();
- }
-
- // Append any unused data in the channel buffer to the save buffer
- if(byteBuffer.remaining() > 0)
- {
- saveBuffer.appendBytes(byteBuffer, byteBuffer.remaining());
- }
- }
-
-
-
- /**
- * Writes a single byte of data to this output stream. If the byte
- * written completes an ASN.1 element that was in progress, then it
- * will be decoded as an LDAP message and converted to an internal
- * operation that will be processed. Otherwise, the data will be
- * accumulated until a complete element can be formed.
- *
- * @param b The byte to be written.
- *
- * @throws IOException If the output stream is closed, or if there
- * is a problem with the data being written.
- */
- @Override
- public synchronized void write(int b)
- throws IOException
- {
- write(new byte[]{(byte)b}, 0, 1);
- }
-
-
-
- /**
- * Processes the provided ASN.1 element by decoding it as an LDAP
- * message, converting that to an internal operation, and sending
- * the appropriate response message(s) to the client through the
- * corresponding internal LDAP input stream.
- *
- * @param message The LDAP message to process.
- *
- * @throws IOException If a problem occurs while attempting to
- * decode the provided ASN.1 element as an
- * LDAP message.
- */
- private void processMessage(LDAPMessage message)
- throws IOException
- {
- switch (message.getProtocolOpType())
- {
- case OP_TYPE_ABANDON_REQUEST:
- // No action is required.
- return;
-
- case OP_TYPE_ADD_REQUEST:
- processAddOperation(message);
- break;
-
- case OP_TYPE_BIND_REQUEST:
- processBindOperation(message);
- break;
-
- case OP_TYPE_COMPARE_REQUEST:
- processCompareOperation(message);
- break;
-
-
- case OP_TYPE_DELETE_REQUEST:
- processDeleteOperation(message);
- break;
-
-
- case OP_TYPE_EXTENDED_REQUEST:
- processExtendedOperation(message);
- break;
-
-
- case OP_TYPE_MODIFY_REQUEST:
- processModifyOperation(message);
- break;
-
-
- case OP_TYPE_MODIFY_DN_REQUEST:
- processModifyDNOperation(message);
- break;
-
-
- case OP_TYPE_SEARCH_REQUEST:
- processSearchOperation(message);
- break;
-
-
- case OP_TYPE_UNBIND_REQUEST:
- socket.close();
- break;
-
-
- default:
- LocalizableMessage m = ERR_INTERNALOS_INVALID_REQUEST.get(
- message.getProtocolElementName());
- throw new IOException(m.toString());
- }
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as an add
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processAddOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- AddRequestProtocolOp request = message.getAddRequestProtocolOp();
-
- InternalClientConnection conn = socket.getConnection();
- AddOperationBasis op =
- new AddOperationBasis(conn, InternalClientConnection.nextOperationID(),
- messageID, message.getControls(),
- request.getDN(),
- request.getAttributes());
- op.run();
-
- AddResponseProtocolOp addResponse =
- new AddResponseProtocolOp(op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, addResponse, responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as a bind
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processBindOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- BindRequestProtocolOp request =
- message.getBindRequestProtocolOp();
-
- if (request.getAuthenticationType() == AuthenticationType.SASL)
- {
- LocalizableMessage m = ERR_INTERNALOS_SASL_BIND_NOT_SUPPORTED.get();
- BindResponseProtocolOp bindResponse =
- new BindResponseProtocolOp(
- LDAPResultCode.UNWILLING_TO_PERFORM, m);
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, bindResponse));
- return;
- }
-
- InternalClientConnection conn = socket.getConnection();
- BindOperationBasis op =
- new BindOperationBasis(conn, nextOperationID(),
- messageID, message.getControls(),
- String.valueOf(request.getProtocolVersion()),
- request.getDN(), request.getSimplePassword());
- op.run();
-
- BindResponseProtocolOp bindResponse =
- new BindResponseProtocolOp(op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- if (bindResponse.getResultCode() == LDAPResultCode.SUCCESS)
- {
- socket.setConnection(new InternalClientConnection(
- op.getAuthenticationInfo()));
- }
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, bindResponse, responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as a compare
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processCompareOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- CompareRequestProtocolOp request =
- message.getCompareRequestProtocolOp();
-
- InternalClientConnection conn = socket.getConnection();
- CompareOperationBasis op =
- new CompareOperationBasis(conn, nextOperationID(),
- messageID, message.getControls(), request.getDN(),
- request.getAttributeType(),
- request.getAssertionValue());
- op.run();
-
- CompareResponseProtocolOp compareResponse =
- new CompareResponseProtocolOp(
- op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, compareResponse,
- responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as a delete
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processDeleteOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- DeleteRequestProtocolOp request =
- message.getDeleteRequestProtocolOp();
-
- InternalClientConnection conn = socket.getConnection();
- DeleteOperationBasis op =
- new DeleteOperationBasis(conn, nextOperationID(),
- messageID, message.getControls(), request.getDN());
- op.run();
-
- DeleteResponseProtocolOp deleteResponse =
- new DeleteResponseProtocolOp(
- op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, deleteResponse,
- responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as an extended
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processExtendedOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- ExtendedRequestProtocolOp request =
- message.getExtendedRequestProtocolOp();
- if (request.getOID().equals(OID_START_TLS_REQUEST))
- {
- LocalizableMessage m = ERR_INTERNALOS_STARTTLS_NOT_SUPPORTED.get();
- ExtendedResponseProtocolOp extendedResponse =
- new ExtendedResponseProtocolOp(
- LDAPResultCode.UNWILLING_TO_PERFORM, m);
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, extendedResponse));
- return;
- }
-
- InternalClientConnection conn = socket.getConnection();
- ExtendedOperationBasis op =
- new ExtendedOperationBasis(conn, nextOperationID(),
- messageID, message.getControls(), request.getOID(),
- request.getValue());
- op.run();
-
- ExtendedResponseProtocolOp extendedResponse =
- new ExtendedResponseProtocolOp(
- op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs(), op.getResponseOID(),
- op.getResponseValue());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, extendedResponse,
- responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as a modify
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processModifyOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- ModifyRequestProtocolOp request =
- message.getModifyRequestProtocolOp();
-
- InternalClientConnection conn = socket.getConnection();
- ModifyOperationBasis op =
- new ModifyOperationBasis(conn, nextOperationID(),
- messageID, message.getControls(), request.getDN(),
- request.getModifications());
- op.run();
-
- ModifyResponseProtocolOp modifyResponse =
- new ModifyResponseProtocolOp(
- op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, modifyResponse,
- responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as a modify DN
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processModifyDNOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- ModifyDNRequestProtocolOp request =
- message.getModifyDNRequestProtocolOp();
-
- InternalClientConnection conn = socket.getConnection();
- ModifyDNOperationBasis op =
- new ModifyDNOperationBasis(conn, nextOperationID(),
- messageID, message.getControls(), request.getEntryDN(),
- request.getNewRDN(), request.deleteOldRDN(),
- request.getNewSuperior());
- op.run();
-
- ModifyDNResponseProtocolOp modifyDNResponse =
- new ModifyDNResponseProtocolOp(
- op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, modifyDNResponse,
- responseControls));
- }
-
-
-
- /**
- * Processes the content of the provided LDAP message as a search
- * operation and returns the appropriate result to the client.
- *
- * @param message The LDAP message containing the request to
- * process.
- *
- * @throws IOException If a problem occurs while attempting to
- * process the operation.
- */
- private void processSearchOperation(LDAPMessage message)
- throws IOException
- {
- int messageID = message.getMessageID();
- SearchRequestProtocolOp request = message.getSearchRequestProtocolOp();
-
- InternalClientConnection conn = socket.getConnection();
- DN baseDN = null;
- SearchFilter filter;
- try
- {
- baseDN = DN.valueOf(request.getBaseDN().toString());
- filter = request.getFilter().toSearchFilter();
- }
- catch (DirectoryException e)
- {
- final String cause = baseDN == null ? "baseDN" : "filter";
- throw error(LocalizableMessage.raw("Could not decode " + cause), e);
- }
- SearchRequest sr = newSearchRequest(baseDN, request.getScope(), filter)
- .setDereferenceAliasesPolicy(request.getDereferencePolicy())
- .setSizeLimit(request.getSizeLimit())
- .setTimeLimit(request.getTimeLimit())
- .setTypesOnly(request.getTypesOnly())
- .addAttribute(request.getAttributes())
- .addControl(message.getControls());
- InternalSearchOperation op = new InternalSearchOperation(
- conn, nextOperationID(), messageID, sr, this);
- op.run();
-
- SearchResultDoneProtocolOp searchDone =
- new SearchResultDoneProtocolOp(
- op.getResultCode().intValue(),
- op.getErrorMessage().toMessage(),
- op.getMatchedDN(),
- op.getReferralURLs());
- List<Control> responseControls = op.getResponseControls();
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(messageID, searchDone, responseControls));
- }
-
-
-
- /**
- * Performs any processing necessary for the provided search result
- * entry.
- *
- * @param searchOperation The internal search operation being
- * processed.
- * @param searchEntry The matching search result entry to be
- * processed.
- */
- @Override
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- public void handleInternalSearchEntry(
- InternalSearchOperation searchOperation,
- SearchResultEntry searchEntry)
- {
- List<Control> entryControls = searchEntry.getControls();
-
- SearchResultEntryProtocolOp entry =
- new SearchResultEntryProtocolOp(searchEntry);
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(searchOperation.getMessageID(), entry, entryControls));
- }
-
-
-
- /**
- * Performs any processing necessary for the provided search result reference.
- *
- * @param searchOperation The internal search operation being processed.
- * @param searchReference The search result reference to be processed.
- */
- @Override
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- public void handleInternalSearchReference(
- InternalSearchOperation searchOperation,
- SearchResultReference searchReference)
- {
- List<Control> entryControls = searchReference.getControls();
-
- SearchResultReferenceProtocolOp reference =
- new SearchResultReferenceProtocolOp(searchReference);
-
- socket.getInputStream().addLDAPMessage(
- new LDAPMessage(searchOperation.getMessageID(), reference,
- entryControls));
- }
-
-
-
- /**
- * Retrieves a string representation of this internal LDAP socket.
- *
- * @return A string representation of this internal LDAP socket.
- */
- @Override
- public String toString()
- {
- return getClass().getSimpleName();
- }
-}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPSocket.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPSocket.java
deleted file mode 100644
index 5bba69e..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPSocket.java
+++ /dev/null
@@ -1,852 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.protocols.internal;
-
-
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.nio.channels.SocketChannel;
-
-import org.forgerock.opendj.ldap.DN;
-
-
-
-/**
- * This class provides an implementation of a {@code java.net.Socket}
- * object that can be used to facilitate internal communication with
- * the Directory Server through third-party LDAP APIs that provide the
- * ability to use a custom socket factory when creating connections.
- * Whenever data is written over the socket, it is decoded as LDAP
- * communication and converted to an appropriate internal operation,
- * which the server then processes and converts the response back to
- * an LDAP encoding.
- * <BR><BR>
- * Note that this implementation only supports those operations which
- * can be performed in the Directory Server via internal operations.
- * This includes add, compare, delete, modify, modify DN, and search
- * operations, and some types of extended operations. Special support
- * has been added for simple bind operations to function properly, but
- * SASL binds are not supported. Abandon and unbind operations are
- * not supported, nor are the cancel or StartTLS extended operations.
- * Only clear-text LDAP communication may be used.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class InternalLDAPSocket
- extends Socket
-{
- /** Indicates whether this socket is closed. */
- private boolean closed;
-
- /** The value that the client has requested for SO_KEEPALIVE. */
- private boolean keepAlive;
-
- /** The value that the client has requested for OOBINLINE. */
- private boolean oobInline;
-
- /** The value that the client has requested for SO_REUSEADDR. */
- private boolean reuseAddress;
-
- /** The value that the client has requested for TCP_NODELAY. */
- private boolean tcpNoDelay;
-
- /** The value that the client has requested for SO_LINGER. */
- private int lingerDuration;
-
- /** The value that the client has requested for SO_RCVBUF. */
- private int receiveBufferSize;
-
- /** The value that the client has requested for SO_SNDBUF. */
- private int sendBufferSize;
-
- /** The value that the client has requested for SO_TIMEOUT. */
- private int timeout;
-
- /** The value that the client has requested for the traffic class. */
- private int trafficClass;
-
- /**
- * The internal client connection used to perform the internal
- * operations. It will be null until it is first used.
- */
- private InternalClientConnection conn;
-
- /** The input stream associated with this internal LDAP socket. */
- private InternalLDAPInputStream inputStream;
-
- /** The output stream associated with this internal LDAP socket. */
- private InternalLDAPOutputStream outputStream;
-
-
-
- /**
- * Creates a new internal LDAP socket.
- */
- public InternalLDAPSocket()
- {
- closed = false;
- keepAlive = true;
- oobInline = true;
- reuseAddress = true;
- tcpNoDelay = true;
- lingerDuration = 0;
- receiveBufferSize = 1024;
- sendBufferSize = 1024;
- timeout = 0;
- trafficClass = 0;
- conn = null;
- inputStream = new InternalLDAPInputStream(this);
- outputStream = new InternalLDAPOutputStream(this);
- }
-
-
-
- /**
- * Retrieves the internal client connection used to back this
- * internal LDAP socket.
- *
- * @return The internal client connection used to back this
- * internal LDAP socket.
- *
- * @throws IOException If there is a problem obtaining the
- * connection.
- */
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- synchronized InternalClientConnection getConnection()
- throws IOException
- {
- if (conn == null)
- {
- try
- {
- conn = new InternalClientConnection(DN.rootDN());
- }
- catch (Exception e)
- {
- // This should never happen.
- throw new IOException(e.getMessage());
- }
- }
-
- return conn;
- }
-
-
-
- /**
- * Sets the internal client connection used to back this internal
- * LDAP socket.
- *
- * @param conn The internal client connection used to back this
- * internal LDAP socket.
- */
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- synchronized void setConnection(InternalClientConnection conn)
- {
- this.conn = conn;
- }
-
-
-
- /**
- * Binds the socket to a local address. This does nothing, since
- * there is no actual network communication performed by this
- * socket implementation.
- *
- * @param bindpoint The socket address to which to bind.
- */
- @Override
- public void bind(SocketAddress bindpoint)
- {
- // No implementation is required.
- }
-
-
-
- /**
- * Closes this socket. This will make it unavailable for use.
- */
- @Override
- public synchronized void close()
- {
- try
- {
- inputStream.closeInternal();
- } catch (Exception e) {}
-
- try
- {
- outputStream.closeInternal();
- } catch (Exception e) {}
-
- closed = true;
- inputStream = null;
- outputStream = null;
- }
-
-
-
- /**
- * Connects this socket to the specified remote endpoint. This will
- * make the connection available again if it has been previously
- * closed. The provided address is irrelevant, as it will always be
- * an internal connection.
- *
- * @param endpoint The address of the remote endpoint.
- */
- @Override
- public synchronized void connect(SocketAddress endpoint)
- {
- closed = false;
- inputStream = new InternalLDAPInputStream(this);
- outputStream = new InternalLDAPOutputStream(this);
- }
-
-
-
- /**
- * Connects this socket to the specified remote endpoint. This does
- * nothing, since there is no actual network communication performed
- * by this socket implementation.
- *
- * @param endpoint The address of the remote endpoint.
- * @param timeout The maximum length of time in milliseconds to
- * wait for the connection to be established.
- */
- @Override
- public void connect(SocketAddress endpoint, int timeout)
- {
- closed = false;
- inputStream = new InternalLDAPInputStream(this);
- outputStream = new InternalLDAPOutputStream(this);
- }
-
-
-
- /**
- * Retrieves the socket channel associated with this socket. This
- * method always returns {@code null} since this implementation does
- * not support use with NIO channels.
- *
- * @return {@code null} because this implementation does not
- * support use with NIO channels.
- */
- @Override
- public SocketChannel getChannel()
- {
- // This implementation does not support use with NIO channels.
- return null;
- }
-
-
-
- /**
- * Retrieves the address to which this socket is connected. The
- * address returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The address to which this socket is connected.
- */
- @Override
- public InetAddress getInetAddress()
- {
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (Exception e)
- {
- // This should not happen.
- return null;
- }
- }
-
-
-
- /**
- * Retrieves the input stream for this socket.
- *
- * @return The input stream for this socket.
- */
- @Override
- public InternalLDAPInputStream getInputStream()
- {
- return inputStream;
- }
-
-
-
- /**
- * Indicates whether SO_KEEPALIVE is enabled. This implementation
- * will return {@code true} by default, but if its value is changed
- * using {@code setKeepalive} then that value will be returned.
- * This setting has no effect in this socket implementation.
- *
- * @return {@code true} if SO_KEEPALIVE is enabled, or
- * {@code false} if not.
- */
- @Override
- public boolean getKeepAlive()
- {
- return keepAlive;
- }
-
-
-
- /**
- * Retrieves the local address to which this socket is bound. The
- * address returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The local address to which this socket is bound.
- */
- @Override
- public InetAddress getLocalAddress()
- {
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (Exception e)
- {
- // This should not happen.
- return null;
- }
- }
-
-
-
- /**
- * Retrieves the local port to which this socket is bound. The
- * value returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The local port to which this socket is bound.
- */
- @Override
- public int getLocalPort()
- {
- return 389;
- }
-
-
-
- /**
- * Retrieves the local socket address to which this socket is bound.
- * The value returned is meaningless, since there is no actual
- * network communication performed by this socket implementation.
- *
- * @return The local socket address to which this socket is bound.
- */
- @Override
- public SocketAddress getLocalSocketAddress()
- {
- try
- {
- return new InetSocketAddress(getLocalAddress(), getLocalPort());
- }
- catch (Exception e)
- {
- // This should not happen.
- return null;
- }
- }
-
-
-
- /**
- * Indicates whether OOBINLINE is enabled. This implementation will
- * return {@code true} by default, but if its value is changed
- * using {@code setOOBInline} then that value will be returned.
- * This setting has no effect in this socket implementation.
- *
- * @return {@code true} if OOBINLINE is enabled, or {@code false}
- * if it is not.
- */
- @Override
- public boolean getOOBInline()
- {
- return oobInline;
- }
-
-
-
- /**
- * Retrieves the output stream for this socket.
- *
- * @return The output stream for this socket.
- */
- @Override
- public InternalLDAPOutputStream getOutputStream()
- {
- return outputStream;
- }
-
-
-
- /**
- * Retrieves the remote port to which this socket is connected. The
- * value returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The remote port to which this socket is connected.
- */
- @Override
- public int getPort()
- {
- return 389;
- }
-
-
-
- /**
- * Retrieves the value of the SO_RCVBUF option for this socket. The
- * value returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The value of the SO_RCVBUF option for this socket.
- */
- @Override
- public int getReceiveBufferSize()
- {
- return receiveBufferSize;
- }
-
-
-
- /**
- * Retrieves the remote socket address to which this socket is
- * connected. The value returned is meaningless, since there is no
- * actual network communication performed by this socket
- * implementation.
- *
- * @return The remote socket address to which this socket is
- * connected.
- */
- @Override
- public SocketAddress getRemoteSocketAddress()
- {
- try
- {
- return new InetSocketAddress(getInetAddress(), getPort());
- }
- catch (Exception e)
- {
- // This should not happen.
- return null;
- }
- }
-
-
-
- /**
- * Indicates whether SO_REUSEADDR is enabled. This implementation
- * will return {@code true} by default, but if its value is changed
- * using {@code setReuseAddress} then that value will be returned.
- * This setting has no effect in this socket implementation.
- *
- * @return {@code true} if SO_REUSEADDR is enabled, or
- * {@code false} if it is not.
- */
- @Override
- public boolean getReuseAddress()
- {
- return reuseAddress;
- }
-
-
-
- /**
- * Retrieves the value of the SO_SNDBUF option for this socket. The
- * value returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The value of the SO_SNDBUF option for this socket.
- */
- @Override
- public int getSendBufferSize()
- {
- return sendBufferSize;
- }
-
-
-
- /**
- * Retrieves the value of the SO_LINGER option for this socket. The
- * value returned is meaningless, since there is no actual network
- * communication performed by this socket implementation.
- *
- * @return The value of the SO_LINGER option for this socket.
- */
- @Override
- public int getSoLinger()
- {
- return lingerDuration;
- }
-
-
-
- /**
- * Retrieves the value of the SO_TIMEOUT option for this socket.
- * The value returned is meaningless, since there is no actual
- * network communication performed by this socket implementation.
- *
- * @return The value of the SO_TIMEOUT option for this socket.
- */
- @Override
- public int getSoTimeout()
- {
- return timeout;
- }
-
-
-
- /**
- * Indicates whether TCP_NODELAY is enabled. This implementation
- * will return {@code true} by default, but if its value is changed
- * using {@code setTcpNoDelay} then that value will be returned.
- * This setting has no effect in this socket implementation.
- *
- * @return {@code true} if TCP_NODELAY is enabled, or {@code false}
- * if it is not.
- */
- @Override
- public boolean getTcpNoDelay()
- {
- return tcpNoDelay;
- }
-
-
-
- /**
- * Retrieves the traffic class for this socket. The value returned
- * will be meaningless, since there is no actual network
- * communication performed by this socket.
- *
- * @return The traffic class for this socket.
- */
- @Override
- public int getTrafficClass()
- {
- return trafficClass;
- }
-
-
-
- /**
- * Indicates whether this socket is bound to a local address. This
- * method will always return {@code true} to indicate that it is
- * bound.
- *
- * @return {@code true} to indicate that the socket is bound to a
- * local address.
- */
- @Override
- public boolean isBound()
- {
- return true;
- }
-
-
-
- /**
- * Indicates whether this socket is closed. This method will always
- * return {@code false} to indicate that it is not closed.
- *
- * @return {@code false} to indicate that the socket is not closed.
- */
- @Override
- public boolean isClosed()
- {
- return closed;
- }
-
-
-
- /**
- * Indicates whether this socket is connected to both local and
- * remote endpoints. This method will always return {@code true} to
- * indicate that it is connected.
- *
- * @return {@code true} to indicate that the socket is connected.
- */
- @Override
- public boolean isConnected()
- {
- return !closed;
- }
-
-
-
- /**
- * Indicates whether the input side of this socket has been closed.
- * This method will always return {@code false} to indicate that it
- * is not closed.
- *
- * @return {@code false} to indicate that the input side of this
- * socket is not closed.
- */
- @Override
- public boolean isInputShutdown()
- {
- return closed;
- }
-
-
-
- /**
- * Indicates whether the output side of this socket has been closed.
- * This method will always return {@code false} to indicate that it
- * is not closed.
- *
- * @return {@code false} to indicate that the output side of this
- * socket is not closed.
- */
- @Override
- public boolean isOutputShutdown()
- {
- return closed;
- }
-
-
-
- /**
- * Sends a single byte of urgent data over this socket.
- *
- * @param data The data to be sent.
- *
- * @throws IOException If a problem occurs while trying to write
- * the provided data over this socket.
- */
- @Override
- public void sendUrgentData(int data)
- throws IOException
- {
- getOutputStream().write(data);
- }
-
-
-
- /**
- * Sets the value of SO_KEEPALIVE for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param on The value to use for the SO_KEEPALIVE option.
- */
- @Override
- public void setKeepAlive(boolean on)
- {
- keepAlive = on;
- }
-
-
-
- /**
- * Sets the value of OOBINLINE for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param on The value to use for the OOBINLINE option.
- */
- @Override
- public void setOOBInline(boolean on)
- {
- oobInline = on;
- }
-
-
-
- /**
- * Sets the provided performance preferences for this socket. This
- * will not affect anything, since there is no actual network
- * communication performed by this socket.
- *
- * @param connectionTime An {@code int} expressing the relative
- * importance of a short connection time.
- * @param latency An {@code int} expressing the relative
- * importance of low latency.
- * @param bandwidth An {@code int} expressing the relative
- * importance of high bandwidth.
- */
- @Override
- public void setPerformancePreferences(int connectionTime,
- int latency, int bandwidth)
- {
- // No implementation is required.
- }
-
-
-
- /**
- * Sets the value of SO_RCVBUF for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param size The value to use for the SO_RCVBUF option.
- */
- @Override
- public void setReceiveBufferSize(int size)
- {
- receiveBufferSize = size;
- }
-
-
-
- /**
- * Sets the value of SO_REUSEADDR for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param on The value to use for the SO_REUSEADDR option.
- */
- @Override
- public void setReuseAddress(boolean on)
- {
- reuseAddress = on;
- }
-
-
-
- /**
- * Sets the value of SO_SNDBUF for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param size The value to use for the SO_SNDBUF option.
- */
- @Override
- public void setSendBufferSize(int size)
- {
- sendBufferSize = size;
- }
-
-
-
- /**
- * Sets the value of SO_LINGER for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param on Indicates whether to enable the linger option.
- * @param linger The length of time in milliseconds to allow the
- * connection to linger.
- */
- @Override
- public void setSoLinger(boolean on, int linger)
- {
- lingerDuration = linger;
- }
-
-
-
- /**
- * Sets the value of SO_TIMEOUT for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param timeout The value to use for the SO_TIMEOUT option.
- */
- @Override
- public void setSoTimeout(int timeout)
- {
- this.timeout = timeout;
- }
-
-
-
- /**
- * Sets the value of TCP_NODELAY for this socket. This will not
- * affect anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param on The value to use for the TCP_NODELAY option.
- */
- @Override
- public void setTcpNoDelay(boolean on)
- {
- tcpNoDelay = on;
- }
-
-
-
- /**
- * Sets the traffic class for this socket. This will not affect
- * anything, since there is no actual network communication
- * performed by this socket.
- *
- * @param tc The value to use for the traffic class.
- */
- @Override
- public void setTrafficClass(int tc)
- {
- trafficClass = tc;
- }
-
-
-
- /**
- * Shuts down the input side of this socket. This will have the
- * effect of closing the entire socket.
- */
- @Override
- public void shutdownInput()
- {
- close();
- }
-
-
-
- /**
- * Shuts down the output side of this socket. This will have the
- * effect of closing the entire socket.
- */
- @Override
- public void shutdownOutput()
- {
- close();
- }
-
-
-
- /**
- * Retrieves a string representation of this internal LDAP socket.
- *
- * @return A string representation of this internal LDAP socket.
- */
- @Override
- public String toString()
- {
- return "InternalLDAPSocket";
- }
-}
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPSocketFactory.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPSocketFactory.java
deleted file mode 100644
index dfc1088..0000000
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalLDAPSocketFactory.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2015 ForgeRock AS.
- */
-package org.opends.server.protocols.internal;
-
-
-
-import java.net.InetAddress;
-import java.net.Socket;
-import javax.net.SocketFactory;
-
-
-
-/**
- * This class provides an implementation of a
- * {@code javax.net.SocketFactory} object that can be used to create
- * internal LDAP sockets. This socket factory can be used with some
- * common LDAP SDKs (e.g., JNDI) in order to allow that SDK to be used
- * to perform internal operations within OpenDS with minimal changes
- * needed from what is required to perform external LDAP
- * communication.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
- mayInstantiate=true,
- mayExtend=false,
- mayInvoke=true)
-public final class InternalLDAPSocketFactory
- extends SocketFactory
-{
- /**
- * Creates a new instance of this internal LDAP socket factory.
- */
- public InternalLDAPSocketFactory()
- {
- // No implementation is required.
- }
-
-
-
- /**
- * Retrieves the default socket factory that should be used. Note
- * that this method must be present for the implementation to work
- * properly. Even though the superclass declares the same static
- * method and static methods are not generally overridden, that is
- * not the case here because the method is invoked through
- * reflection, and the superclass returns a bogus socket factory.
- *
- * @return The default socket factory that should be used.
- */
- public static SocketFactory getDefault()
- {
- return new InternalLDAPSocketFactory();
- }
-
-
-
- /**
- * Creates a new internal LDAP socket. The provided arguments will
- * be ignored, as they are not needed by this implementation.
- *
- * @param host The remote address to which the socket should be
- * connected.
- * @param port The remote port to which the socket should be
- * connected.
- *
- * @return The created internal LDAP socket.
- */
- @Override
- public Socket createSocket(InetAddress host, int port)
- {
- return new InternalLDAPSocket();
- }
-
-
-
- /**
- * Creates a new internal LDAP socket. The provided arguments will
- * be ignored, as they are not needed by this implementation.
- *
- * @param host The remote address to which the socket should be
- * connected.
- * @param port The remote port to which the socket should be
- * connected.
- *
- * @return The created internal LDAP socket.
- */
- @Override
- public Socket createSocket(String host, int port)
- {
- return new InternalLDAPSocket();
- }
-
-
-
- /**
- * Creates a new internal LDAP socket. The provided arguments will
- * be ignored, as they are not needed by this implementation.
- *
- * @param host The remote address to which the socket should
- * be connected.
- * @param port The remote port to which the socket should be
- * connected.
- * @param clientHost The local address to which the socket should
- * be bound.
- * @param clientPort The local port to which the socket should be
- * bound.
- *
- * @return The created internal LDAP socket.
- */
- @Override
- public Socket createSocket(InetAddress host, int port,
- InetAddress clientHost, int clientPort)
- {
- return new InternalLDAPSocket();
- }
-
-
-
- /**
- * Creates a new internal LDAP socket. The provided arguments will
- * be ignored, as they are not needed by this implementation.
- *
- * @param host The remote address to which the socket should
- * be connected.
- * @param port The remote port to which the socket should be
- * connected.
- * @param clientHost The local address to which the socket should
- * be bound.
- * @param clientPort The local port to which the socket should be
- * bound.
- *
- * @return The created internal LDAP socket.
- */
- @Override
- public Socket createSocket(String host, int port,
- InetAddress clientHost, int clientPort)
- {
- return new InternalLDAPSocket();
- }
-
-
-
- /**
- * Retrieves a string representation of this internal LDAP socket
- * factory.
- *
- * @return A string representation of this internal LDAP socket
- * factory.
- */
- @Override
- public String toString()
- {
- return "InternalLDAPSocketFactory";
- }
-}
-
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalLDAPSocketTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalLDAPSocketTestCase.java
deleted file mode 100644
index 4c4544e..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalLDAPSocketTestCase.java
+++ /dev/null
@@ -1,598 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.protocols.internal;
-
-import java.util.Hashtable;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import javax.naming.directory.ModificationItem;
-import javax.naming.directory.SearchControls;
-
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
-import org.forgerock.opendj.ldap.SearchScope;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.ldap.AddRequestProtocolOp;
-import org.opends.server.protocols.ldap.BindRequestProtocolOp;
-import org.opends.server.protocols.ldap.CompareRequestProtocolOp;
-import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
-import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
-import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
-import org.opends.server.protocols.ldap.LDAPFilter;
-import org.opends.server.protocols.ldap.LDAPMessage;
-import org.opends.server.protocols.ldap.LDAPResultCode;
-import org.opends.server.protocols.ldap.ModifyDNRequestProtocolOp;
-import org.opends.server.protocols.ldap.ModifyRequestProtocolOp;
-import org.opends.server.protocols.ldap.SearchRequestProtocolOp;
-import org.opends.server.tools.LDAPReader;
-import org.opends.server.tools.LDAPWriter;
-import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.RawAttribute;
-import org.opends.server.types.RawModification;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import static org.forgerock.opendj.ldap.ModificationType.*;
-import static org.opends.server.util.CollectionUtils.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.testng.Assert.*;
-
-/** This class provides a number of tests to cover the internal LDAP socket implementation. */
-public class InternalLDAPSocketTestCase extends InternalTestCase
-{
- /**
- * Ensures that the Directory Server is running.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @BeforeClass
- public void startServer() throws Exception
- {
- TestCaseUtils.startServer();
- }
-
-
-
- /**
- * Tests the ability to perform an add operation over the internal LDAP
- * socket.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testAddOperation() throws Exception
- {
- TestCaseUtils.initializeTestBackend(false);
- assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- writer.writeMessage(bindRequestMessage());
-
- LDAPMessage message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- List<RawAttribute> attrList = newArrayList(
- RawAttribute.create("objectClass", "organization"),
- RawAttribute.create("o", "test"));
-
- AddRequestProtocolOp addRequest = new AddRequestProtocolOp(ByteString.valueOfUtf8("o=test"), attrList);
- writer.writeMessage(new LDAPMessage(2, addRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getAddResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
- }
- }
-
-
-
- /**
- * Tests the ability to perform an add operation over the internal LDAP
- * socket via JNDI.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testAddOperationThroughJNDI() throws Exception
- {
- TestCaseUtils.initializeTestBackend(false);
- assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
-
- Hashtable<String,String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put("java.naming.ldap.factory.socket",
- InternalLDAPSocketFactory.class.getName());
- env.put(Context.PROVIDER_URL, "ldap://doesntmatter:389/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
- env.put(Context.SECURITY_CREDENTIALS, "password");
- env.put("com.sun.jndi.ldap.connect.pool.debug", "fine");
-
- DirContext context = new InitialDirContext(env);
-
- Attributes attributes = new BasicAttributes(true);
-
- Attribute objectClass = new BasicAttribute("objectClass");
- objectClass.add("top");
- objectClass.add("organization");
- attributes.put(objectClass);
-
- Attribute o = new BasicAttribute("o");
- o.add("test");
- attributes.put(o);
-
- context.createSubcontext("o=test", attributes);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- context.close();
- }
-
-
-
- /**
- * Tests the ability to perform a compare operation over the internal LDAP
- * socket.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testCompareOperation() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- writer.writeMessage(bindRequestMessage());
-
- LDAPMessage message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- CompareRequestProtocolOp compareRequest =
- new CompareRequestProtocolOp(ByteString.valueOfUtf8("o=test"), "o", ByteString.valueOfUtf8("test"));
- writer.writeMessage(new LDAPMessage(2, compareRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getCompareResponseProtocolOp().getResultCode(), LDAPResultCode.COMPARE_TRUE);
- }
- }
-
-
-
- /**
- * Tests the ability to perform a compare operation over the internal LDAP
- * socket via JNDI.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testCompareOperationThroughJNDI() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
-
- Hashtable<String,String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put("java.naming.ldap.factory.socket",
- InternalLDAPSocketFactory.class.getName());
- env.put(Context.PROVIDER_URL, "ldap://doesntmatter:389/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
- env.put(Context.SECURITY_CREDENTIALS, "password");
-
- DirContext context = new InitialDirContext(env);
-
- SearchControls poorlyNamedSearchControls = new SearchControls();
- poorlyNamedSearchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
- poorlyNamedSearchControls.setReturningAttributes(new String[0]);
-
- NamingEnumeration results = context.search("o=test", "(o=test)",
- poorlyNamedSearchControls);
- assertTrue(results.hasMoreElements());
- assertNotNull(results.nextElement());
- assertFalse(results.hasMoreElements());
-
- context.close();
- }
-
-
-
- /**
- * Tests the ability to perform a delete operation over the internal LDAP
- * socket.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testDeleteOperation() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- writer.writeMessage(bindRequestMessage());
-
- LDAPMessage message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- DeleteRequestProtocolOp deleteRequest = new DeleteRequestProtocolOp(ByteString.valueOfUtf8("o=test"));
- writer.writeMessage(new LDAPMessage(2, deleteRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getDeleteResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS);
- assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test")));
- }
- }
-
-
-
- /**
- * Tests the ability to perform a delete operation over the internal LDAP
- * socket via JNDI.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testDeleteOperationThroughJNDI() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
-
- Hashtable<String,String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put("java.naming.ldap.factory.socket",
- InternalLDAPSocketFactory.class.getName());
- env.put(Context.PROVIDER_URL, "ldap://doesntmatter:389/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
- env.put(Context.SECURITY_CREDENTIALS, "password");
-
- DirContext context = new InitialDirContext(env);
-
- context.destroySubcontext("o=test");
- assertFalse(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- context.close();
- }
-
-
-
- /**
- * Tests the ability to perform an extended operation over the internal LDAP
- * socket using the "Who Am I?" request.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testExtendedOperation() throws Exception
- {
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- writer.writeMessage(bindRequestMessage());
-
- LDAPMessage message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- ExtendedRequestProtocolOp extendedRequest = new ExtendedRequestProtocolOp(OID_WHO_AM_I_REQUEST);
- writer.writeMessage(new LDAPMessage(2, extendedRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
-
- ExtendedResponseProtocolOp extendedResponse = message.getExtendedResponseProtocolOp();
- assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS);
- assertTrue(extendedResponse.getValue().toString().equalsIgnoreCase(
- "dn:cn=Directory Manager,cn=Root DNs,cn=config"));
- }
- }
-
-
-
- /**
- * Tests the ability to perform a modify operation over the internal LDAP
- * socket.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testModifyOperation() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- writer.writeMessage(bindRequestMessage());
-
- LDAPMessage message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- List<RawModification> mods = newArrayList(
- RawModification.create(REPLACE, "description", "foo"));
-
- ModifyRequestProtocolOp modifyRequest = new ModifyRequestProtocolOp(ByteString.valueOfUtf8("o=test"), mods);
- writer.writeMessage(new LDAPMessage(2, modifyRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getModifyResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS);
- }
- }
-
-
-
- /**
- * @return
- */
- private LDAPMessage bindRequestMessage()
- {
- BindRequestProtocolOp bindRequest = bindRequest();
- LDAPMessage message = new LDAPMessage(1, bindRequest);
- return message;
- }
-
-
-
- /**
- * Tests the ability to perform a modify operation over the internal LDAP
- * socket via JNDI.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testModifyOperationThroughJNDI() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
-
- Hashtable<String, String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put("java.naming.ldap.factory.socket",
- InternalLDAPSocketFactory.class.getName());
- env.put(Context.PROVIDER_URL, "ldap://doesntmatter:389/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
- env.put(Context.SECURITY_CREDENTIALS, "password");
-
- DirContext context = new InitialDirContext(env);
-
- ModificationItem[] mods =
- {
- new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description", "foo"))
- };
-
- context.modifyAttributes("o=test", mods);
- context.close();
- }
-
-
-
- /**
- * Tests the ability to perform a modify DN operation over the internal LDAP
- * socket.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testModifyDNOperation() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- TestCaseUtils.addEntry(
- "dn: ou=People,o=test",
- "objectClass: top",
- "objectClass: organizationalUnit",
- "ou: People");
-
- assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test")));
- assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test")));
-
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- LDAPMessage message = bindRequestMessage();
- writer.writeMessage(message);
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- ModifyDNRequestProtocolOp modifyDNRequest =
- new ModifyDNRequestProtocolOp(ByteString.valueOfUtf8("ou=People,o=test"), ByteString.valueOfUtf8("ou=Users"),
- true);
- writer.writeMessage(new LDAPMessage(2, modifyDNRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getModifyDNResponseProtocolOp().getResultCode(), LDAPResultCode.SUCCESS);
-
- assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test")));
- assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test")));
- }
- }
-
-
-
- /**
- * @return
- */
- private BindRequestProtocolOp bindRequest()
- {
- BindRequestProtocolOp bindRequest =
- new BindRequestProtocolOp(ByteString.valueOfUtf8("cn=Directory Manager"), 3, ByteString
- .valueOfUtf8("password"));
- return bindRequest;
- }
-
-
-
- /**
- * Tests the ability to perform a modify DN operation over the internal LDAP
- * socket via JNDI.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testModifyDNOperationThroughJNDI() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- TestCaseUtils.addEntry(
- "dn: ou=People,o=test",
- "objectClass: top",
- "objectClass: organizationalUnit",
- "ou: People");
-
- assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test")));
- assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test")));
-
-
- Hashtable<String,String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put("java.naming.ldap.factory.socket",
- InternalLDAPSocketFactory.class.getName());
- env.put(Context.PROVIDER_URL, "ldap://doesntmatter:389/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
- env.put(Context.SECURITY_CREDENTIALS, "password");
-
- DirContext context = new InitialDirContext(env);
-
- context.rename("ou=People,o=test", "ou=Users,o=test");
-
- assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=People,o=test")));
- assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=Users,o=test")));
-
- context.close();
- }
-
-
-
- /**
- * Tests the ability to perform a search operation over the internal LDAP
- * socket.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testSearchOperation() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
- try (InternalLDAPSocket socket = new InternalLDAPSocket();
- LDAPReader reader = new LDAPReader(socket);
- LDAPWriter writer = new LDAPWriter(socket))
- {
- writer.writeMessage(bindRequestMessage());
-
- LDAPMessage message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getBindResponseProtocolOp().getResultCode(), 0);
-
- SearchRequestProtocolOp searchRequest =
- new SearchRequestProtocolOp(ByteString.valueOfUtf8("o=test"), SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false, LDAPFilter.objectClassPresent(), new LinkedHashSet<String>());
- writer.writeMessage(new LDAPMessage(2, searchRequest));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getSearchResultEntryProtocolOp().getDN(), DN.valueOf("o=test"));
-
- message = reader.readMessage();
- assertNotNull(message);
- assertEquals(message.getSearchResultDoneProtocolOp().getResultCode(), LDAPResultCode.SUCCESS);
- }
- }
-
-
-
- /**
- * Tests the ability to perform a searcj operation over the internal LDAP
- * socket via JNDI.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test
- public void testSearchOperationThroughJNDI() throws Exception
- {
- TestCaseUtils.initializeTestBackend(true);
- assertTrue(DirectoryServer.entryExists(DN.valueOf("o=test")));
-
-
- Hashtable<String,String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY,
- "com.sun.jndi.ldap.LdapCtxFactory");
- env.put("java.naming.ldap.factory.socket",
- InternalLDAPSocketFactory.class.getName());
- env.put(Context.PROVIDER_URL, "ldap://doesntmatter:389/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
- env.put(Context.SECURITY_CREDENTIALS, "password");
-
- DirContext context = new InitialDirContext(env);
-
- SearchControls poorlyNamedSearchControls = new SearchControls();
- poorlyNamedSearchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
-
- NamingEnumeration results = context.search("o=test", "(objectClass=*)",
- poorlyNamedSearchControls);
- assertTrue(results.hasMoreElements());
- assertNotNull(results.nextElement());
- assertFalse(results.hasMoreElements());
-
- context.close();
- }
-}
--
Gitblit v1.10.0