Package org.apache.thrift.transport
Class TSaslServerTransport
- java.lang.Object
-
- org.apache.thrift.transport.TTransport
-
- org.apache.thrift.transport.TEndpointTransport
-
- org.apache.thrift.transport.TSaslServerTransport
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class TSaslServerTransport extends TEndpointTransport
Wraps another ThriftTTransport, but performs SASL server negotiation on the call toopen(). This class will wrap ensuing communication over it, if a SASL QOP is negotiated with the other party.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTSaslServerTransport.FactoryTTransportFactoryto createTSaslServerTransports.
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_MAX_LENGTHprotected static intMECHANISM_NAME_BYTESprotected static intPAYLOAD_LENGTH_BYTESprotected static intSTATUS_BYTESprotected TTransportunderlyingTransportTransport underlying this one.-
Fields inherited from class org.apache.thrift.transport.TEndpointTransport
knownMessageSize, remainingMessageSize
-
-
Constructor Summary
Constructors Constructor Description TSaslServerTransport(java.lang.String mechanism, 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 aSaslServerusing the given SASL-specific parameters.TSaslServerTransport(TTransport transport)Uses the given underlying transport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddServerDefinition(java.lang.String mechanism, java.lang.String protocol, java.lang.String serverName, java.util.Map<java.lang.String,java.lang.String> props, javax.security.auth.callback.CallbackHandler cbh)Add a supported server definition to this transport.voidclose()Closes the underlying transport and disposes of the SASL implementation underlying this transport.voidflush()Flushes to the underlying transport.protected org.apache.thrift.transport.TSaslTransport.SaslRolegetRole()javax.security.sasl.SaslClientgetSaslClient()Get the underlyingSaslClient.javax.security.sasl.SaslServergetSaslServer()Get the underlyingSaslServer.TTransportgetUnderlyingTransport()Get the underlying transport that Sasl is using.protected voidhandleSaslStartMessage()Performs the server side of the initial portion of the Thrift SASL protocol.booleanisOpen()True if the underlying transport is open and the SASL handshake is complete.voidopen()Opens the underlying transport if it's not already open and then performs SASL negotiation.intread(byte[] buf, int off, int len)Read from the underlying transport.protected intreadLength()Read a 4-byte word from the underlying transport and interpret it as an integer.protected org.apache.thrift.transport.TSaslTransport.SaslResponsereceiveSaslMessage()Read a complete Thrift SASL message.protected TTransportExceptionsendAndThrowMessage(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 voidsendSaslMessage(NegotiationStatus status, byte[] payload)Send a complete Thrift SASL message.protected voidsetSaslServer(javax.security.sasl.SaslServer saslServer)voidwrite(byte[] buf, int off, int len)Write to the underlying transport.protected voidwriteLength(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, getMaxMessageSize, resetConsumedMessageSize, updateKnownMessageSize
-
Methods inherited from class org.apache.thrift.transport.TTransport
consumeBuffer, getBuffer, getBufferPosition, getBytesRemainingInBuffer, peek, read, readAll, write, write
-
-
-
-
Field Detail
-
DEFAULT_MAX_LENGTH
protected static final int DEFAULT_MAX_LENGTH
- See Also:
- Constant Field Values
-
MECHANISM_NAME_BYTES
protected static final int MECHANISM_NAME_BYTES
- See Also:
- Constant Field Values
-
STATUS_BYTES
protected static final int STATUS_BYTES
- See Also:
- Constant Field Values
-
PAYLOAD_LENGTH_BYTES
protected static final int PAYLOAD_LENGTH_BYTES
- See Also:
- Constant Field Values
-
underlyingTransport
protected TTransport underlyingTransport
Transport underlying this one.
-
-
Constructor Detail
-
TSaslServerTransport
public TSaslServerTransport(TTransport transport) throws TTransportException
Uses the given underlying transport. Assumes that addServerDefinition is called later.- Parameters:
transport- Transport underlying this one.- Throws:
TTransportException
-
TSaslServerTransport
public TSaslServerTransport(java.lang.String mechanism, 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 TTransportExceptionCreates aSaslServerusing the given SASL-specific parameters. See the Java documentation forSasl.createSaslServerfor the details of the parameters.- Parameters:
transport- The underlying Thrift transport.- Throws:
TTransportException
-
-
Method Detail
-
addServerDefinition
public void addServerDefinition(java.lang.String mechanism, java.lang.String protocol, java.lang.String serverName, java.util.Map<java.lang.String,java.lang.String> props, javax.security.auth.callback.CallbackHandler cbh)Add a supported server definition to this transport. See the Java documentation forSasl.createSaslServerfor the details of the parameters.
-
getRole
protected org.apache.thrift.transport.TSaslTransport.SaslRole getRole()
-
handleSaslStartMessage
protected void handleSaslStartMessage() throws TTransportException, javax.security.sasl.SaslExceptionPerforms the server side of the initial portion of the Thrift SASL protocol. Receives the initial response from the client, creates a SASL server using the mechanism requested by the client (if this server supports it), and sends the first challenge back to the client.- Throws:
TTransportExceptionjavax.security.sasl.SaslException
-
setSaslServer
protected void setSaslServer(javax.security.sasl.SaslServer saslServer)
-
sendSaslMessage
protected void sendSaslMessage(NegotiationStatus status, byte[] payload) throws TTransportException
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, java.lang.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
public void open() throws TTransportExceptionOpens 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:
openin classTTransport- Throws:
TTransportException- if the transport could not be opened
-
getSaslClient
public javax.security.sasl.SaslClient getSaslClient()
Get the underlyingSaslClient.- Returns:
- The
SaslClient, ornullif this transport is backed by aSaslServer.
-
getUnderlyingTransport
public TTransport getUnderlyingTransport()
Get the underlying transport that Sasl is using.- Returns:
- The
TTransporttransport
-
getSaslServer
public javax.security.sasl.SaslServer getSaslServer()
Get the underlyingSaslServer.- Returns:
- The
SaslServer, ornullif this transport is backed by aSaslClient.
-
readLength
protected int readLength() throws TTransportExceptionRead 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
protected void writeLength(int length) throws TTransportExceptionWrite 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classTTransport
-
isOpen
public boolean isOpen()
True if the underlying transport is open and the SASL handshake is complete.- Specified by:
isOpenin classTTransport- Returns:
- True if the transport is open.
-
read
public int read(byte[] buf, int off, int len) throws TTransportExceptionRead from the underlying transport. Unwraps the contents if a QOP was negotiated during the SASL handshake.- Specified by:
readin 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
public void write(byte[] buf, int off, int len) throws TTransportExceptionWrite to the underlying transport.- Specified by:
writein 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
public void flush() throws TTransportExceptionFlushes to the underlying transport. Wraps the contents if a QOP was negotiated during the SASL handshake.- Overrides:
flushin classTTransport- Throws:
TTransportException- if there was an error writing out data.
-
-