diff --git a/hbase-client/pom.xml b/hbase-client/pom.xml index 9df71e3..a009f46 100644 --- a/hbase-client/pom.xml +++ b/hbase-client/pom.xml @@ -105,6 +105,11 @@ io.netty netty + + commons-io + commons-io + 2.4 + diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java index 6f78fa3..8e22cb3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/RpcClient.java @@ -257,14 +257,21 @@ public class RpcClient { boolean done; // true when call is done long startTime; final MethodDescriptor md; + String methodUser; protected Call(final MethodDescriptor md, Message param, final CellScanner cells, final Message responseDefaultType) { + this(md, param, cells, responseDefaultType, null); + } + + protected Call(final MethodDescriptor md, Message param, final CellScanner cells, + final Message responseDefaultType, String methodUser) { this.param = param; this.md = md; this.cells = cells; this.startTime = System.currentTimeMillis(); this.responseDefaultType = responseDefaultType; + this.methodUser = methodUser; synchronized (RpcClient.this) { this.id = counter++; } @@ -309,6 +316,14 @@ public class RpcClient { public long getStartTime() { return this.startTime; } + + /** + * Method will be called as this user + * @return + */ + public String getMethodUser() { + return methodUser; + } } protected final static Map headerAndParam = new Pair(header, param); @@ -1822,9 +1837,20 @@ public class RpcServer implements RpcServerInterface { currentRequestSpan = Trace.startSpan( "handling " + call.toShortString(), call.tinfo, Sampler.ALWAYS); } - RequestContext.set(User.create(call.connection.user), getRemoteIp(), + //if call has proxy user set use it + UserGroupInformation callUser = call.connection.user; + if(call.getMethodUser() != null) { + UserGroupInformation connUser = call.connection.user; + if(connUser.getRealUser() != null) { + connUser = connUser.getRealUser(); + } + callUser = UserGroupInformation.createProxyUser(call.getMethodUser(), connUser); + ProxyUsers.authorize(callUser, call.connection.getHostAddress(), conf); + } + RequestContext.set( + User.create(callUser), + getRemoteIp(), call.connection.service); - // make the call resultPair = call(call.service, call.md, call.param, call.cellScanner, call.timestamp, status);