|
@@ -17,35 +17,40 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.security;
|
|
|
|
|
|
-import com.google.protobuf.ServiceException;
|
|
|
-import org.apache.commons.logging.Log;
|
|
|
-import org.apache.commons.logging.LogFactory;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
+import java.net.NetworkInterface;
|
|
|
+import java.security.PrivilegedExceptionAction;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Enumeration;
|
|
|
+
|
|
|
+import org.junit.Assert;
|
|
|
+
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
-import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
import org.apache.hadoop.io.Text;
|
|
|
-import org.apache.hadoop.ipc.ProtobufRpcEngine;
|
|
|
+import org.apache.hadoop.ipc.ProtocolSignature;
|
|
|
import org.apache.hadoop.ipc.RPC;
|
|
|
import org.apache.hadoop.ipc.Server;
|
|
|
-import org.apache.hadoop.ipc.TestRpcBase;
|
|
|
+import org.apache.hadoop.ipc.VersionedProtocol;
|
|
|
+import org.apache.hadoop.net.NetUtils;
|
|
|
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
|
|
|
import org.apache.hadoop.security.authorize.DefaultImpersonationProvider;
|
|
|
import org.apache.hadoop.security.authorize.ProxyUsers;
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
|
-import org.junit.Assert;
|
|
|
+import org.apache.hadoop.security.token.TokenInfo;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.net.NetworkInterface;
|
|
|
-import java.security.PrivilegedExceptionAction;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Enumeration;
|
|
|
+import org.apache.hadoop.ipc.TestRpcBase.TestTokenSecretManager;
|
|
|
+import org.apache.hadoop.ipc.TestRpcBase.TestTokenIdentifier;
|
|
|
+import org.apache.hadoop.ipc.TestRpcBase.TestTokenSelector;
|
|
|
+import org.apache.commons.logging.*;
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
|
|
|
/**
|
|
|
- * Test do as effective user.
|
|
|
+ *
|
|
|
*/
|
|
|
-public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
+public class TestDoAsEffectiveUser {
|
|
|
final private static String REAL_USER_NAME = "realUser1@HADOOP.APACHE.ORG";
|
|
|
final private static String REAL_USER_SHORT_NAME = "realUser1";
|
|
|
final private static String PROXY_USER_NAME = "proxyUser";
|
|
@@ -53,8 +58,8 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
final private static String GROUP2_NAME = "group2";
|
|
|
final private static String[] GROUP_NAMES = new String[] { GROUP1_NAME,
|
|
|
GROUP2_NAME };
|
|
|
-
|
|
|
- private TestRpcService client;
|
|
|
+ private static final String ADDRESS = "0.0.0.0";
|
|
|
+ private TestProtocol proxy;
|
|
|
private static final Configuration masterConf = new Configuration();
|
|
|
|
|
|
|
|
@@ -77,7 +82,7 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
|
|
|
private void configureSuperUserIPAddresses(Configuration conf,
|
|
|
String superUserShortName) throws IOException {
|
|
|
- ArrayList<String> ipList = new ArrayList<>();
|
|
|
+ ArrayList<String> ipList = new ArrayList<String>();
|
|
|
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface
|
|
|
.getNetworkInterfaces();
|
|
|
while (netInterfaceList.hasMoreElements()) {
|
|
@@ -125,19 +130,50 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
curUGI.toString());
|
|
|
}
|
|
|
|
|
|
- private void checkRemoteUgi(final UserGroupInformation ugi,
|
|
|
- final Configuration conf) throws Exception {
|
|
|
+ @TokenInfo(TestTokenSelector.class)
|
|
|
+ public interface TestProtocol extends VersionedProtocol {
|
|
|
+ public static final long versionID = 1L;
|
|
|
+
|
|
|
+ String aMethod() throws IOException;
|
|
|
+ String getServerRemoteUser() throws IOException;
|
|
|
+ }
|
|
|
+
|
|
|
+ public class TestImpl implements TestProtocol {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String aMethod() throws IOException {
|
|
|
+ return UserGroupInformation.getCurrentUser().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getServerRemoteUser() throws IOException {
|
|
|
+ return Server.getRemoteUser().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getProtocolVersion(String protocol, long clientVersion)
|
|
|
+ throws IOException {
|
|
|
+ return TestProtocol.versionID;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProtocolSignature getProtocolSignature(String protocol,
|
|
|
+ long clientVersion, int clientMethodsHash) throws IOException {
|
|
|
+ return new ProtocolSignature(TestProtocol.versionID, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkRemoteUgi(final Server server,
|
|
|
+ final UserGroupInformation ugi, final Configuration conf)
|
|
|
+ throws Exception {
|
|
|
ugi.doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
@Override
|
|
|
- public Void run() throws ServiceException {
|
|
|
- client = getClient(addr, conf);
|
|
|
- String currentUser = client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
- String serverRemoteUser = client.getServerRemoteUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
-
|
|
|
- Assert.assertEquals(ugi.toString(), currentUser);
|
|
|
- Assert.assertEquals(ugi.toString(), serverRemoteUser);
|
|
|
+ public Void run() throws IOException {
|
|
|
+ proxy = RPC.getProxy(
|
|
|
+ TestProtocol.class, TestProtocol.versionID,
|
|
|
+ NetUtils.getConnectAddress(server), conf);
|
|
|
+ Assert.assertEquals(ugi.toString(), proxy.aMethod());
|
|
|
+ Assert.assertEquals(ugi.toString(), proxy.getServerRemoteUser());
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
@@ -149,27 +185,29 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
conf.setStrings(DefaultImpersonationProvider.getTestProvider().
|
|
|
getProxySuperuserGroupConfKey(REAL_USER_SHORT_NAME), "group1");
|
|
|
configureSuperUserIPAddresses(conf, REAL_USER_SHORT_NAME);
|
|
|
- // Set RPC engine to protobuf RPC engine
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
- UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 5);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).build();
|
|
|
|
|
|
refreshConf(conf);
|
|
|
try {
|
|
|
+ server.start();
|
|
|
+
|
|
|
UserGroupInformation realUserUgi = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
- checkRemoteUgi(realUserUgi, conf);
|
|
|
+ checkRemoteUgi(server, realUserUgi, conf);
|
|
|
|
|
|
- UserGroupInformation proxyUserUgi =
|
|
|
- UserGroupInformation.createProxyUserForTesting(
|
|
|
+ UserGroupInformation proxyUserUgi = UserGroupInformation.createProxyUserForTesting(
|
|
|
PROXY_USER_NAME, realUserUgi, GROUP_NAMES);
|
|
|
- checkRemoteUgi(proxyUserUgi, conf);
|
|
|
+ checkRemoteUgi(server, proxyUserUgi, conf);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
Assert.fail();
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -180,25 +218,29 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
conf.setStrings(DefaultImpersonationProvider.getTestProvider().
|
|
|
getProxySuperuserGroupConfKey(REAL_USER_SHORT_NAME),
|
|
|
"group1");
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
- UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 5);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(2).setVerbose(false).build();
|
|
|
|
|
|
refreshConf(conf);
|
|
|
try {
|
|
|
+ server.start();
|
|
|
+
|
|
|
UserGroupInformation realUserUgi = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
- checkRemoteUgi(realUserUgi, conf);
|
|
|
+ checkRemoteUgi(server, realUserUgi, conf);
|
|
|
|
|
|
UserGroupInformation proxyUserUgi = UserGroupInformation
|
|
|
.createProxyUserForTesting(PROXY_USER_NAME, realUserUgi, GROUP_NAMES);
|
|
|
- checkRemoteUgi(proxyUserUgi, conf);
|
|
|
+ checkRemoteUgi(server, proxyUserUgi, conf);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
Assert.fail();
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -214,14 +256,17 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
conf.setStrings(DefaultImpersonationProvider.getTestProvider().
|
|
|
getProxySuperuserGroupConfKey(REAL_USER_SHORT_NAME),
|
|
|
"group1");
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
- UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 5);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(2).setVerbose(false).build();
|
|
|
|
|
|
refreshConf(conf);
|
|
|
|
|
|
try {
|
|
|
+ server.start();
|
|
|
+
|
|
|
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
|
|
|
+
|
|
|
UserGroupInformation realUserUgi = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
|
|
@@ -230,10 +275,11 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
String retVal = proxyUserUgi
|
|
|
.doAs(new PrivilegedExceptionAction<String>() {
|
|
|
@Override
|
|
|
- public String run() throws ServiceException {
|
|
|
- client = getClient(addr, conf);
|
|
|
- return client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
+ public String run() throws IOException {
|
|
|
+ proxy = RPC.getProxy(TestProtocol.class,
|
|
|
+ TestProtocol.versionID, addr, conf);
|
|
|
+ String ret = proxy.aMethod();
|
|
|
+ return ret;
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -241,7 +287,10 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -250,14 +299,17 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
final Configuration conf = new Configuration();
|
|
|
conf.setStrings(DefaultImpersonationProvider.getTestProvider().
|
|
|
getProxySuperuserGroupConfKey(REAL_USER_SHORT_NAME), "group1");
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
- UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 2);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(2).setVerbose(false).build();
|
|
|
|
|
|
refreshConf(conf);
|
|
|
|
|
|
try {
|
|
|
+ server.start();
|
|
|
+
|
|
|
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
|
|
|
+
|
|
|
UserGroupInformation realUserUgi = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
|
|
@@ -266,10 +318,11 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
String retVal = proxyUserUgi
|
|
|
.doAs(new PrivilegedExceptionAction<String>() {
|
|
|
@Override
|
|
|
- public String run() throws ServiceException {
|
|
|
- client = getClient(addr, conf);
|
|
|
- return client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
+ public String run() throws IOException {
|
|
|
+ proxy = RPC.getProxy(TestProtocol.class,
|
|
|
+ TestProtocol.versionID, addr, conf);
|
|
|
+ String ret = proxy.aMethod();
|
|
|
+ return ret;
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -277,7 +330,10 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -285,12 +341,15 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
public void testRealUserGroupNotSpecified() throws IOException {
|
|
|
final Configuration conf = new Configuration();
|
|
|
configureSuperUserIPAddresses(conf, REAL_USER_SHORT_NAME);
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
- UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 2);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(2).setVerbose(false).build();
|
|
|
|
|
|
try {
|
|
|
+ server.start();
|
|
|
+
|
|
|
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
|
|
|
+
|
|
|
UserGroupInformation realUserUgi = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
|
|
@@ -299,10 +358,11 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
String retVal = proxyUserUgi
|
|
|
.doAs(new PrivilegedExceptionAction<String>() {
|
|
|
@Override
|
|
|
- public String run() throws ServiceException {
|
|
|
- client = getClient(addr, conf);
|
|
|
- return client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
+ public String run() throws IOException {
|
|
|
+ proxy = (TestProtocol) RPC.getProxy(TestProtocol.class,
|
|
|
+ TestProtocol.versionID, addr, conf);
|
|
|
+ String ret = proxy.aMethod();
|
|
|
+ return ret;
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -310,7 +370,10 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -321,14 +384,17 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
conf.setStrings(DefaultImpersonationProvider.getTestProvider().
|
|
|
getProxySuperuserGroupConfKey(REAL_USER_SHORT_NAME),
|
|
|
"group3");
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
- UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 2);
|
|
|
+ Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(2).setVerbose(false).build();
|
|
|
|
|
|
refreshConf(conf);
|
|
|
|
|
|
try {
|
|
|
+ server.start();
|
|
|
+
|
|
|
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
|
|
|
+
|
|
|
UserGroupInformation realUserUgi = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
|
|
@@ -337,10 +403,11 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
String retVal = proxyUserUgi
|
|
|
.doAs(new PrivilegedExceptionAction<String>() {
|
|
|
@Override
|
|
|
- public String run() throws ServiceException {
|
|
|
- client = getClient(addr, conf);
|
|
|
- return client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
+ public String run() throws IOException {
|
|
|
+ proxy = RPC.getProxy(TestProtocol.class,
|
|
|
+ TestProtocol.versionID, addr, conf);
|
|
|
+ String ret = proxy.aMethod();
|
|
|
+ return ret;
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -348,7 +415,10 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -362,17 +432,20 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
final Configuration conf = new Configuration(masterConf);
|
|
|
TestTokenSecretManager sm = new TestTokenSecretManager();
|
|
|
SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, conf);
|
|
|
- RPC.setProtocolEngine(conf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
UserGroupInformation.setConfiguration(conf);
|
|
|
- final Server server = setupTestServer(conf, 5, sm);
|
|
|
+ final Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
|
|
|
+ .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0)
|
|
|
+ .setNumHandlers(5).setVerbose(true).setSecretManager(sm).build();
|
|
|
+
|
|
|
+ server.start();
|
|
|
|
|
|
final UserGroupInformation current = UserGroupInformation
|
|
|
.createRemoteUser(REAL_USER_NAME);
|
|
|
-
|
|
|
+
|
|
|
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
|
|
|
TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
|
|
|
.getUserName()), new Text("SomeSuperUser"));
|
|
|
- Token<TestTokenIdentifier> token = new Token<>(tokenId,
|
|
|
+ Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
|
|
|
sm);
|
|
|
SecurityUtil.setTokenService(token, addr);
|
|
|
UserGroupInformation proxyUserUgi = UserGroupInformation
|
|
@@ -380,19 +453,23 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
proxyUserUgi.addToken(token);
|
|
|
|
|
|
refreshConf(conf);
|
|
|
-
|
|
|
+
|
|
|
String retVal = proxyUserUgi.doAs(new PrivilegedExceptionAction<String>() {
|
|
|
@Override
|
|
|
public String run() throws Exception {
|
|
|
try {
|
|
|
- client = getClient(addr, conf);
|
|
|
- return client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
+ proxy = RPC.getProxy(TestProtocol.class,
|
|
|
+ TestProtocol.versionID, addr, conf);
|
|
|
+ String ret = proxy.aMethod();
|
|
|
+ return ret;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw e;
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -409,34 +486,42 @@ public class TestDoAsEffectiveUser extends TestRpcBase {
|
|
|
TestTokenSecretManager sm = new TestTokenSecretManager();
|
|
|
final Configuration newConf = new Configuration(masterConf);
|
|
|
SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, newConf);
|
|
|
- // Set RPC engine to protobuf RPC engine
|
|
|
- RPC.setProtocolEngine(newConf, TestRpcService.class,
|
|
|
- ProtobufRpcEngine.class);
|
|
|
UserGroupInformation.setConfiguration(newConf);
|
|
|
- final Server server = setupTestServer(newConf, 5, sm);
|
|
|
+ final Server server = new RPC.Builder(newConf)
|
|
|
+ .setProtocol(TestProtocol.class).setInstance(new TestImpl())
|
|
|
+ .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
|
|
|
+ .setSecretManager(sm).build();
|
|
|
+
|
|
|
+ server.start();
|
|
|
|
|
|
final UserGroupInformation current = UserGroupInformation
|
|
|
.createUserForTesting(REAL_USER_NAME, GROUP_NAMES);
|
|
|
|
|
|
refreshConf(newConf);
|
|
|
-
|
|
|
+
|
|
|
+ final InetSocketAddress addr = NetUtils.getConnectAddress(server);
|
|
|
TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
|
|
|
.getUserName()), new Text("SomeSuperUser"));
|
|
|
- Token<TestTokenIdentifier> token = new Token<>(tokenId, sm);
|
|
|
+ Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
|
|
|
+ sm);
|
|
|
SecurityUtil.setTokenService(token, addr);
|
|
|
current.addToken(token);
|
|
|
String retVal = current.doAs(new PrivilegedExceptionAction<String>() {
|
|
|
@Override
|
|
|
public String run() throws Exception {
|
|
|
try {
|
|
|
- client = getClient(addr, newConf);
|
|
|
- return client.getCurrentUser(null,
|
|
|
- newEmptyRequest()).getUser();
|
|
|
+ proxy = RPC.getProxy(TestProtocol.class,
|
|
|
+ TestProtocol.versionID, addr, newConf);
|
|
|
+ String ret = proxy.aMethod();
|
|
|
+ return ret;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw e;
|
|
|
} finally {
|
|
|
- stop(server, client);
|
|
|
+ server.stop();
|
|
|
+ if (proxy != null) {
|
|
|
+ RPC.stopProxy(proxy);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|