|
@@ -18,6 +18,7 @@ package org.apache.hadoop.security;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.io.Text;
|
|
|
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
|
|
import org.apache.hadoop.security.SaslRpcServer.AuthMethod;
|
|
@@ -35,6 +36,7 @@ import javax.security.auth.login.AppConfigurationEntry;
|
|
|
import javax.security.auth.login.LoginContext;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.lang.reflect.Method;
|
|
@@ -848,7 +850,9 @@ public class TestUserGroupInformation {
|
|
|
*/
|
|
|
@Test
|
|
|
public void testPrivateTokenExclusion() throws Exception {
|
|
|
- UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
|
+ UserGroupInformation ugi =
|
|
|
+ UserGroupInformation.createUserForTesting(
|
|
|
+ "privateUser", new String[] { "PRIVATEUSERS" });
|
|
|
TestTokenIdentifier tokenId = new TestTokenIdentifier();
|
|
|
Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(
|
|
|
tokenId.getBytes(), "password".getBytes(),
|
|
@@ -928,4 +932,46 @@ public class TestUserGroupInformation {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testExternalTokenFiles() throws Exception {
|
|
|
+ StringBuilder tokenFullPathnames = new StringBuilder();
|
|
|
+ String tokenFilenames = "token1,token2";
|
|
|
+ String tokenFiles[] = StringUtils.getTrimmedStrings(tokenFilenames);
|
|
|
+ final File testDir = new File("target",
|
|
|
+ TestUserGroupInformation.class.getName() + "-tmpDir").getAbsoluteFile();
|
|
|
+ String testDirPath = testDir.getAbsolutePath();
|
|
|
+
|
|
|
+ // create path for token files
|
|
|
+ for (String tokenFile: tokenFiles) {
|
|
|
+ if (tokenFullPathnames.length() > 0) {
|
|
|
+ tokenFullPathnames.append(",");
|
|
|
+ }
|
|
|
+ tokenFullPathnames.append(testDirPath).append("/").append(tokenFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ // create new token and store it
|
|
|
+ TestTokenIdentifier tokenId = new TestTokenIdentifier();
|
|
|
+ Credentials cred1 = new Credentials();
|
|
|
+ Token<TestTokenIdentifier> token1 = new Token<TestTokenIdentifier>(
|
|
|
+ tokenId.getBytes(), "password".getBytes(),
|
|
|
+ tokenId.getKind(), new Text("token-service1"));
|
|
|
+ cred1.addToken(token1.getService(), token1);
|
|
|
+ cred1.writeTokenStorageFile(new Path(testDirPath, tokenFiles[0]), conf);
|
|
|
+
|
|
|
+ Credentials cred2 = new Credentials();
|
|
|
+ Token<TestTokenIdentifier> token2 = new Token<TestTokenIdentifier>(
|
|
|
+ tokenId.getBytes(), "password".getBytes(),
|
|
|
+ tokenId.getKind(), new Text("token-service2"));
|
|
|
+ cred2.addToken(token2.getService(), token2);
|
|
|
+ cred2.writeTokenStorageFile(new Path(testDirPath, tokenFiles[1]), conf);
|
|
|
+
|
|
|
+ // set property for token external token files
|
|
|
+ System.setProperty("hadoop.token.files", tokenFullPathnames.toString());
|
|
|
+ UserGroupInformation.setLoginUser(null);
|
|
|
+ UserGroupInformation tokenUgi = UserGroupInformation.getLoginUser();
|
|
|
+ Collection<Token<?>> credsugiTokens = tokenUgi.getTokens();
|
|
|
+ assertTrue(credsugiTokens.contains(token1));
|
|
|
+ assertTrue(credsugiTokens.contains(token2));
|
|
|
+ }
|
|
|
}
|