Class AbstractDelegationTokenSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>
java.lang.Object
org.apache.hadoop.security.token.SecretManager<TokenIdent>
org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager<TokenIdent>
- Direct Known Subclasses:
SQLDelegationTokenSecretManager,ZKDelegationTokenSecretManager
@Public
@Evolving
public abstract class AbstractDelegationTokenSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>
extends SecretManager<TokenIdent>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass to encapsulate a token's renew date and password.Nested classes/interfaces inherited from class org.apache.hadoop.security.token.SecretManager
SecretManager.InvalidToken -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Integer,DelegationKey> Access to allKeys is protected by this object lockprotected intAccess to currentId is protected by this object lock.Cache of currently valid tokens, mapping from DelegationTokenIdentifier to DelegationTokenInformation.protected intSequence number to create DelegationTokenIdentifier.protected ObjectIf the delegation token update thread holds this lock, it will not get interrupted.protected booleanprotected booleanWhether to store a token's tracking ID in its TokenInformation.Map of token real owners to its token count. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDelegationTokenSecretManager(long delegationKeyUpdateInterval, long delegationTokenMaxLifetime, long delegationTokenRenewInterval, long delegationTokenRemoverScanInterval) Create a secret manager -
Method Summary
Modifier and TypeMethodDescriptionvoidaddKey(DelegationKey key) Add a previously used master key to cache (when NN restarts), should be called before activate().voidaddPersistedDelegationToken(TokenIdent identifier, long renewDate) This method is intended to be used for recovering persisted delegation tokens.protected voidAdd token stats to the owner to token count mapping.cancelToken(Token<TokenIdent> token, String canceller) Cancel a token by removing it from cache.checkToken(TokenIdent identifier) Find the DelegationTokenInformation for the given token id, and verify that if the token is expired.protected byte[]createPassword(TokenIdent identifier) Create the password for the given identifier.static SecretKeycreateSecretKey(byte[] key) Convert the byte[] to a secret keydecodeTokenIdentifier(Token<TokenIdent> token) Decode the token identifier.protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.longTotal count of active delegation tokens.protected DelegationKeygetDelegationKey(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenSecretManagerMetricsgetTokenInfo(TokenIdent ident) For subclasses externalizing the storage, for example Zookeeper based implementationsprotected longInterval for tokens to be renewed.getTokenTrackingId(TokenIdent identifier) getTopTokenRealOwners(int n) Return top token real owners list as well as the tokens count.protected StringgetTrackingIdIfEnabled(TokenIdent ident) protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.booleanis secretMgr runningprotected voidlogExpireToken(TokenIdent ident) protected voidlogExpireTokens(Collection<TokenIdent> expiredTokens) protected voidprotected voidprotected voidprotected voidremoveStoredToken(TokenIdent ident) longrenewToken(Token<TokenIdent> token, String renewer) Renew a delegation token.voidreset()Reset all data structures and mutable state.byte[]retrievePassword(TokenIdent identifier) Retrieve the password for the given token identifier.protected voidUpdate the current master key for generating delegation tokens It should be called only by tokenRemoverThread.protected voidsetCurrentKeyId(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.protected voidsetDelegationTokenSeqNum(int seqNum) For subclasses externalizing the storage, for example Zookeeper based implementations.voidshould be called before this object is used.voidprotected voidFor subclasses externalizing the storage, for example Zookeeper based implementations.protected voidprotected voidstoreNewToken(TokenIdent ident, long renewDate) protected voidstoreToken(TokenIdent ident, AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) For subclasses externalizing the storage, for example Zookeeper based implementations.protected voidThis method syncs token information from currentTokens to tokenOwnerStats.protected voidFor subclasses externalizing the storage, for example Zookeeper based implementations.protected voidupdateStoredToken(TokenIdent ident, long renewDate) protected voidupdateToken(TokenIdent ident, AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) For subclasses externalizing the storage, for example Zookeeper based implementations.voidverifyToken(TokenIdent identifier, byte[] password) Verifies that the given identifier and password are valid and match.Methods inherited from class org.apache.hadoop.security.token.SecretManager
checkAvailableForRead, createIdentifier, createPassword, generateSecret, retriableRetrievePassword, update, validateSecretKeyLength
-
Field Details
-
currentTokens
protected Map<TokenIdent extends AbstractDelegationTokenIdentifier,AbstractDelegationTokenSecretManager.DelegationTokenInformation> currentTokensCache of currently valid tokens, mapping from DelegationTokenIdentifier to DelegationTokenInformation. Protected by this object lock. -
tokenOwnerStats
Map of token real owners to its token count. This is used to generate metrics of top users by owned tokens. -
delegationTokenSequenceNumber
protected int delegationTokenSequenceNumberSequence number to create DelegationTokenIdentifier. Protected by this object lock. -
allKeys
Access to allKeys is protected by this object lock -
currentId
protected int currentIdAccess to currentId is protected by this object lock. -
storeTokenTrackingId
protected boolean storeTokenTrackingIdWhether to store a token's tracking ID in its TokenInformation. Can be overridden by a subclass. -
running
protected volatile boolean running -
noInterruptsLock
If the delegation token update thread holds this lock, it will not get interrupted.
-
-
Constructor Details
-
AbstractDelegationTokenSecretManager
public AbstractDelegationTokenSecretManager(long delegationKeyUpdateInterval, long delegationTokenMaxLifetime, long delegationTokenRenewInterval, long delegationTokenRemoverScanInterval) Create a secret manager- Parameters:
delegationKeyUpdateInterval- the number of milliseconds for rolling new secret keys.delegationTokenMaxLifetime- the maximum lifetime of the delegation tokens in millisecondsdelegationTokenRenewInterval- how often the tokens must be renewed in millisecondsdelegationTokenRemoverScanInterval- how often the tokens are scanned for expired tokens in milliseconds
-
-
Method Details
-
startThreads
should be called before this object is used.- Throws:
IOException- raised on errors performing I/O.
-
reset
public void reset()Reset all data structures and mutable state. -
getCurrentTokensSize
public long getCurrentTokensSize()Total count of active delegation tokens.- Returns:
- currentTokens.size.
-
getTokenRenewInterval
protected long getTokenRenewInterval()Interval for tokens to be renewed.- Returns:
- Renew interval in milliseconds.
-
addKey
Add a previously used master key to cache (when NN restarts), should be called before activate().- Parameters:
key- delegation key.- Throws:
IOException- raised on errors performing I/O.
-
getAllKeys
-
logUpdateMasterKey
- Throws:
IOException
-
logExpireToken
- Throws:
IOException
-
storeNewMasterKey
- Throws:
IOException
-
removeStoredMasterKey
-
storeNewToken
- Throws:
IOException
-
removeStoredToken
- Throws:
IOException
-
updateStoredToken
- Throws:
IOException
-
getCurrentKeyId
protected int getCurrentKeyId()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- currentId.
-
incrementCurrentKeyId
protected int incrementCurrentKeyId()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- currentId.
-
setCurrentKeyId
protected void setCurrentKeyId(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
keyId- keyId.
-
getDelegationTokenSeqNum
protected int getDelegationTokenSeqNum()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- delegationTokenSequenceNumber.
-
incrementDelegationTokenSeqNum
protected int incrementDelegationTokenSeqNum()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- delegationTokenSequenceNumber.
-
setDelegationTokenSeqNum
protected void setDelegationTokenSeqNum(int seqNum) For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
seqNum- seqNum.
-
getDelegationKey
For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
keyId- keyId.- Returns:
- DelegationKey.
-
storeDelegationKey
For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
key- DelegationKey.- Throws:
IOException- raised on errors performing I/O.
-
updateDelegationKey
For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
key- DelegationKey.- Throws:
IOException- raised on errors performing I/O.
-
getTokenInfo
protected AbstractDelegationTokenSecretManager.DelegationTokenInformation getTokenInfo(TokenIdent ident) For subclasses externalizing the storage, for example Zookeeper based implementations- Parameters:
ident- ident.- Returns:
- DelegationTokenInformation.
-
storeToken
protected void storeToken(TokenIdent ident, AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) throws IOException For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
ident- ident.tokenInfo- tokenInfo.- Throws:
IOException- raised on errors performing I/O.
-
updateToken
protected void updateToken(TokenIdent ident, AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) throws IOException For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
ident- ident.tokenInfo- tokenInfo.- Throws:
IOException- raised on errors performing I/O.
-
addPersistedDelegationToken
This method is intended to be used for recovering persisted delegation tokens. Tokens that have an unknownDelegationKeyare marked as expired and automatically cleaned up. This method must be called before this secret manager is activated (before startThreads() is called)- Parameters:
identifier- identifier read from persistent storagerenewDate- token renew time- Throws:
IOException- raised on errors performing I/O.
-
rollMasterKey
Update the current master key for generating delegation tokens It should be called only by tokenRemoverThread.- Throws:
IOException- raised on errors performing I/O.
-
createPassword
Description copied from class:SecretManagerCreate the password for the given identifier. identifier may be modified inside this method.- Specified by:
createPasswordin classSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>- Parameters:
identifier- the identifier to use- Returns:
- the new password
-
checkToken
protected AbstractDelegationTokenSecretManager.DelegationTokenInformation checkToken(TokenIdent identifier) throws SecretManager.InvalidToken Find the DelegationTokenInformation for the given token id, and verify that if the token is expired. Note that this method should be called with acquiring the secret manager's monitor.- Parameters:
identifier- identifier.- Returns:
- DelegationTokenInformation.
- Throws:
SecretManager.InvalidToken- invalid token exception.
-
retrievePassword
Description copied from class:SecretManagerRetrieve the password for the given token identifier. Should check the date or registry to make sure the token hasn't expired or been revoked. Returns the relevant password.- Specified by:
retrievePasswordin classSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>- Parameters:
identifier- the identifier to validate- Returns:
- the password to use
- Throws:
SecretManager.InvalidToken- the token was invalid
-
getTrackingIdIfEnabled
-
getTokenTrackingId
-
verifyToken
Verifies that the given identifier and password are valid and match.- Parameters:
identifier- Token identifier.password- Password in the token.- Throws:
SecretManager.InvalidToken- InvalidToken.
-
renewToken
public long renewToken(Token<TokenIdent> token, String renewer) throws SecretManager.InvalidToken, IOException Renew a delegation token.- Parameters:
token- the token to renewrenewer- the full principal name of the user doing the renewal- Returns:
- the new expiration time
- Throws:
SecretManager.InvalidToken- if the token is invalidAccessControlException- if the user can't renew tokenIOException
-
cancelToken
Cancel a token by removing it from cache.- Parameters:
token- token.canceller- canceller.- Returns:
- Identifier of the canceled token
- Throws:
SecretManager.InvalidToken- for invalid tokenAccessControlException- if the user isn't allowed to cancelIOException
-
createSecretKey
Convert the byte[] to a secret key- Parameters:
key- the byte[] to create the secret key from- Returns:
- the secret key
-
getCandidateTokensForCleanup
protected Map<TokenIdent,AbstractDelegationTokenSecretManager.DelegationTokenInformation> getCandidateTokensForCleanup() -
logExpireTokens
- Throws:
IOException
-
removeExpiredStoredToken
- Throws:
IOException
-
stopThreads
public void stopThreads() -
isRunning
public boolean isRunning()is secretMgr running- Returns:
- true if secret mgr is running
-
decodeTokenIdentifier
Decode the token identifier. The subclass can customize the way to decode the token identifier.- Parameters:
token- the token where to extract the identifier- Returns:
- the delegation token identifier
- Throws:
IOException- raised on errors performing I/O.
-
getTopTokenRealOwners
Return top token real owners list as well as the tokens count.- Parameters:
n- top number of users- Returns:
- map of owners to counts
-
addTokenForOwnerStats
Add token stats to the owner to token count mapping.- Parameters:
id- token id.
-
syncTokenOwnerStats
protected void syncTokenOwnerStats()This method syncs token information from currentTokens to tokenOwnerStats. It is used when the currentTokens is initialized or refreshed. This is called from a single thread thus no synchronization is needed. -
getMetrics
protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenSecretManagerMetrics getMetrics()
-