org.opends.server.extensions
Class NullConnectionSecurityProvider

java.lang.Object
  extended by org.opends.server.api.ConnectionSecurityProvider
      extended by org.opends.server.extensions.NullConnectionSecurityProvider
Direct Known Subclasses:
InternalConnectionSecurityProvider

public class NullConnectionSecurityProvider
extends ConnectionSecurityProvider

This class provides an implementation of a connection security provider that does not actually provide any security for the communication process. Any data read or written will be assumed to be clear text.


Constructor Summary
  NullConnectionSecurityProvider()
          Creates a new instance of this connection security provider.
protected NullConnectionSecurityProvider(ClientConnection clientConnection, java.nio.channels.SocketChannel socketChannel)
          Creates a new instance of this connection security provider that will be associated with the provided client connection.
 
Method Summary
 void disconnect(boolean connectionValid)
          Indicates that the associated client connection is being closed and that this security provider should perform any necessary processing to deal with that.
 void finalizeConnectionSecurityProvider()
          Performs any finalization that may be necessary for this connection security provider.
 int getClearBufferSize()
          Retrieves the size in bytes that the client should use for the byte buffer meant to hold clear-text data read from or to be written to the client.
 int getEncodedBufferSize()
          Retrieves the size in bytes that the client should use for the byte buffer meant to hold encoded data read from or to be written to the client.
 java.lang.String getSecurityMechanismName()
          Retrieves the name used to identify this security mechanism.
 void initializeConnectionSecurityProvider(ConfigEntry configEntry)
          Initializes this connection security provider using the information in the provided configuration entry.
 boolean isSecure()
          Indicates whether client connections using this connection security provider should be considered secure.
 ConnectionSecurityProvider newInstance(ClientConnection clientConnection, java.nio.channels.SocketChannel socketChannel)
          Creates a new instance of this connection security provider that will be used to encode and decode all communication on the provided client connection.
 boolean readData()
          Reads data from a client connection, performing any necessary negotiation in the process.
 boolean writeData(java.nio.ByteBuffer clearData)
          Writes the data contained in the provided clear-text buffer to the client, performing any necessary encoding in the process.
static boolean writeWithTimeout(ClientConnection clientConnection, java.nio.channels.SocketChannel socketChannel, java.nio.ByteBuffer buffer)
          Writes the contents of the provided buffer to the client, terminating the connection if the write is unsuccessful for too long (e.g., if the client is unresponsive or there is a network problem).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullConnectionSecurityProvider

public NullConnectionSecurityProvider()
Creates a new instance of this connection security provider. Note that no initialization should be done here, since it should all be done in the initializeConnectionSecurityProvider method. Also note that this instance should only be used to create new instances that are associated with specific client connections. This instance itself should not be used to attempt secure communication with the client.


NullConnectionSecurityProvider

protected NullConnectionSecurityProvider(ClientConnection clientConnection,
                                         java.nio.channels.SocketChannel socketChannel)
Creates a new instance of this connection security provider that will be associated with the provided client connection.

Parameters:
clientConnection - The client connection with which this connection security provider should be associated.
socketChannel - The socket channel that may be used to communicate with the client.
Method Detail

initializeConnectionSecurityProvider

public void initializeConnectionSecurityProvider(ConfigEntry configEntry)
                                          throws ConfigException,
                                                 InitializationException
Initializes this connection security provider using the information in the provided configuration entry.

Specified by:
initializeConnectionSecurityProvider in class ConnectionSecurityProvider
Parameters:
configEntry - The entry that contains the configuration for this connection security provider.
Throws:
ConfigException - If the provided entry does not contain an acceptable configuration for this security provider.
InitializationException - If a problem occurs during initialization that is not related to the provided configuration.

finalizeConnectionSecurityProvider

public void finalizeConnectionSecurityProvider()
Performs any finalization that may be necessary for this connection security provider.

Specified by:
finalizeConnectionSecurityProvider in class ConnectionSecurityProvider

getSecurityMechanismName

public java.lang.String getSecurityMechanismName()
Retrieves the name used to identify this security mechanism.

Specified by:
getSecurityMechanismName in class ConnectionSecurityProvider
Returns:
The name used to identify this security mechanism.

isSecure

public boolean isSecure()
Indicates whether client connections using this connection security provider should be considered secure.

Specified by:
isSecure in class ConnectionSecurityProvider
Returns:
true if client connections using this connection security provider should be considered secure, or false if not.

newInstance

public ConnectionSecurityProvider newInstance(ClientConnection clientConnection,
                                              java.nio.channels.SocketChannel socketChannel)
                                       throws DirectoryException
Creates a new instance of this connection security provider that will be used to encode and decode all communication on the provided client connection.

Specified by:
newInstance in class ConnectionSecurityProvider
Parameters:
clientConnection - The client connection with which this security provider will be associated.
socketChannel - The socket channel that may be used to communicate with the client.
Returns:
The created connection security provider instance.
Throws:
DirectoryException - If a problem occurs while creating a new instance of this security provider for the given client connection.

disconnect

public void disconnect(boolean connectionValid)
Indicates that the associated client connection is being closed and that this security provider should perform any necessary processing to deal with that. If it is indicated that the connection is still valid, then the security provider may attempt to communicate with the client to perform a graceful shutdown.

Specified by:
disconnect in class ConnectionSecurityProvider
Parameters:
connectionValid - Indicates whether the Directory Server believes that the client connection is still valid and may be used for communication with the client. Note that this may be inaccurate, or that the state of the connection may change during the course of this method, so the security provider must be able to handle failures if they arise.

getClearBufferSize

public int getClearBufferSize()
Retrieves the size in bytes that the client should use for the byte buffer meant to hold clear-text data read from or to be written to the client.

Specified by:
getClearBufferSize in class ConnectionSecurityProvider
Returns:
The size in bytes that the client should use for the byte buffer meant to hold clear-text data read from or to be written to the client.

getEncodedBufferSize

public int getEncodedBufferSize()
Retrieves the size in bytes that the client should use for the byte buffer meant to hold encoded data read from or to be written to the client.

Specified by:
getEncodedBufferSize in class ConnectionSecurityProvider
Returns:
The size in bytes that the client should use for the byte buffer meant to hold encoded data read from or to be written to the client.

readData

public boolean readData()
Reads data from a client connection, performing any necessary negotiation in the process. Whenever any clear-text data has been obtained, then the connection security provider should make that available to the client by calling the ClientConnection.processDataRead method.

Specified by:
readData in class ConnectionSecurityProvider
Returns:
true if all the data in the provided buffer was processed and the client connection can remain established, or false if a decoding error occurred and requests from this client should no longer be processed. Note that if this method does return false, then it must have already disconnected the client.

writeData

public boolean writeData(java.nio.ByteBuffer clearData)
Writes the data contained in the provided clear-text buffer to the client, performing any necessary encoding in the process. It must be capable of dealing with input buffers that are larger than the value returned by the getClearBufferSize method. When this method returns, the provided buffer should be in its original state with regard to the position and limit.

Specified by:
writeData in class ConnectionSecurityProvider
Parameters:
clearData - The buffer containing the clear-text data to write to the client.
Returns:
true if all the data in the provided buffer was written to the client and the connection may remain established, or false if a problem occurred and the client connection is no longer valid. Note that if this method does return false, then it must have already disconnected the client.

writeWithTimeout

public static boolean writeWithTimeout(ClientConnection clientConnection,
                                       java.nio.channels.SocketChannel socketChannel,
                                       java.nio.ByteBuffer buffer)
                                throws java.io.IOException
Writes the contents of the provided buffer to the client, terminating the connection if the write is unsuccessful for too long (e.g., if the client is unresponsive or there is a network problem). If possible, it will attempt to use the selector returned by the ClientConnection.getWriteSelector method, but it is capable of working even if that method returns null.

Note that this method has been written in a generic manner so that other connection security providers can use it to send data to the client, provided that the given buffer contains the appropriate pre-encoded information.

Also note that the original position and limit values will not be preserved, so if that is important to the caller, then it should record them before calling this method and restore them after it returns.

Parameters:
clientConnection - The client connection to which the data is to be written.
socketChannel - The socket channel over which to write the data.
buffer - The data to be written to the client.
Returns:
true if all the data in the provided buffer was written to the client and the connection may remain established, or false if a problem occurred and the client connection is no longer valid. Note that if this method does return false, then it must have already disconnected the client.
Throws:
java.io.IOException - If a problem occurs while attempting to write data to the client. The caller will be responsible for catching this and terminating the client connection.