code: private IoBuffer encodeAuthenticationPacket(final SocksProxyRequest request)
              throws UnsupportedEncodingException, GSSException {
          byte method = (Byte) getSession().getAttribute(
                  Socks5LogicHandler.SELECTED_AUTH_METHOD);
  
          switch (method) {
              case SocksProxyConstants.NO_AUTH:
                  // In this case authentication is immediately considered as successfull
                  // Next writeRequest() call will send the proxy request
                  getSession().setAttribute(HANDSHAKE_STEP,
                          SocksProxyConstants.SOCKS5_REQUEST_STEP);
                  break;
      
              case SocksProxyConstants.GSSAPI_AUTH:
                  return encodeGSSAPIAuthenticationPacket(request);
      
              case SocksProxyConstants.BASIC_AUTH:
                  // The basic auth scheme packet is sent
                  byte[] user = request.getUserName().getBytes("ASCII");
                  byte[] pwd = request.getPassword().getBytes("ASCII");
                  IoBuffer buf = IoBuffer.allocate(3 + user.length + pwd.length);
      
                  buf.put(SocksProxyConstants.BASIC_AUTH_SUBNEGOTIATION_VERSION);
                  buf.put((byte) user.length);
                  buf.put(user);
                  buf.put((byte) pwd.length);
                  buf.put(pwd);
      
                  return buf;
          }
  
          return null;
      }
docs: Encodes the authentication packet for supported authentication methods.
  
  @param request the socks proxy request data
  @return the encoded buffer, if null then authentication step is over
  and handshake process can jump immediately to the next step without waiting
  for a server reply.
  @throws UnsupportedEncodingException if some string charset convertion fails
  @throws GSSException when something fails while using GSSAPI