public class TSaslClientTransport extends TTransport
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.Modifier and Type | Class and Description |
---|---|
protected static class |
org.apache.thrift.transport.TSaslTransport.NegotiationStatus
Status bytes used during the initial Thrift SASL handshake.
|
protected static class |
org.apache.thrift.transport.TSaslTransport.SaslResponse
Used exclusively by readSaslMessage to return both a status and data.
|
protected static class |
org.apache.thrift.transport.TSaslTransport.SaslRole |
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_MAX_LENGTH |
protected static int |
MECHANISM_NAME_BYTES |
protected static int |
PAYLOAD_LENGTH_BYTES |
protected static int |
STATUS_BYTES |
protected TTransport |
underlyingTransport
Transport underlying this one.
|
Constructor and Description |
---|
TSaslClientTransport(javax.security.sasl.SaslClient saslClient,
TTransport transport)
Uses the given
SaslClient . |
TSaslClientTransport(java.lang.String mechanism,
java.lang.String authorizationId,
java.lang.String protocol,
java.lang.String serverName,
java.util.Map<java.lang.String,java.lang.String> props,
javax.security.auth.callback.CallbackHandler cbh,
TTransport transport)
Creates a
SaslClient using the given SASL-specific parameters. |
Modifier and Type | Method and Description |
---|---|
void |
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() |
javax.security.sasl.SaslClient |
getSaslClient()
Get the underlying
SaslClient . |
javax.security.sasl.SaslServer |
getSaslServer()
Get the underlying
SaslServer . |
TTransport |
getUnderlyingTransport()
Get the underlying transport that Sasl is using.
|
protected void |
handleSaslStartMessage()
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 |
readLength()
Read a 4-byte word from the underlying transport and interpret it as an
integer.
|
protected org.apache.thrift.transport.TSaslTransport.SaslResponse |
receiveSaslMessage()
Read a complete Thrift SASL message.
|
protected TTransportException |
sendAndThrowMessage(org.apache.thrift.transport.TSaslTransport.NegotiationStatus status,
java.lang.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(org.apache.thrift.transport.TSaslTransport.NegotiationStatus status,
byte[] payload)
Send a complete Thrift SASL message.
|
protected void |
setSaslServer(javax.security.sasl.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.
|
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, readAll, write
protected static final int DEFAULT_MAX_LENGTH
protected static final int MECHANISM_NAME_BYTES
protected static final int STATUS_BYTES
protected static final int PAYLOAD_LENGTH_BYTES
protected TTransport underlyingTransport
public TSaslClientTransport(javax.security.sasl.SaslClient saslClient, TTransport transport)
SaslClient
.saslClient
- The SaslClient
to use for the subsequent SASL
negotiation.transport
- Transport underlying this one.public TSaslClientTransport(java.lang.String mechanism, java.lang.String authorizationId, java.lang.String protocol, java.lang.String serverName, java.util.Map<java.lang.String,java.lang.String> props, javax.security.auth.callback.CallbackHandler cbh, TTransport transport) throws javax.security.sasl.SaslException
SaslClient
using the given SASL-specific parameters.
See the Java documentation for Sasl.createSaslClient
for the
details of the parameters.transport
- The underlying Thrift transport.javax.security.sasl.SaslException
protected org.apache.thrift.transport.TSaslTransport.SaslRole getRole()
protected void handleSaslStartMessage() throws TTransportException, javax.security.sasl.SaslException
TTransportException
javax.security.sasl.SaslException
protected void setSaslServer(javax.security.sasl.SaslServer saslServer)
protected void sendSaslMessage(org.apache.thrift.transport.TSaslTransport.NegotiationStatus status, byte[] payload) throws TTransportException
status
- The status to send.payload
- The data to send as the payload of this message.TTransportException
protected org.apache.thrift.transport.TSaslTransport.SaslResponse receiveSaslMessage() throws TTransportException
TTransportException
- Thrown if there is a failure reading from the underlying
transport, or if a status code of BAD or ERROR is encountered.protected TTransportException sendAndThrowMessage(org.apache.thrift.transport.TSaslTransport.NegotiationStatus status, java.lang.String message) throws TTransportException
status
- The Thrift SASL status code to send. Usually BAD or ERROR.message
- The optional message to send to the other side.TTransportException
- Always thrown with the message provided.public void open() throws TTransportException
open
in class TTransport
TTransportException
- if the transport could not be openedpublic javax.security.sasl.SaslClient getSaslClient()
SaslClient
.SaslClient
, or null
if this transport
is backed by a SaslServer
.public TTransport getUnderlyingTransport()
TTransport
transportpublic javax.security.sasl.SaslServer getSaslServer()
SaslServer
.SaslServer
, or null
if this transport
is backed by a SaslClient
.protected int readLength() throws TTransportException
TTransportException
- Thrown if reading from the underlying transport fails.protected void writeLength(int length) throws TTransportException
length
- The length prefix of the next SASL message to write.TTransportException
- Thrown if writing to the underlying transport fails.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class TTransport
public boolean isOpen()
isOpen
in class TTransport
public int read(byte[] buf, int off, int len) throws TTransportException
read
in class TTransport
buf
- Array to read intooff
- Index to start reading atlen
- Maximum number of bytes to readTTransportException
- if there was an error reading datapublic void write(byte[] buf, int off, int len) throws TTransportException
write
in class TTransport
buf
- The output data bufferoff
- The offset to start writing fromlen
- The number of bytes to writeTTransportException
- if there was an error writing datapublic void flush() throws TTransportException
flush
in class TTransport
TTransportException
- if there was an error writing out data.