Skip to content

Commit b7745b0

Browse files
authored
Revert "HADOOP-17159 Ability for forceful relogin in UserGroupInformation class (#2197)"
This reverts commit a932796.
1 parent 931adba commit b7745b0

File tree

2 files changed

+7
-64
lines changed

2 files changed

+7
-64
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,26 +1232,7 @@ public void reloginFromKeytab() throws IOException {
12321232
reloginFromKeytab(false);
12331233
}
12341234

1235-
/**
1236-
* Force re-Login a user in from a keytab file. Loads a user identity from a
1237-
* keytab file and logs them in. They become the currently logged-in user.
1238-
* This method assumes that {@link #loginUserFromKeytab(String, String)} had
1239-
* happened already. The Subject field of this UserGroupInformation object is
1240-
* updated to have the new credentials.
1241-
*
1242-
* @param ignoreTimeElapsed Force re-login irrespective of the time of last
1243-
* login
1244-
* @throws IOException
1245-
* @throws KerberosAuthException on a failure
1246-
*/
1247-
@InterfaceAudience.Public
1248-
@InterfaceStability.Evolving
1249-
public void reloginFromKeytab(boolean ignoreTimeElapsed) throws IOException {
1250-
reloginFromKeytab(false, ignoreTimeElapsed);
1251-
}
1252-
1253-
private void reloginFromKeytab(boolean checkTGT, boolean ignoreTimeElapsed)
1254-
throws IOException {
1235+
private void reloginFromKeytab(boolean checkTGT) throws IOException {
12551236
if (!shouldRelogin() || !isFromKeytab()) {
12561237
return;
12571238
}
@@ -1266,7 +1247,7 @@ private void reloginFromKeytab(boolean checkTGT, boolean ignoreTimeElapsed)
12661247
return;
12671248
}
12681249
}
1269-
relogin(login, ignoreTimeElapsed);
1250+
relogin(login);
12701251
}
12711252

12721253
/**
@@ -1287,27 +1268,25 @@ public void reloginFromTicketCache() throws IOException {
12871268
if (login == null) {
12881269
throw new KerberosAuthException(MUST_FIRST_LOGIN);
12891270
}
1290-
relogin(login, false);
1271+
relogin(login);
12911272
}
12921273

1293-
private void relogin(HadoopLoginContext login, boolean ignoreTimeElapsed)
1294-
throws IOException {
1274+
private void relogin(HadoopLoginContext login) throws IOException {
12951275
// ensure the relogin is atomic to avoid leaving credentials in an
12961276
// inconsistent state. prevents other ugi instances, SASL, and SPNEGO
12971277
// from accessing or altering credentials during the relogin.
12981278
synchronized(login.getSubjectLock()) {
12991279
// another racing thread may have beat us to the relogin.
13001280
if (login == getLogin()) {
1301-
unprotectedRelogin(login, ignoreTimeElapsed);
1281+
unprotectedRelogin(login);
13021282
}
13031283
}
13041284
}
13051285

1306-
private void unprotectedRelogin(HadoopLoginContext login,
1307-
boolean ignoreTimeElapsed) throws IOException {
1286+
private void unprotectedRelogin(HadoopLoginContext login) throws IOException {
13081287
assert Thread.holdsLock(login.getSubjectLock());
13091288
long now = Time.now();
1310-
if (!hasSufficientTimeElapsed(now) && !ignoreTimeElapsed) {
1289+
if (!hasSufficientTimeElapsed(now)) {
13111290
return;
13121291
}
13131292
// register most recent relogin attempt

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUGILoginFromKeytab.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -158,42 +158,6 @@ public void testUGIReLoginFromKeytab() throws Exception {
158158
Assert.assertNotSame(login1, login2);
159159
}
160160

161-
/**
162-
* Force re-login from keytab using the MiniKDC and verify the UGI can
163-
* successfully relogin from keytab as well.
164-
*/
165-
@Test
166-
public void testUGIForceReLoginFromKeytab() throws Exception {
167-
// Set this to false as we are testing force re-login anyways
168-
UserGroupInformation.setShouldRenewImmediatelyForTests(false);
169-
String principal = "foo";
170-
File keytab = new File(workDir, "foo.keytab");
171-
kdc.createPrincipal(keytab, principal);
172-
173-
UserGroupInformation.loginUserFromKeytab(principal, keytab.getPath());
174-
UserGroupInformation ugi = UserGroupInformation.getLoginUser();
175-
Assert.assertTrue("UGI should be configured to login from keytab",
176-
ugi.isFromKeytab());
177-
178-
// Verify relogin from keytab.
179-
User user = getUser(ugi.getSubject());
180-
final long firstLogin = user.getLastLogin();
181-
final LoginContext login1 = user.getLogin();
182-
Assert.assertNotNull(login1);
183-
184-
// Sleep for 2 secs to have a difference between first and second login
185-
Thread.sleep(2000);
186-
187-
// Force relogin from keytab
188-
ugi.reloginFromKeytab(true);
189-
final long secondLogin = user.getLastLogin();
190-
final LoginContext login2 = user.getLogin();
191-
Assert.assertTrue("User should have been able to relogin from keytab",
192-
secondLogin > firstLogin);
193-
Assert.assertNotNull(login2);
194-
Assert.assertNotSame(login1, login2);
195-
}
196-
197161
@Test
198162
public void testGetUGIFromKnownSubject() throws Exception {
199163
KerberosPrincipal principal = new KerberosPrincipal("user");

0 commit comments

Comments
 (0)