Search in sources :

Example 1 with TUGIContainingTransport

use of org.apache.hadoop.hive.metastore.security.TUGIContainingTransport in project hive by apache.

the class TUGIBasedProcessor method setIpAddress.

@Override
protected void setIpAddress(final TProtocol in) {
    TUGIContainingTransport ugiTrans = (TUGIContainingTransport) in.getTransport();
    Socket socket = ugiTrans.getSocket();
    if (socket != null) {
        setIpAddress(socket);
    }
}
Also used : TUGIContainingTransport(org.apache.hadoop.hive.metastore.security.TUGIContainingTransport) Socket(java.net.Socket)

Example 2 with TUGIContainingTransport

use of org.apache.hadoop.hive.metastore.security.TUGIContainingTransport in project hive by apache.

the class TUGIBasedProcessor method process.

@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) {
            // unexpected!
            throw new RuntimeException(ie);
        } catch (IOException ioe) {
            // unexpected!
            throw new RuntimeException(ioe);
        } finally {
            try {
                FileSystem.closeAllForUGI(clientUgi);
            } catch (IOException e) {
                LOG.error("Could not clean up file-system handles for UGI: " + clientUgi, e);
            }
        }
    }
}
Also used : TException(org.apache.thrift.TException) TUGIContainingTransport(org.apache.hadoop.hive.metastore.security.TUGIContainingTransport) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) TProtocolException(org.apache.thrift.protocol.TProtocolException) TApplicationException(org.apache.thrift.TApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TApplicationException(org.apache.thrift.TApplicationException) Iface(org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface) TMessage(org.apache.thrift.protocol.TMessage) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

TUGIContainingTransport (org.apache.hadoop.hive.metastore.security.TUGIContainingTransport)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Socket (java.net.Socket)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Iface (org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.Iface)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1 TMessage (org.apache.thrift.protocol.TMessage)1 TProtocolException (org.apache.thrift.protocol.TProtocolException)1