Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
apache::thrift::transport::TSaslTransport Class Referenceabstract

#include <TSaslTransport.h>

Inheritance diagram for apache::thrift::transport::TSaslTransport:
Collaboration diagram for apache::thrift::transport::TSaslTransport:

Public Member Functions

 TSaslTransport (boost::shared_ptr< TTransport > transport)
 
 TSaslTransport (boost::shared_ptr< sasl::TSasl > saslClient, boost::shared_ptr< TTransport > transport)
 
virtual ~TSaslTransport ()
 
virtual bool isOpen ()
 
virtual bool peek ()
 
virtual void open ()
 
virtual void close ()
 
uint32_t read (uint8_t *buf, uint32_t len)
 
void write (const uint8_t *buf, uint32_t len)
 
virtual void flush ()
 
boost::shared_ptr< TTransport > getUnderlyingTransport ()
 
std::string getUsername ()
 

Protected Member Functions

void encodeInt (uint32_t x, uint8_t *buf, uint32_t offset)
 
uint32_t decodeInt (uint8_t *buf, uint32_t offset)
 
uint8_t * receiveSaslMessage (NegotiationStatus *status, uint32_t *length)
 
void sendSaslMessage (const NegotiationStatus status, const uint8_t *payload, const uint32_t length, bool flush=true)
 
uint32_t readLength ()
 
void writeLength (uint32_t length)
 
virtual void handleSaslStartMessage ()=0
 
void shrinkBuffer ()
 

Protected Attributes

boost::shared_ptr< TTransport > transport_
 Underlying transport. More...
 
TMemoryBuffer * memBuf_
 Buffer for reading and writing. More...
 
boost::shared_ptr< sasl::TSaslsasl_
 
bool shouldWrap_
 IF true we wrap data in encryption. More...
 
bool isClient_
 True if this is a client. More...
 
boost::scoped_array< uint8_t > protoBuf_
 Buffer to hold protocol info. More...
 

Detailed Description

This transport implements the Simple Authentication and Security Layer (SASL). see: http://www.ietf.org/rfc/rfc2222.txt. It is based on and depends on the presence of the cyrus-sasl library.

Definition at line 56 of file TSaslTransport.h.

Constructor & Destructor Documentation

apache::thrift::transport::TSaslTransport::TSaslTransport ( boost::shared_ptr< TTransport >  transport)

Constructs a new TSaslTransport to act as a server. SetSaslServer must be called later to initialize the SASL endpoint underlying this transport.

Definition at line 39 of file TSaslTransport.cpp.

apache::thrift::transport::TSaslTransport::TSaslTransport ( boost::shared_ptr< sasl::TSasl saslClient,
boost::shared_ptr< TTransport >  transport 
)

Constructs a new TSaslTransport to act as a client.

Definition at line 46 of file TSaslTransport.cpp.

apache::thrift::transport::TSaslTransport::~TSaslTransport ( )
virtual

Destroys the TSasl object.

Definition at line 55 of file TSaslTransport.cpp.

References memBuf_.

Member Function Documentation

void apache::thrift::transport::TSaslTransport::close ( )
virtual

Closes the transport.

Definition at line 134 of file TSaslTransport.cpp.

References transport_.

uint32_t apache::thrift::transport::TSaslTransport::decodeInt ( uint8_t *  buf,
uint32_t  offset 
)
inlineprotected

Definition at line 173 of file TSaslTransport.h.

Referenced by readLength(), and receiveSaslMessage().

void apache::thrift::transport::TSaslTransport::encodeInt ( uint32_t  x,
uint8_t *  buf,
uint32_t  offset 
)
inlineprotected

Definition at line 168 of file TSaslTransport.h.

References offset.

Referenced by sendSaslMessage(), and writeLength().

void apache::thrift::transport::TSaslTransport::flush ( )
virtual

Flushes any pending data to be written. Typically used with buffered transport mechanisms.

Exceptions
TTransportExceptionif an error occurs

Definition at line 228 of file TSaslTransport.cpp.

References transport_.

boost::shared_ptr<TTransport> apache::thrift::transport::TSaslTransport::getUnderlyingTransport ( )
inline

Returns the transport underlying this one

Definition at line 136 of file TSaslTransport.h.

References transport_.

Referenced by impala::ThriftServer::ThriftServerEventProcessor::createContext().

string apache::thrift::transport::TSaslTransport::getUsername ( )

Returns the username associated with the underlying sasl connection.

Exceptions
TTransportExceptionif an error occurs

Definition at line 67 of file TSaslTransport.cpp.

References sasl_.

Referenced by impala::ThriftServer::ThriftServerEventProcessor::createContext().

virtual void apache::thrift::transport::TSaslTransport::handleSaslStartMessage ( )
protectedpure virtual
bool apache::thrift::transport::TSaslTransport::isOpen ( )
virtual

Whether this transport is open.

Definition at line 59 of file TSaslTransport.cpp.

References transport_.

void apache::thrift::transport::TSaslTransport::open ( )
virtual
bool apache::thrift::transport::TSaslTransport::peek ( )
virtual

Tests whether there is more data to read or if the remote side is still open.

Definition at line 63 of file TSaslTransport.cpp.

References transport_.

uint32_t apache::thrift::transport::TSaslTransport::read ( uint8_t *  buf,
uint32_t  len 
)

Attempt to read up to the specified number of bytes into the string.

Parameters
bufReference to the location to write the data
lenHow many bytes to read
Returns
How many bytes were actually read
Exceptions
TTransportExceptionIf an error occurs

Definition at line 170 of file TSaslTransport.cpp.

References memBuf_, readLength(), sasl_, shouldWrap_, shrinkBuffer(), and transport_.

uint32_t apache::thrift::transport::TSaslTransport::readLength ( )
protected

Opens the transport for communications.

Returns
bool Whether the transport was successfully opened
Exceptions
TTransportExceptionif opening failed

Definition at line 138 of file TSaslTransport.cpp.

References decodeInt(), apache::thrift::transport::PAYLOAD_LENGTH_BYTES, and transport_.

Referenced by read().

uint8_t * apache::thrift::transport::TSaslTransport::receiveSaslMessage ( NegotiationStatus status,
uint32_t *  length 
)
protected

Read a complete Thrift SASL message.

Returns
The SASL status and payload from this message. Is valid only to till the next call.
Exceptions
TTransportExceptionThrown if there is a failure reading from the underlying transport, or if a status code of BAD or ERROR is encountered.

Definition at line 232 of file TSaslTransport.cpp.

References decodeInt(), apache::thrift::transport::HEADER_LENGTH, protoBuf_, apache::thrift::transport::STATUS_BYTES, transport_, apache::thrift::transport::TSASL_BAD, apache::thrift::transport::TSASL_COMPLETE, apache::thrift::transport::TSASL_ERROR, and apache::thrift::transport::TSASL_START.

Referenced by apache::thrift::transport::TSaslServerTransport::handleSaslStartMessage(), and open().

void apache::thrift::transport::TSaslTransport::sendSaslMessage ( const NegotiationStatus  status,
const uint8_t *  payload,
const uint32_t  length,
bool  flush = true 
)
protected

send message with SASL transport headers. status is put before the payload. If flush is false we delay flushing the underlying transport so that the following message will be in the same packet if necessary.

Definition at line 71 of file TSaslTransport.cpp.

References encodeInt(), apache::thrift::transport::HEADER_LENGTH, apache::thrift::transport::PAYLOAD_LENGTH_BYTES, apache::thrift::transport::STATUS_BYTES, and transport_.

Referenced by apache::thrift::transport::TSaslServerTransport::handleSaslStartMessage(), apache::thrift::transport::TSaslClientTransport::handleSaslStartMessage(), and open().

void apache::thrift::transport::TSaslTransport::shrinkBuffer ( )
protected

If memBuf_ is filled with bytes that are already read, and has crossed a size threshold (see implementation for exact value), resize the buffer to a default value.

Definition at line 149 of file TSaslTransport.cpp.

References DEFAULT_MEM_BUF_SIZE, and memBuf_.

Referenced by read().

void apache::thrift::transport::TSaslTransport::write ( const uint8_t *  buf,
uint32_t  len 
)

Writes the string in its entirety to the buffer.

Note: You must call flush() to ensure the data is actually written, and available to be read back in the future. Destroying a TTransport object does not automatically flush pending data–if you destroy a TTransport object with written but unflushed data, that data may be discarded.

Parameters
bufThe data to write out
Exceptions
TTransportExceptionif an error occurs

Definition at line 216 of file TSaslTransport.cpp.

References sasl_, shouldWrap_, transport_, and writeLength().

void apache::thrift::transport::TSaslTransport::writeLength ( uint32_t  length)
protected

Write the given integer as 4 bytes to the underlying transport.

Parameters
lengthThe length prefix of the next SASL message to write.
Exceptions
TTransportExceptionThrown if writing to the underlying transport fails.

Definition at line 209 of file TSaslTransport.cpp.

References encodeInt(), apache::thrift::transport::PAYLOAD_LENGTH_BYTES, and transport_.

Referenced by write().

Member Data Documentation

bool apache::thrift::transport::TSaslTransport::isClient_
protected

True if this is a client.

Definition at line 162 of file TSaslTransport.h.

Referenced by open(), and apache::thrift::transport::TSaslServerTransport::setSaslServer().

TMemoryBuffer* apache::thrift::transport::TSaslTransport::memBuf_
protected

Buffer for reading and writing.

Definition at line 152 of file TSaslTransport.h.

Referenced by read(), shrinkBuffer(), and ~TSaslTransport().

boost::scoped_array<uint8_t> apache::thrift::transport::TSaslTransport::protoBuf_
protected

Buffer to hold protocol info.

Definition at line 165 of file TSaslTransport.h.

Referenced by receiveSaslMessage().

boost::shared_ptr<sasl::TSasl> apache::thrift::transport::TSaslTransport::sasl_
protected

Sasl implementation class. This is passed in to the transport constructor initialized for either a client or a server.

Definition at line 156 of file TSaslTransport.h.

Referenced by getUsername(), apache::thrift::transport::TSaslServerTransport::handleSaslStartMessage(), apache::thrift::transport::TSaslClientTransport::handleSaslStartMessage(), open(), read(), apache::thrift::transport::TSaslServerTransport::setSaslServer(), and write().

bool apache::thrift::transport::TSaslTransport::shouldWrap_
protected

IF true we wrap data in encryption.

Definition at line 159 of file TSaslTransport.h.

Referenced by read(), and write().

boost::shared_ptr<TTransport> apache::thrift::transport::TSaslTransport::transport_
protected

The documentation for this class was generated from the following files: