|
@@ -26,6 +26,7 @@ import java.net.InetSocketAddress;
|
|
|
import java.net.URI;
|
|
|
import java.security.PrivilegedExceptionAction;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.HashSet;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
@@ -44,11 +45,13 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
|
|
|
import org.apache.hadoop.io.Text;
|
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
|
+import org.apache.hadoop.security.SecurityUtilTestHelper;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
|
import org.apache.hadoop.security.token.TokenIdentifier;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.junit.AfterClass;
|
|
|
+import org.junit.Before;
|
|
|
import org.junit.BeforeClass;
|
|
|
import org.junit.Test;
|
|
|
|
|
@@ -100,6 +103,11 @@ public class TestDelegationTokensWithHA {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Before
|
|
|
+ public void prepTest() {
|
|
|
+ SecurityUtilTestHelper.setTokenServiceUseIp(true);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testDelegationTokenDFSApi() throws Exception {
|
|
|
Token<DelegationTokenIdentifier> token = dfs.getDelegationToken("JobTracker");
|
|
@@ -187,23 +195,48 @@ public class TestDelegationTokensWithHA {
|
|
|
URI haUri = new URI("hdfs://my-ha-uri/");
|
|
|
token.setService(HAUtil.buildTokenServiceForLogicalUri(haUri));
|
|
|
ugi.addToken(token);
|
|
|
- HAUtil.cloneDelegationTokenForLogicalUri(ugi, haUri, nn0.getNameNodeAddress());
|
|
|
- HAUtil.cloneDelegationTokenForLogicalUri(ugi, haUri, nn1.getNameNodeAddress());
|
|
|
+
|
|
|
+ Collection<InetSocketAddress> nnAddrs = new HashSet<InetSocketAddress>();
|
|
|
+ nnAddrs.add(nn0.getNameNodeAddress());
|
|
|
+ nnAddrs.add(nn1.getNameNodeAddress());
|
|
|
+ HAUtil.cloneDelegationTokenForLogicalUri(ugi, haUri, nnAddrs);
|
|
|
|
|
|
Collection<Token<? extends TokenIdentifier>> tokens = ugi.getTokens();
|
|
|
assertEquals(3, tokens.size());
|
|
|
|
|
|
LOG.info("Tokens:\n" + Joiner.on("\n").join(tokens));
|
|
|
+ DelegationTokenSelector dts = new DelegationTokenSelector();
|
|
|
|
|
|
// check that the token selected for one of the physical IPC addresses
|
|
|
// matches the one we received
|
|
|
- InetSocketAddress addr = nn0.getNameNodeAddress();
|
|
|
- Text ipcDtService = SecurityUtil.buildTokenService(addr);
|
|
|
- Token<DelegationTokenIdentifier> token2 =
|
|
|
- DelegationTokenSelector.selectHdfsDelegationToken(ipcDtService, ugi);
|
|
|
- assertNotNull(token2);
|
|
|
- assertArrayEquals(token.getIdentifier(), token2.getIdentifier());
|
|
|
- assertArrayEquals(token.getPassword(), token2.getPassword());
|
|
|
+ for (InetSocketAddress addr : nnAddrs) {
|
|
|
+ Text ipcDtService = SecurityUtil.buildTokenService(addr);
|
|
|
+ Token<DelegationTokenIdentifier> token2 =
|
|
|
+ dts.selectToken(ipcDtService, ugi.getTokens());
|
|
|
+ assertNotNull(token2);
|
|
|
+ assertArrayEquals(token.getIdentifier(), token2.getIdentifier());
|
|
|
+ assertArrayEquals(token.getPassword(), token2.getPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ // switch to host-based tokens, shouldn't match existing tokens
|
|
|
+ SecurityUtilTestHelper.setTokenServiceUseIp(false);
|
|
|
+ for (InetSocketAddress addr : nnAddrs) {
|
|
|
+ Text ipcDtService = SecurityUtil.buildTokenService(addr);
|
|
|
+ Token<DelegationTokenIdentifier> token2 =
|
|
|
+ dts.selectToken(ipcDtService, ugi.getTokens());
|
|
|
+ assertNull(token2);
|
|
|
+ }
|
|
|
+
|
|
|
+ // reclone the tokens, and see if they match now
|
|
|
+ HAUtil.cloneDelegationTokenForLogicalUri(ugi, haUri, nnAddrs);
|
|
|
+ for (InetSocketAddress addr : nnAddrs) {
|
|
|
+ Text ipcDtService = SecurityUtil.buildTokenService(addr);
|
|
|
+ Token<DelegationTokenIdentifier> token2 =
|
|
|
+ dts.selectToken(ipcDtService, ugi.getTokens());
|
|
|
+ assertNotNull(token2);
|
|
|
+ assertArrayEquals(token.getIdentifier(), token2.getIdentifier());
|
|
|
+ assertArrayEquals(token.getPassword(), token2.getPassword());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|