@SuppressWarnings("unchecked")
  @Override
  public void process(final TProtocol in, final TProtocol out) throws TException {
   setIpAddress(in);

   final TMessage msg = in.readMessageBegin();
   final ProcessFunction<Iface, ? extends  TBase> fn = functions.get(msg.name);
   if (fn == null) {
     TProtocolUtil.skip(in, TType.STRUCT);
     in.readMessageEnd();
     TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD,
         "Invalid method name: '"+msg.name+"'");
     out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
     x.write(out);
     out.writeMessageEnd();
     out.getTransport().flush();
     return;
   }
   TUGIContainingTransport ugiTrans = (TUGIContainingTransport)in.getTransport();
   // Store ugi in transport if the rpc is set_ugi
   if (msg.name.equalsIgnoreCase("set_ugi")){
     try {
       handleSetUGI(ugiTrans, (ThriftHiveMetastore.Processor.set_ugi<Iface>)fn, msg, in, out);
     } catch (TException e) {
       throw e;
     } catch (Exception e) {
       throw new TException(e.getCause());
     }
     return;
   }
   UserGroupInformation clientUgi = ugiTrans.getClientUGI();
   if (null == clientUgi){
     // At this point, transport must contain client ugi, if it doesn't then its an old client.
     fn.process(msg.seqid, in, out, iface);
     return;
   } else { // Found ugi, perform doAs().
     PrivilegedExceptionAction<Void> pvea = new PrivilegedExceptionAction<Void>() {
       @Override
       public Void run() {
         try {
           fn.process(msg.seqid,in, out, iface);
           return null;
         } catch (TException te) {
           throw new RuntimeException(te);
         }
       }
     };
     try {
       clientUgi.doAs(pvea);
       return;
     } catch (RuntimeException rte) {
       if (rte.getCause() instanceof TException) {
         throw (TException)rte.getCause();
       }
       throw rte;
     } catch (InterruptedException ie) {
       throw new RuntimeException(ie); // unexpected!
     } catch (IOException ioe) {
       throw new RuntimeException(ioe); // unexpected!
     } finally {
         try {
           FileSystem.closeAllForUGI(clientUgi);
         } catch (IOException e) {
           LOG.error("Could not clean up file-system handles for UGI: " + clientUgi, e);
         }
     }
   }
  }
TUGIBasedProcessor is used in unsecure mode for thrift metastore client server communication.
 This processor checks whether the first rpc call after connection is set up is set_ugi()
 through which client sends ugi to server. Processor then perform all subsequent rpcs on the
 connection using ugi.doAs() so all actions are performed in client user context.
 Note that old clients will never call set_ugi() and thus ugi will never be received on server
 side, in which case server exhibits previous behavior and continues as usual.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/TUGIBasedProcessor.java