Package org.apache.thrift.transport
Class TSaslClientTransport
java.lang.Object
org.apache.thrift.transport.TTransport
org.apache.thrift.transport.TEndpointTransport
org.apache.thrift.transport.TSaslClientTransport
- All Implemented Interfaces:
Closeable
,AutoCloseable
Wraps another Thrift
TTransport
, but performs SASL client negotiation on the call to
open()
. This class will wrap ensuing communication over it, if a SASL QOP is
negotiated with the other party.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
protected static final int
protected static final int
protected static final int
protected TTransport
Transport underlying this one.Fields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize
-
Constructor Summary
ConstructorsConstructorDescriptionTSaslClientTransport
(String mechanism, String authorizationId, String protocol, String serverName, Map<String, String> props, CallbackHandler cbh, TTransport transport) Creates aSaslClient
using the given SASL-specific parameters.TSaslClientTransport
(SaslClient saslClient, TTransport transport) Uses the givenSaslClient
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the underlying transport and disposes of the SASL implementation underlying this transport.void
flush()
Flushes to the underlying transport.protected org.apache.thrift.transport.TSaslTransport.SaslRole
getRole()
Get the underlyingSaslClient
.Get the underlyingSaslServer
.Get the underlying transport that Sasl is using.protected void
Performs the client side of the initial portion of the Thrift SASL protocol.boolean
isOpen()
True if the underlying transport is open and the SASL handshake is complete.void
open()
Opens the underlying transport if it's not already open and then performs SASL negotiation.int
read
(byte[] buf, int off, int len) Read from the underlying transport.protected int
Read a 4-byte word from the underlying transport and interpret it as an integer.protected org.apache.thrift.transport.TSaslTransport.SaslResponse
Read a complete Thrift SASL message.protected TTransportException
sendAndThrowMessage
(NegotiationStatus status, String message) Send a Thrift SASL message with the given status (usually BAD or ERROR) and string message, and then throw a TTransportException with the given message.protected void
sendSaslMessage
(NegotiationStatus status, byte[] payload) Send a complete Thrift SASL message.protected void
setSaslServer
(SaslServer saslServer) void
write
(byte[] buf, int off, int len) Write to the underlying transport.protected void
writeLength
(int length) Write the given integer as 4 bytes to the underlying transport.Methods inherited from class org.apache.thrift.transport.TEndpointTransport
checkReadBytesAvailable, countConsumedMessageBytes, getConfiguration, getMaxFrameSize, getMaxMessageSize, resetConsumedMessageSize, setMaxFrameSize, updateKnownMessageSize
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, read, readAll, write, write
-
Field Details
-
DEFAULT_MAX_LENGTH
protected static final int DEFAULT_MAX_LENGTH- See Also:
-
MECHANISM_NAME_BYTES
protected static final int MECHANISM_NAME_BYTES- See Also:
-
STATUS_BYTES
protected static final int STATUS_BYTES- See Also:
-
PAYLOAD_LENGTH_BYTES
protected static final int PAYLOAD_LENGTH_BYTES- See Also:
-
underlyingTransport
Transport underlying this one.
-
-
Constructor Details
-
TSaslClientTransport
Uses the givenSaslClient
.- Parameters:
saslClient
- TheSaslClient
to use for the subsequent SASL negotiation.transport
- Transport underlying this one.- Throws:
TTransportException
-
TSaslClientTransport
public TSaslClientTransport(String mechanism, String authorizationId, String protocol, String serverName, Map<String, String> props, CallbackHandler cbh, TTransport transport) throws SaslException, TTransportExceptionCreates aSaslClient
using the given SASL-specific parameters. See the Java documentation forSasl.createSaslClient
for the details of the parameters.- Parameters:
transport
- The underlying Thrift transport.- Throws:
SaslException
TTransportException
-
-
Method Details
-
getRole
protected org.apache.thrift.transport.TSaslTransport.SaslRole getRole() -
handleSaslStartMessage
Performs the client side of the initial portion of the Thrift SASL protocol. Generates and sends the initial response to the server, including which mechanism this client wants to use.- Throws:
TTransportException
SaslException
-
setSaslServer
-
sendSaslMessage
Send a complete Thrift SASL message.- Parameters:
status
- The status to send.payload
- The data to send as the payload of this message.- Throws:
TTransportException
-
receiveSaslMessage
protected org.apache.thrift.transport.TSaslTransport.SaslResponse receiveSaslMessage() throws TTransportExceptionRead a complete Thrift SASL message.- Returns:
- The SASL status and payload from this message.
- Throws:
TTransportException
- Thrown if there is a failure reading from the underlying transport, or if a status code of BAD or ERROR is encountered.
-
sendAndThrowMessage
protected TTransportException sendAndThrowMessage(NegotiationStatus status, String message) throws TTransportException Send a Thrift SASL message with the given status (usually BAD or ERROR) and string message, and then throw a TTransportException with the given message.- Parameters:
status
- The Thrift SASL status code to send. Usually BAD or ERROR.message
- The optional message to send to the other side.- Returns:
- always throws TTransportException but declares return type to allow throw sendAndThrowMessage(...) to inform compiler control flow
- Throws:
TTransportException
- Always thrown with the message provided.
-
open
Opens the underlying transport if it's not already open and then performs SASL negotiation. If a QOP is negotiated during this SASL handshake, it used for all communication on this transport after this call is complete.- Specified by:
open
in classTTransport
- Throws:
TTransportException
- if the transport could not be opened
-
getSaslClient
Get the underlyingSaslClient
.- Returns:
- The
SaslClient
, ornull
if this transport is backed by aSaslServer
.
-
getUnderlyingTransport
Get the underlying transport that Sasl is using.- Returns:
- The
TTransport
transport
-
getSaslServer
Get the underlyingSaslServer
.- Returns:
- The
SaslServer
, ornull
if this transport is backed by aSaslClient
.
-
readLength
Read a 4-byte word from the underlying transport and interpret it as an integer.- Returns:
- The length prefix of the next SASL message to read.
- Throws:
TTransportException
- Thrown if reading from the underlying transport fails.
-
writeLength
Write the given integer as 4 bytes to the underlying transport.- Parameters:
length
- The length prefix of the next SASL message to write.- Throws:
TTransportException
- Thrown if writing to the underlying transport fails.
-
close
public void close()Closes the underlying transport and disposes of the SASL implementation underlying this transport.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classTTransport
-
isOpen
public boolean isOpen()True if the underlying transport is open and the SASL handshake is complete.- Specified by:
isOpen
in classTTransport
- Returns:
- True if the transport is open.
-
read
Read from the underlying transport. Unwraps the contents if a QOP was negotiated during the SASL handshake.- Specified by:
read
in classTTransport
- Parameters:
buf
- Array to read intooff
- Index to start reading atlen
- Maximum number of bytes to read- Returns:
- The number of bytes actually read
- Throws:
TTransportException
- if there was an error reading data
-
write
Write to the underlying transport.- Specified by:
write
in classTTransport
- Parameters:
buf
- The output data bufferoff
- The offset to start writing fromlen
- The number of bytes to write- Throws:
TTransportException
- if there was an error writing data
-
flush
Flushes to the underlying transport. Wraps the contents if a QOP was negotiated during the SASL handshake.- Overrides:
flush
in classTTransport
- Throws:
TTransportException
- if there was an error writing out data.
-