Skip to content

Commit a0c95ee

Browse files
committed
HDDS-2228. Fix NPE in OzoneDelegationTokenManager#addPersistedDelegat… (#1571)
(cherry picked from commit c5665b2)
1 parent 2eb41fb commit a0c95ee

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneDelegationTokenSecretManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,16 @@ public class OzoneDelegationTokenSecretManager
8181
* milliseconds
8282
* @param dtRemoverScanInterval how often the tokens are scanned for expired
8383
* tokens in milliseconds
84+
* @param certClient certificate client to SCM CA
8485
*/
8586
public OzoneDelegationTokenSecretManager(OzoneConfiguration conf,
8687
long tokenMaxLifetime, long tokenRenewInterval,
8788
long dtRemoverScanInterval, Text service,
88-
S3SecretManager s3SecretManager) throws IOException {
89+
S3SecretManager s3SecretManager, CertificateClient certClient)
90+
throws IOException {
8991
super(new SecurityConfig(conf), tokenMaxLifetime, tokenRenewInterval,
9092
service, LOG);
93+
setCertClient(certClient);
9194
currentTokens = new ConcurrentHashMap();
9295
this.tokenRemoverScanInterval = dtRemoverScanInterval;
9396
this.s3SecretManager = (S3SecretManagerImpl) s3SecretManager;

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneSecretManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public abstract class OzoneSecretManager<T extends TokenIdentifier>
7070
* @param tokenRenewInterval how often the tokens must be renewed in
7171
* milliseconds
7272
* @param service name of service
73+
* @param logger logger for the secret manager
7374
*/
7475
public OzoneSecretManager(SecurityConfig secureConf, long tokenMaxLifetime,
7576
long tokenRenewInterval, Text service, Logger logger) {
@@ -188,7 +189,7 @@ public String formatTokenId(T id) {
188189
public synchronized void start(CertificateClient client)
189190
throws IOException {
190191
Preconditions.checkState(!isRunning());
191-
this.certClient = client;
192+
setCertClient(client);
192193
updateCurrentKey(new KeyPair(certClient.getPublicKey(),
193194
certClient.getPrivateKey()));
194195
setIsRunning(true);
@@ -247,5 +248,9 @@ public AtomicInteger getTokenSequenceNumber() {
247248
public CertificateClient getCertClient() {
248249
return certClient;
249250
}
251+
252+
public void setCertClient(CertificateClient client) {
253+
this.certClient = client;
254+
}
250255
}
251256

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ private OzoneDelegationTokenSecretManager createDelegationTokenSecretManager(
794794

795795
return new OzoneDelegationTokenSecretManager(conf, tokenMaxLifetime,
796796
tokenRenewInterval, tokenRemoverScanInterval, omRpcAddressTxt,
797-
s3SecretManager);
797+
s3SecretManager, certClient);
798798
}
799799

800800
private OzoneBlockTokenSecretManager createBlockTokenSecretManager(

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/security/TestOzoneDelegationTokenSecretManager.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,41 @@ public void testCreateToken() throws Exception {
169169
validateHash(token.getPassword(), token.getIdentifier());
170170
}
171171

172-
@Test
173-
public void testRenewTokenSuccess() throws Exception {
172+
private void restartSecretManager() throws IOException {
173+
secretManager.stop();
174+
secretManager = null;
175+
secretManager = createSecretManager(conf, tokenMaxLifetime,
176+
expiryTime, tokenRemoverScanInterval);
177+
}
178+
179+
private void testRenewTokenSuccessHelper(boolean restartSecretManager)
180+
throws Exception {
174181
secretManager = createSecretManager(conf, tokenMaxLifetime,
175182
expiryTime, tokenRemoverScanInterval);
176183
secretManager.start(certificateClient);
177184
Token<OzoneTokenIdentifier> token = secretManager.createToken(TEST_USER,
178185
TEST_USER,
179186
TEST_USER);
180187
Thread.sleep(10 * 5);
188+
189+
if (restartSecretManager) {
190+
restartSecretManager();
191+
}
192+
181193
long renewalTime = secretManager.renewToken(token, TEST_USER.toString());
182194
Assert.assertTrue(renewalTime > 0);
183195
}
184196

197+
@Test
198+
public void testReloadAndRenewToken() throws Exception {
199+
testRenewTokenSuccessHelper(true);
200+
}
201+
202+
@Test
203+
public void testRenewTokenSuccess() throws Exception {
204+
testRenewTokenSuccessHelper(false);
205+
}
206+
185207
/**
186208
* Tests failure for mismatch in renewer.
187209
*/
@@ -375,6 +397,7 @@ private void validateHash(byte[] hash, byte[] identifier) throws Exception {
375397
createSecretManager(OzoneConfiguration config, long tokenMaxLife,
376398
long expiry, long tokenRemoverScanTime) throws IOException {
377399
return new OzoneDelegationTokenSecretManager(config, tokenMaxLife,
378-
expiry, tokenRemoverScanTime, serviceRpcAdd, s3SecretManager);
400+
expiry, tokenRemoverScanTime, serviceRpcAdd, s3SecretManager,
401+
certificateClient);
379402
}
380403
}

0 commit comments

Comments
 (0)