buffer.put( TLV.getBytes( getBindRequestLength() ) );
}
catch ( BufferOverflowException boe )
{
throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
}
// The version (LDAP V3 only)
Value.encode( buffer, 3 );
// The name
Dn name = getName();
// The name
if ( name == null )
{
name = Dn.EMPTY_DN;
}
Value.encode( buffer, Dn.getBytes( name ) );
byte[] credentials = getCredentials();
// The authentication
if ( isSimple() )
{
// Simple authentication
try
{
// The simpleAuthentication Tag
buffer.put( ( byte ) LdapConstants.BIND_REQUEST_SIMPLE_TAG );
if ( credentials != null )
{
buffer.put( TLV.getBytes( credentials.length ) );
if ( credentials.length != 0 )
{
buffer.put( credentials );
}
}
else
{
buffer.put( ( byte ) 0 );
}
}
catch ( BufferOverflowException boe )
{
String msg = I18n.err( I18n.ERR_04005 );
throw new EncoderException( msg );
}
}
else
{
// SASL Bind
try
{
// The saslAuthentication Tag
buffer.put( ( byte ) LdapConstants.BIND_REQUEST_SASL_TAG );
byte[] mechanismBytes = Strings.getBytesUtf8( getSaslMechanism() );
buffer.put( TLV
.getBytes( getSaslMechanismLength() + getSaslCredentialsLength() ) );
Value.encode( buffer, mechanismBytes );
if ( credentials != null )
{
Value.encode( buffer, credentials );
}
}
catch ( BufferOverflowException boe )
{
String msg = I18n.err( I18n.ERR_04005 );
throw new EncoderException( msg );
}
}
return buffer;
}