|
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.security;
|
|
|
|
|
|
|
|
|
|
|
|
+import static org.apache.hadoop.security.authentication.util.KerberosName.setRules;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
@@ -29,6 +30,10 @@ import java.io.DataInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
import java.security.PrivilegedExceptionAction;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
@@ -54,6 +59,7 @@ import org.apache.hadoop.security.Credentials;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
|
+import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.slf4j.event.Level;
|
|
|
import org.junit.After;
|
|
@@ -376,4 +382,30 @@ public class TestDelegationToken {
|
|
|
" for SomeUser with renewer JobTracker",
|
|
|
dtId.toStringStable());
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testLogExpireTokensWhenChangeRules() throws IOException {
|
|
|
+ setRules("RULE:[2:$1@$0](SomeUser.*)s/.*/SomeUser/");
|
|
|
+ DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(
|
|
|
+ new Text("SomeUser/HOST@EXAMPLE.COM"),
|
|
|
+ new Text("SomeUser/HOST@EXAMPLE.COM"),
|
|
|
+ new Text("SomeUser/HOST@EXAMPLE.COM"));
|
|
|
+ Set<DelegationTokenIdentifier> expiredTokens = new HashSet();
|
|
|
+ expiredTokens.add(dtId);
|
|
|
+ setRules("RULE:[2:$1@$0](OtherUser.*)s/.*/OtherUser/");
|
|
|
+ //rules was modified, causing the existing tokens
|
|
|
+ //(May be loaded from other storage systems like zookeeper) to fail to match the kerberos rules,
|
|
|
+ //return an exception that cannot be handled
|
|
|
+ new AbstractDelegationTokenSecretManager<DelegationTokenIdentifier>(10 * 1000, 10 * 1000,
|
|
|
+ 10 * 1000, 10 * 1000) {
|
|
|
+ @Override
|
|
|
+ public DelegationTokenIdentifier createIdentifier() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ public void logExpireTokens(Collection<DelegationTokenIdentifier> expiredTokens)
|
|
|
+ throws IOException {
|
|
|
+ super.logExpireTokens(expiredTokens);
|
|
|
+ }
|
|
|
+ }.logExpireTokens(expiredTokens);
|
|
|
+ }
|
|
|
}
|