d.readFields(new DataInputStream(new ByteArrayInputStream(
t.getIdentifier())));
assertTrue("Usernames don't match",
clientUgi.getShortUserName().equals(d.getUser().getShortUserName()));
DelegationTokenInformation tokenInfo = MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE
.getToken(d);
assertNotNull("token not in store", tokenInfo);
assertFalse("duplicate token add",
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.addToken(d, tokenInfo));
// check keys are copied from token store when token is loaded
TokenStoreDelegationTokenSecretManager anotherManager =
new TokenStoreDelegationTokenSecretManager(0, 0, 0, 0,
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE);
assertEquals("master keys empty on init", 0,
anotherManager.getAllKeys().length);
assertNotNull("token loaded",
anotherManager.retrievePassword(d));
anotherManager.renewToken(t, clientUgi.getShortUserName());
assertEquals("master keys not loaded from store",
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.getMasterKeys().length,
anotherManager.getAllKeys().length);
// cancel the delegation token
tokenManager.cancelDelegationToken(tokenStrForm);
assertNull("token not removed from store after cancel",
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.getToken(d));
assertFalse("token removed (again)",
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.removeToken(d));
try {
anotherManager.retrievePassword(d);
fail("InvalidToken expected after cancel");
} catch (InvalidToken ex) {
// expected
}
// token expiration
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.addToken(d,
new DelegationTokenInformation(0, t.getPassword()));
assertNotNull(MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.getToken(d));
anotherManager.removeExpiredTokens();
assertNull("Expired token not removed",
MyHadoopThriftAuthBridge20S.Server.TOKEN_STORE.getToken(d));